64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
package rpcx
|
|
|
|
import (
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/lego/utils/mapstructure"
|
|
|
|
"github.com/smallnest/rpcx/client"
|
|
)
|
|
|
|
type Option func(*Options)
|
|
type Options struct {
|
|
ServiceId string //服务id
|
|
Port int //监听地址
|
|
FailMode client.FailMode //失败模式
|
|
Debug bool //日志是否开启
|
|
Log log.ILog
|
|
}
|
|
|
|
func SetServiceId(v string) Option {
|
|
return func(o *Options) {
|
|
o.ServiceId = v
|
|
}
|
|
}
|
|
func SetPort(v int) Option {
|
|
return func(o *Options) {
|
|
o.Port = v
|
|
}
|
|
}
|
|
func SetDebug(v bool) Option {
|
|
return func(o *Options) {
|
|
o.Debug = v
|
|
}
|
|
}
|
|
func SetLog(v log.ILog) Option {
|
|
return func(o *Options) {
|
|
o.Log = v
|
|
}
|
|
}
|
|
|
|
func newOptions(config map[string]interface{}, opts ...Option) Options {
|
|
options := Options{
|
|
Debug: true,
|
|
Log: log.Clone(log.SetLoglayer(2)),
|
|
}
|
|
if config != nil {
|
|
mapstructure.Decode(config, &options)
|
|
}
|
|
for _, o := range opts {
|
|
o(&options)
|
|
}
|
|
return options
|
|
}
|
|
|
|
func newOptionsByOption(opts ...Option) Options {
|
|
options := Options{
|
|
Debug: true,
|
|
Log: log.Clone(log.SetLoglayer(2)),
|
|
}
|
|
for _, o := range opts {
|
|
o(&options)
|
|
}
|
|
return options
|
|
}
|