Ai
1 Star 0 Fork 0

陈志端/jd-union-go-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api_config.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
陈志端 提交于 2022-01-25 17:20 +08:00 . 京东联盟Go SDK
package api
import (
"fmt"
"strings"
)
import (
"gitee.com/changeden/jd-union-go-sdk/common"
)
type apiConfig struct {
appKey string
appSecret string
serverAddress string
}
func NewApiConfig(appKey, appSecret string) *apiConfig {
inst := &apiConfig{
serverAddress: common.DefaultServer,
}
return inst.SetAppKey(appKey).SetAppSecret(appSecret)
}
func checkAppInfo(req string, msg string) (res string, err error) {
res = strings.TrimSpace(req)
if len(res) == 0 {
err = fmt.Errorf(msg)
}
return res, err
}
func checkAppKey(appKey string) (res string, err error) {
return checkAppInfo(appKey, "AppKey不能为空")
}
func checkAppSecret(appSecret string) (res string, err error) {
return checkAppInfo(appSecret, "AppSecret不能为空")
}
func (c *apiConfig) SetAppKey(appKey string) *apiConfig {
appKey, _ = checkAppKey(appKey)
c.appKey = appKey
return c
}
func (c *apiConfig) SetAppSecret(appSecret string) *apiConfig {
appSecret, _ = checkAppKey(appSecret)
c.appSecret = appSecret
return c
}
func (c *apiConfig) Build() (inst *api, err error) {
_, err = checkAppKey(c.appKey)
if err != nil {
return
}
_, err = checkAppSecret(c.appSecret)
if err != nil {
return
}
inst = newApi(c)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/changeden/jd-union-go-sdk.git
git@gitee.com:changeden/jd-union-go-sdk.git
changeden
jd-union-go-sdk
jd-union-go-sdk
v0.0.1

搜索帮助