github.com/btccom/go-micro/v2@v2.9.3/api/server/options.go (about)

     1  package server
     2  
     3  import (
     4  	"crypto/tls"
     5  	"net/http"
     6  
     7  	"github.com/btccom/go-micro/v2/api/resolver"
     8  	"github.com/btccom/go-micro/v2/api/server/acme"
     9  )
    10  
    11  type Option func(o *Options)
    12  
    13  type Options struct {
    14  	EnableACME   bool
    15  	EnableCORS   bool
    16  	ACMEProvider acme.Provider
    17  	EnableTLS    bool
    18  	ACMEHosts    []string
    19  	TLSConfig    *tls.Config
    20  	Resolver     resolver.Resolver
    21  	Wrappers     []Wrapper
    22  }
    23  
    24  type Wrapper func(h http.Handler) http.Handler
    25  
    26  func WrapHandler(w Wrapper) Option {
    27  	return func(o *Options) {
    28  		o.Wrappers = append(o.Wrappers, w)
    29  	}
    30  }
    31  
    32  func EnableCORS(b bool) Option {
    33  	return func(o *Options) {
    34  		o.EnableCORS = b
    35  	}
    36  }
    37  
    38  func EnableACME(b bool) Option {
    39  	return func(o *Options) {
    40  		o.EnableACME = b
    41  	}
    42  }
    43  
    44  func ACMEHosts(hosts ...string) Option {
    45  	return func(o *Options) {
    46  		o.ACMEHosts = hosts
    47  	}
    48  }
    49  
    50  func ACMEProvider(p acme.Provider) Option {
    51  	return func(o *Options) {
    52  		o.ACMEProvider = p
    53  	}
    54  }
    55  
    56  func EnableTLS(b bool) Option {
    57  	return func(o *Options) {
    58  		o.EnableTLS = b
    59  	}
    60  }
    61  
    62  func TLSConfig(t *tls.Config) Option {
    63  	return func(o *Options) {
    64  		o.TLSConfig = t
    65  	}
    66  }
    67  
    68  func Resolver(r resolver.Resolver) Option {
    69  	return func(o *Options) {
    70  		o.Resolver = r
    71  	}
    72  }