teambition open api for go
Teambition Open Api
in Apifox,可用于测试验证,以及用于生成代码根据teambition swagger doc自动生成,刷新间隔每24小时
Go 实现的 teambition Open Api 集合
go get github.com/kexin8/teambition-sdk-go
package main
import (
"log"
teambitionapi "github.com/kexin8/teambition-sdk-go/teambition-api"
)
func main() {
var (
orgId = "..."
appId = "..."
appSecret = "..."
tbapi = teambitionapi.NewClient(teambitionapi.NewOptions(orgId, appId, appSecret))
)
resp, err := tbapi.GetOrgInfo(orgId)
if err != nil {
log.Errorf("%v", err)
}
log.Println(resp)
log.Println(resp.Result)
}
tbapi = teambitionapi.NewClient(teambitionapi.NewOptions(orgId, appId, appSecret))
配置相关属性参考config.go#Options
//config.go
type Options struct {
baseUrl string //https://open.teambition.com/api
orgId string //企业ID
appID string
appSecret string
tokenExpies int64 //token过期时间
isCacheToken bool //是否缓存token
tokenCacheExecutor TokenCacheExecutor //token缓存执行器
}
配置属性说明:
orgId、appID、appSecret需要从teambition申请获取
tokenExpies: 请求tb open api
时token的有效时间,单位ms
isCacheToken: 是否缓存token,默认true
;如果为false
,则每次请求都会重新生成token
tokenCacheExecutor: token缓存执行器,用于指定token缓存策略,默认为本地缓存;当isCacheToken == true
时生效,可通过实现TokenCacheExecutor
接口自定义缓存策略
用户可根据业务需求自定义token缓存策略,例如redis缓存
TokenCacheExecutor
接口
type TokenCacheExecutor interface {
SetToken(tenantId, token string, expireTime int64) //设置token
GetToken(tenantId string) (token string, ok bool) //获取token
}
- 自定义缓存
CustomToeknCacheExecutor
type CustomToeknCacheExecutor struct {
}
func (d *CustomToeknCacheExecutor) SetToken(tenantId, token string, expireTime int64) {
//...
}
func (d *CustomToeknCacheExecutor) GetToken(tenantId string) (token string, ok bool) {
//...
}
- 使用
options := teambitionapi.NewOptions(orgId, appId, appSecret)
options.SetTokenCacheExecutor(&CustomToeknCacheExecutor{})
tbapi := teambitionapi.NewClient(options)
PRs accepted.
Small note: If editing the README, please conform to the standard-readme specification.
MIT © 2023 kexin8