client/

directory
v0.0.0-...-26e1b9e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2022 License: Apache-2.0

README

Client模块

client模块封装了grpc(暂未实现)和http客户端,并且增加了链路追踪和应用监控的功能。

使用示例:

auth = &client{
		conf:       conf,
		httpClient: http.DefaultClient,
		cache:      memory.NewCache(conf.Cache),
	}
err := auth.httpClient.Get(ctx, auth.conf.Url, nil, &msg, http.WithToken(token))

注:1.目前的链路追踪只支持jaeger。

2.http的client支持调用其他系统时所携带的token分两种。第一种在用户直接交互的系统时携带用户认证信息的token,第二种在内部系统调用内部系统时使用系统Token。具体实现如下:


type Options struct {
	Token string
}

type Option func(o *Options)

// 第一种token。用户认证信息token
func WithToken(token string) Option {
	return func(o *Options) {
		o.Token = token
	}
}

// 第二种token。系统内部调用时使用的token
func WithSysToken(caller, resource, requestId string) Option {
	return func(o *Options) {
		msg := caller + "|" + resource + "|" + requestId + "|" + strconv.FormatInt(time.Now().UnixNano(), 10)
		o.Token, _ = xaes.Encrypt(msg)
	}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL