Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { Register() error Get(rawURL string, opts ...Option) (*http.Response, error) Post(rawURL string, body *bytes.Reader, opts ...Option) (*http.Response, error) }
Client 整合客户端
func New ¶
New 新建客户端
serviceName: 服务名,如:post-service zone: eureka服务地址,多个逗号","分隔离,如:http://192.168.1.100:1111/eureka,http://192.168.1.101:1111/eureka opts: 可选配置,指定端口:eureka.WithPort(80),指定IP:eureka.WithIP("192.168.1.102"), 指定logger:eureka.WithLogFunc(func...) 调用例子: client1 := eureka.New("post-service", "http://192.168.1.100:1111/eureka,http://192.168.1.101:1111/eureka"); client2 := eureka.New( "post-service", "http://192.168.1.100:1111/eureka", eureka.WithPort(80), eureka.WithIP("192.168.1.102"), eureka.WithLogFunc(func...) );
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option 配置
func WithHeaders ¶
WithHeaders 指定请求头 默认{"Content-Type": "application/json"}
func WithKeepAliveDuration ¶
WithKeepAliveDuration 实例健康检测时常,默认1分钟
func WithLogFunc ¶
WithLogFunc 指定logger
例子
func(level int, format string, a ...interface{}) { var logFunc *zerolog.Event switch level { case 1: logFunc = log.Debug() case 2: logFunc = log.Info() case 3: logFunc = log.Error() } if logFunc != nil { funcName, file, line, _ := runtime.Caller(2) fullFuncName := runtime.FuncForPC(funcName).Name() arr := strings.Split(fullFuncName, "/") arrFile := strings.Split(file, "/") logFunc.Str("file", arrFile[len(arrFile)-1]).Int("line", line).Str("func", arr[len(arr)-1]).Msgf(format, a...) } }
Click to show internal directories.
Click to hide internal directories.