github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/proxy/register_options.go (about) 1 package proxy 2 3 import ( 4 "time" 5 6 "github.com/hellofresh/janus/pkg/router" 7 "github.com/hellofresh/stats-go/client" 8 ) 9 10 // RegisterOption represents the register options 11 type RegisterOption func(*Register) 12 13 // WithRouter sets the router 14 func WithRouter(router router.Router) RegisterOption { 15 return func(r *Register) { 16 r.router = router 17 } 18 } 19 20 // WithFlushInterval sets the Flush interval for copying upgraded connections 21 func WithFlushInterval(d time.Duration) RegisterOption { 22 return func(r *Register) { 23 r.flushInterval = d 24 } 25 } 26 27 // WithIdleConnectionsPerHost sets idle connections per host option 28 func WithIdleConnectionsPerHost(value int) RegisterOption { 29 return func(r *Register) { 30 r.idleConnectionsPerHost = value 31 } 32 } 33 34 // WithStatsClient sets stats client instance for proxy 35 func WithStatsClient(statsClient client.Client) RegisterOption { 36 return func(r *Register) { 37 r.statsClient = statsClient 38 } 39 } 40 41 // WithIdleConnTimeout sets the maximum amount of time an idle 42 // (keep-alive) connection will remain idle before closing 43 // itself. 44 func WithIdleConnTimeout(d time.Duration) RegisterOption { 45 return func(r *Register) { 46 r.idleConnTimeout = d 47 } 48 } 49 50 // WithIdleConnPurgeTicker purges idle connections on every interval if set 51 // this is done to prevent permanent keep-alive on connections with high ops 52 func WithIdleConnPurgeTicker(d time.Duration) RegisterOption { 53 var ticker *time.Ticker 54 55 if d != 0 { 56 ticker = time.NewTicker(d) 57 } 58 59 return func(t *Register) { 60 t.idleConnPurgeTicker = ticker 61 } 62 } 63 64 // WithIsPublicEndpoint adds trace metadata from incoming requests 65 // as parent span if set to false 66 func WithIsPublicEndpoint(b bool) RegisterOption { 67 return func(r *Register) { 68 r.isPublicEndpoint = b 69 } 70 }