You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-library/service/eastiot/app.go

40 lines
877 B

2 years ago
package eastiot
import (
"errors"
2 years ago
"go.dtapp.net/library/utils/gohttp"
"go.dtapp.net/library/utils/gomongo"
2 years ago
"net/http"
"time"
)
type App struct {
AppID string
ApiKey string
2 years ago
Mongo gomongo.App // 日志数据库
2 years ago
}
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
// 公共参数
params["appId"] = app.AppID
params["timeStamp"] = time.Now().Unix()
// 签名
params["sign"] = app.getSign(app.ApiKey, params)
switch method {
case http.MethodGet:
// 请求
2 years ago
get, err := gohttp.Get(url, params)
// 日志
2 years ago
go app.mongoLog(url, params, method, get)
2 years ago
return get.Body, err
case http.MethodPost:
// 请求
2 years ago
postJson, err := gohttp.PostForm(url, params)
// 日志
2 years ago
go app.mongoLog(url, params, method, postJson)
2 years ago
return postJson.Body, err
default:
return nil, errors.New("请求类型不支持")
2 years ago
}
}