Documentation
¶
Overview ¶
Package utils 包含一些公共工具
Index ¶
- Variables
- func GetJSON(ctx context.Context, urlPath string, params url.Values, result interface{}) error
- func GetJSONWithAppAccessToken(ctx context.Context, urlPath string, provider conf.AppAccessTokenProvider, ...) error
- func GetJSONWithTenantAccessToken(ctx context.Context, urlPath string, provider conf.TenantAccessTokenProvider, ...) error
- func PostJSON(ctx context.Context, urlPath string, body interface{}, result interface{}) error
- func PostJSONWithAppAccessToken(ctx context.Context, urlPath string, provider conf.AppAccessTokenProvider, ...) error
- func PostJSONWithTenantAccessToken(ctx context.Context, urlPath string, provider conf.TenantAccessTokenProvider, ...) error
- type APIError
- type APIOptions
- type APIResultBase
- type HTTPClient
Constants ¶
This section is empty.
Variables ¶
var (
// DefaultURLBase 是默认的 api 地址前缀
DefaultURLBase = "https://open.feishu.cn/open-apis"
)
Functions ¶
func GetJSON ¶
GetJSON 使用 GET 方法调用位于 URLBase+urlPath 的接口,params 是 url 上的参数,result 是响应的 body, 用 json 编码; 调用者可使用 APIOptions 附着到 ctx 来调整调用配置
func GetJSONWithAppAccessToken ¶
func GetJSONWithAppAccessToken(ctx context.Context, urlPath string, provider conf.AppAccessTokenProvider, params url.Values, result interface{}) error
GetJSONWithAppAccessToken 类似于 GetJSON,不过 Authorization 头部会添加 app access token
func GetJSONWithTenantAccessToken ¶
func GetJSONWithTenantAccessToken(ctx context.Context, urlPath string, provider conf.TenantAccessTokenProvider, params url.Values, result interface{}) error
GetJSONWithTenantAccessToken 类似于 GetJSON,不过 Authorization 头部会添加 tenant access token
func PostJSON ¶
PostJSON 使用 POST 方法调用位于 URLBase+urlPath 的接口,body 是请求的 body,result 是响应的 body, 两者均用 json 编码/解码; 调用者可使用 APIOptions 附着到 ctx 来调整调用配置
func PostJSONWithAppAccessToken ¶
func PostJSONWithAppAccessToken(ctx context.Context, urlPath string, provider conf.AppAccessTokenProvider, body interface{}, result interface{}) error
PostJSONWithAppAccessToken 类似于 PostJSON,不过 Authorization 头部会添加 app access token
func PostJSONWithTenantAccessToken ¶
func PostJSONWithTenantAccessToken(ctx context.Context, urlPath string, provider conf.TenantAccessTokenProvider, body interface{}, result interface{}) error
PostJSONWithTenantAccessToken 类似于 PostJSON,不过 Authorization 头部会添加 tenant access token
Types ¶
type APIOptions ¶
type APIOptions struct {
// URLBase 是 api 地址前缀,若空使用 DefaultURLBase.
// NOTE: URLBase 结尾的 '/' 会被截取掉
URLBase string
// Client 是使用的 http client, 若空使用 http.DefaultClient
Client HTTPClient
}
APIOptions 是调用 api 时的配置
func CtxAPIOptions ¶
func CtxAPIOptions(ctx context.Context) APIOptions
CtxAPIOptions 从 context.Context 中获得 APIOptions, 若 context.Context 没有,则返回全局默认
type APIResultBase ¶
type APIResultBase struct {
// Code 是错码,非 0 表示错误
Code int `json:"code"`
// Msg 是错误描述
Msg string `json:"msg"`
}
APIResultBase 是 api 返回结果基础字段
func (*APIResultBase) ResultError ¶
func (result *APIResultBase) ResultError() error
ResultError 在 Code 非 0 的时候返回非 nil error