diff --git a/README.md b/README.md index 1198b49148ee0507f9405cac2253ae260873a480..aa0b46e2305a21d1828358cdc31218f49255dbd5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ -# library + +## stbz/library + +胜天åŠå内部调用库 +## åœ°å€ + + https://gitlab.jxhh.com/stbz/library + +## é™åˆ¶ + + golang版本 >= 1.14 + +## 使用方法 + +```php + use Stbz\Api\SupplyClient; + //appkeyã€appSecret 在开放平å°èŽ·å– https://open.jxhh.com + $appKey = "your appkey"; + $appSecret = "your appSecret"; + + try { + $supplyClient = new SupplyClient($appKey,$appSecret); + } catch (OssException $e) { + printf(__FUNCTION__ . "creating supplyClient instance: FAILED\n"); + printf($e->getMessage() . "\n"); + return null; + } + + //获å–商å“列表 + $param = ['page'=>1, 'limit'=>20, 'source'=>2];//è¯·æ±‚å‚æ•° + $method = 'get';//请求方法 + $action = 'v2/Goods/Lists';//请求资æºå + $response = $supplyClient->getApiResponse($method,$action,$param); +``` + + diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..06c213c31a908ac16f2e6bd6963fbe9499904920 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module gitlab.jxhh.com/stbz/library + +go 1.16 + +require github.com/gogf/gf v1.16.6 diff --git a/logs/logs.go b/logs/logs.go new file mode 100644 index 0000000000000000000000000000000000000000..64e96a7d6dcb1cc7f50e791b835be9685b5fac4b --- /dev/null +++ b/logs/logs.go @@ -0,0 +1,51 @@ +package logs + +import ( + "fmt" + "github.com/gogf/gf/errors/gerror" + "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/os/glog" +) + + +type RequestLogReq struct { + Path string //å˜å‚¨è·¯å¾„ + RequestURI string //请求URI + RequestID string //请求RequestID + Method string //请求方法 + Params string //è¯·æ±‚å‚æ•° + Response string //å“åº”å‚æ•° + Err error //é”™è¯¯ä¿¡æ¯ + ServerName string //请求æœåŠ¡åç§° + ResponseTime string //å“应时间 +} + +//统一请求日志 20211208 gk +func RequestLog(req RequestLogReq){ + Info(req.Path, "请求ID:ã€%v】 æœåŠ¡åç§°: ã€%v】 请求路径:ã€%v】 请求方法: ã€%v】 è¯·æ±‚å‚æ•°: ã€%v】 å“åº”å‚æ•°: ã€%v】 å“应时间:ã€%v ms】error:ã€%v】", + req.RequestID, req.ServerName, req.RequestURI, req.Method, req.Params,req.Response, req.ResponseTime, req.Err.Error()) + if req.Err != nil { + Error("%+v",gerror.Wrap(req.Err, extra)) + } +} + +//记录info日志 20211208 gk +func Info(path string,format string, v ...interface{}) { + newPath := g.Log().GetPath() + "/" + path + glog.Path(newPath).File( "info-{Ymd}.log").Println(fmt.Sprintf(format, v...)) +} + +//记录error日志 20211208 gk +func Error(format string, v ...interface{}) { + newPath := g.Log().GetPath() + "/error/" + glog.Path(newPath).File("{Ymd}.log").Println(fmt.Sprintf(format, v...)) +} + +//检查错误 20211208 gk +func CheckErr(err error, extra string) bool { + if err != nil { + Error("%+v",gerror.Wrap(err, extra)) + return true + } + return false +} \ No newline at end of file