github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/stub/stub_rest_option.go (about) 1 package stub 2 3 import "github.com/clubpay/ronykit/kit" 4 5 type RESTOption func(cfg *restConfig) 6 7 type restConfig struct { 8 preflights []RESTPreflightHandler 9 tp kit.TracePropagator 10 hdr map[string]string 11 } 12 13 // WithPreflightREST register one or many handlers to run in sequence before 14 // actually making requests. 15 func WithPreflightREST(h ...RESTPreflightHandler) RESTOption { 16 return func(cfg *restConfig) { 17 cfg.preflights = append(cfg.preflights[:0], h...) 18 } 19 } 20 21 func WithHeaderMap(hdr map[string]string) RESTOption { 22 return func(cfg *restConfig) { 23 cfg.hdr = hdr 24 } 25 } 26 27 func WithHeader(key, value string) RESTOption { 28 return func(cfg *restConfig) { 29 if cfg.hdr == nil { 30 cfg.hdr = make(map[string]string) 31 } 32 cfg.hdr[key] = value 33 } 34 }