2019-06-03 20:44:43 +03:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2019-10-09 18:42:05 +03:00
|
|
|
|
2020-04-02 19:44:48 +03:00
|
|
|
"github.com/micro/go-micro/v2/api/resolver"
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/api/server/acme"
|
2019-06-03 20:44:43 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
type Options struct {
|
2020-04-07 12:38:27 +03:00
|
|
|
EnableACME bool
|
|
|
|
EnableCORS bool
|
|
|
|
ACMEProvider acme.Provider
|
|
|
|
EnableTLS bool
|
|
|
|
ACMEHosts []string
|
|
|
|
TLSConfig *tls.Config
|
|
|
|
Resolver resolver.Resolver
|
|
|
|
Namespace string
|
|
|
|
ServicePrefix string
|
2019-10-09 18:42:05 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 14:40:53 +03:00
|
|
|
func EnableCORS(b bool) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.EnableCORS = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 18:42:05 +03:00
|
|
|
func EnableACME(b bool) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.EnableACME = b
|
|
|
|
}
|
2019-06-03 20:44:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func ACMEHosts(hosts ...string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.ACMEHosts = hosts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-09 18:42:05 +03:00
|
|
|
func ACMEProvider(p acme.Provider) Option {
|
2019-06-03 20:44:43 +03:00
|
|
|
return func(o *Options) {
|
2019-10-09 18:42:05 +03:00
|
|
|
o.ACMEProvider = p
|
2019-06-03 20:44:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func EnableTLS(b bool) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.EnableTLS = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TLSConfig(t *tls.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.TLSConfig = t
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 19:44:48 +03:00
|
|
|
|
2020-04-07 12:38:27 +03:00
|
|
|
func ServicePrefix(n string) Option {
|
2020-04-07 11:40:40 +03:00
|
|
|
return func(o *Options) {
|
2020-04-07 12:38:27 +03:00
|
|
|
o.ServicePrefix = n
|
2020-04-07 11:40:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 19:44:48 +03:00
|
|
|
func Namespace(n string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Namespace = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Resolver(r resolver.Resolver) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Resolver = r
|
|
|
|
}
|
|
|
|
}
|