github.com/thanos-io/thanos@v0.32.5/pkg/server/http/option.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package http 5 6 import ( 7 "net/http" 8 "time" 9 ) 10 11 type options struct { 12 gracePeriod time.Duration 13 listen string 14 tlsConfigPath string 15 mux *http.ServeMux 16 enableH2C bool 17 } 18 19 // Option overrides behavior of Server. 20 type Option interface { 21 apply(*options) 22 } 23 24 type optionFunc func(*options) 25 26 func (f optionFunc) apply(o *options) { 27 f(o) 28 } 29 30 // WithGracePeriod sets shutdown grace period for HTTP server. 31 // Server waits connections to drain for specified amount of time. 32 func WithGracePeriod(t time.Duration) Option { 33 return optionFunc(func(o *options) { 34 o.gracePeriod = t 35 }) 36 } 37 38 // WithListen sets address to listen for HTTP server. 39 // Server accepts incoming TCP connections on given address. 40 func WithListen(s string) Option { 41 return optionFunc(func(o *options) { 42 o.listen = s 43 }) 44 } 45 46 func WithTLSConfig(tls string) Option { 47 return optionFunc(func(o *options) { 48 o.tlsConfigPath = tls 49 }) 50 } 51 52 func WithEnableH2C(enableH2C bool) Option { 53 return optionFunc(func(o *options) { 54 o.enableH2C = enableH2C 55 }) 56 } 57 58 // WithMux overrides the server's default mux. 59 func WithMux(mux *http.ServeMux) Option { 60 return optionFunc(func(o *options) { 61 o.mux = mux 62 }) 63 }