1 Star 0 Fork 0

h79 / gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
child.go 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-09-19 20:48 . log string
package token
import (
"fmt"
"gitee.com/h79/gothird/token/access"
"gitee.com/h79/gothird/token/validate"
"gitee.com/h79/goutils/common/logger"
"strings"
)
// VMap [string] = access_token, refresh_token, code...
type VMap map[string]*validate.Data
func (vmap *VMap) String() string {
var b strings.Builder
for k, v := range *vmap {
b.WriteString("\"")
b.WriteString(k)
b.WriteString("\":{")
b.WriteString(v.String())
b.WriteString("}")
}
return b.String()
}
type Child struct {
App
VMap VMap `json:"data"`
}
func (c *Child) String() string {
return fmt.Sprintf("App= {%s},VMap = {%s}", c.App.String(), c.VMap.String())
}
type CreateChildFunc func(tk Token, sev Service, ch *Child, acsToken access.Token) (Token, error)
func CreateChildEmpty(tk Token, sev Service, ch *Child, acsToken access.Token) (Token, error) {
logger.Warn("Token: CreateChildEmpty, will return 'ErrNotSupported' for appid= %s", tk.GetAppId())
return nil, ErrNotSupported
}
func CreateChild(parent Token, service Service, ch *Child, acsToken access.Token) (Token, error) {
logger.Debug("Token: create child, info= %s", ch.String())
tk, err := Mgr().CreateChild(parent, ch, service)
if err != nil {
return nil, err
}
tk.SetAccessTokenWithAcs(acsToken)
return tk, nil
}
func SyncCreateChild(parent Token, service Service, ch *Child, acsToken access.Token, realId []string, syncFunc func()) {
go func() {
if syncFunc != nil {
syncFunc()
}
if _, err := CreateChild(parent, service, ch, acsToken); err != nil {
logger.Error("Token: create child failure, parentId= %v, child= %s , err= %+v", parent.GetId(), ch.String(), err)
}
if len(realId) == 0 {
return
}
if err := Mgr().AddRealId(realId, ch.Id, ch.Type); err != nil {
logger.Error("Token: add alias failure, realId= %+v, aliasId= %v, err= %+v", realId, ch.Id, err)
}
}()
}
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.8.103

搜索帮助