mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 00:59:22 +00:00
* Merge HTTP and HTTPS routes builder in coordinator * Extract HTTP/S routes * Rename config in coordinator * Generalize child services * Extract games library helper function * Use string address instead of port for HTTP/S * Use a dedicated port extractor function * Add missing GA tag templating * Rename shared server address and port params * Introduce TLS config parameters * Simplify HTTP/S server constructors * Update server auto port roll * Extract init function in worker * Reorder return params of address type port fn * Refactor config handler names * Update TLS default config params * Extract HTTP to HTTPS redirect function * Use httpx in monitoring * Don't log echo requests * Remove error return from the abstract server * Add WSS option to the worker-coordinator connection * Change default worker config * Make worker send its internal connection params * Decouple gamelib from the coordinator * Expose HTTP/S listener address * Keep original HTTP/S addresses * Remove no config handler in worker * Use HTTP-HTTPS redirection * Wrap net.Listener into a struct * Clean http server creation fn * Redirect to https with a generated address * Use URL in the redirector * Use zone address param in worker * Make use of actual addr and port in the monitoring servers * Use auto-justified monitoring addresses info * Add the non-HTTPS worker to HTTPS coordinator connection warning * Embed TLS struct * Move connection API struct into cws package
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package httpx
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/giongto35/cloud-game/v2/pkg/config/shared"
|
|
)
|
|
|
|
type (
|
|
Options struct {
|
|
Https bool
|
|
HttpsRedirect bool
|
|
HttpsRedirectAddress string
|
|
HttpsCert string
|
|
HttpsKey string
|
|
HttpsDomain string
|
|
PortRoll bool
|
|
IdleTimeout time.Duration
|
|
ReadTimeout time.Duration
|
|
WriteTimeout time.Duration
|
|
Zone string
|
|
}
|
|
Option func(*Options)
|
|
)
|
|
|
|
func (o *Options) override(options ...Option) {
|
|
for _, opt := range options {
|
|
opt(o)
|
|
}
|
|
}
|
|
|
|
func (o *Options) IsAutoHttpsCert() bool { return !(o.HttpsCert != "" && o.HttpsKey != "") }
|
|
|
|
func HttpsRedirect(redirect bool) Option {
|
|
return func(opts *Options) { opts.HttpsRedirect = redirect }
|
|
}
|
|
|
|
//func Https(is bool) Option { return func(opts *Options) { opts.Https = is } }
|
|
//func HttpsCert(cert string) Option { return func(opts *Options) { opts.HttpsCert = cert } }
|
|
//func HttpsKey(key string) Option { return func(opts *Options) { opts.HttpsKey = key } }
|
|
//func HttpsDomain(domain string) Option { return func(opts *Options) { opts.HttpsDomain = domain } }
|
|
//func IdleTimeout(t time.Duration) Option { return func(opts *Options) { opts.IdleTimeout = t } }
|
|
//func ReadTimeout(t time.Duration) Option { return func(opts *Options) { opts.ReadTimeout = t } }
|
|
//func WriteTimeout(t time.Duration) Option { return func(opts *Options) { opts.WriteTimeout = t } }
|
|
|
|
func WithPortRoll(roll bool) Option { return func(opts *Options) { opts.PortRoll = roll } }
|
|
func WithZone(zone string) Option { return func(opts *Options) { opts.Zone = zone } }
|
|
func WithServerConfig(conf shared.Server) Option {
|
|
return func(opts *Options) {
|
|
opts.Https = conf.Https
|
|
opts.HttpsCert = conf.Tls.HttpsCert
|
|
opts.HttpsKey = conf.Tls.HttpsKey
|
|
opts.HttpsDomain = conf.Tls.Domain
|
|
opts.HttpsRedirectAddress = conf.Address
|
|
}
|
|
}
|