Skip to content

kexin8/teambition-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

teambition-sdk-go

banner

standard-readme compliant GitHub go.mod Go version (subdirectory of monorepo) teambition

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

Usage

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缓存策略

用户可根据业务需求自定义token缓存策略,例如redis缓存

TokenCacheExecutor接口

type TokenCacheExecutor interface {
	SetToken(tenantId, token string, expireTime int64) //设置token
	GetToken(tenantId string) (token string, ok bool)  //获取token
}
  1. 自定义缓存CustomToeknCacheExecutor
type CustomToeknCacheExecutor struct {
}

func (d *CustomToeknCacheExecutor) SetToken(tenantId, token string, expireTime int64) {
	//...
}

func (d *CustomToeknCacheExecutor) GetToken(tenantId string) (token string, ok bool) {
	//...
}
  1. 使用
options := teambitionapi.NewOptions(orgId, appId, appSecret)
options.SetTokenCacheExecutor(&CustomToeknCacheExecutor{})

tbapi := teambitionapi.NewClient(options)

API

Maintainers

@kexin8

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2023 kexin8