diff --git a/README.md b/README.md index da27359..7817c44 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Dada Logistics Open Platform SDK For Golang Language -[![Go Report Card](https://goreportcard.com/badge/github.com/houseme/imdada-go)](https://goreportcard.com/report/github.com/houseme/imdada-go) -[![Go Reference](https://pkg.go.dev/badge/github.com/houseme/imdada-go.svg)](https://pkg.go.dev/github.com/houseme/imdada-go) -[![ImDada-CI](https://github.com/houseme/imdada-go/actions/workflows/go.yml/badge.svg)](https://github.com/houseme/imdada-go/actions/workflows/go.yml) -![GitHub](https://img.shields.io/github/license/houseme/imdada-go?style=flat-square) -![GitHub go.mod Go version (branch)](https://img.shields.io/github/go-mod/go-version/houseme/imdada-go/main?style=flat-square) +[![Go Report Card](https://goreportcard.com/badge/github.com/houseme/imdadago)](https://goreportcard.com/report/github.com/houseme/imdadago) +[![Go Reference](https://pkg.go.dev/badge/github.com/houseme/imdadago.svg)](https://pkg.go.dev/github.com/houseme/imdadago) +[![ImDada-CI](https://github.com/houseme/imdadago/actions/workflows/go.yml/badge.svg)](https://github.com/houseme/imdadago/actions/workflows/go.yml) +![GitHub](https://img.shields.io/github/license/houseme/imdadago?style=flat-square) +![GitHub go.mod Go version (branch)](https://img.shields.io/github/go-mod/go-version/houseme/imdadago/main?style=flat-square) Dada logistics information service open platform SDK for Golang language. Help you save costs and achieve efficient distribution @@ -12,7 +12,7 @@ Help you save costs and achieve efficient distribution ## Installation ```bash -go get -u -v github.com/houseme/imdada-go@main +go get -u -v github.com/houseme/imdadago@main ``` ## Usage @@ -24,12 +24,12 @@ import ( "context" "fmt" - "github.com/houseme/imdada-go" + "github.com/houseme/imdadago" ) func main() { ctx := context.Background() - d := dada.New(ctx, dada.WithAppKey("xxxxx"), dada.WithAppSecret("xxxxx")) + d := dadago.New(ctx, dada.WithAppKey("xxxxx"), dada.WithAppSecret("xxxxx")) fmt.Println("Dada:", d) } diff --git a/constant.go b/constant.go index e5b2ec9..4630032 100644 --- a/constant.go +++ b/constant.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ -package dada +package dadago const ( // version is the default version of ImDada. diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..848f103 --- /dev/null +++ b/doc.go @@ -0,0 +1,21 @@ +/* + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * You can obtain one at https://github.com/houseme/imdadago. + * + */ + +// Package dadago is the ImDaDa-go client. +package dadago diff --git a/domain.go b/domain.go new file mode 100644 index 0000000..8c1f343 --- /dev/null +++ b/domain.go @@ -0,0 +1,139 @@ +/* + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * You can obtain one at https://github.com/houseme/imdadago. + * + */ + +package dadago + +import ( + "time" + + "github.com/cloudwego/hertz/pkg/common/hlog" + "github.com/cloudwego/hertz/pkg/protocol" + + "github.com/houseme/imdadago/domain" +) + +// Level is the log level. +type Level hlog.Level + +// Logger is the logger. +type Logger hlog.FullLogger + +// options is the configuration for the ImDada client. +type options struct { + AppKey string + AppSecret string + SourceID string + Gateway string + Callback string + ShopNo string + LogPath string // 日志路径 + Level Level // 日志级别 + TimeOut time.Duration + UserAgent []byte + Debug bool +} + +// Option the option is an ImDada option. +type Option func(o *options) + +// WithAppKey sets the app key. +func WithAppKey(appKey string) Option { + return func(o *options) { + o.AppKey = appKey + } +} + +// WithAppSecret sets the app secret. +func WithAppSecret(appSecret string) Option { + return func(o *options) { + o.AppSecret = appSecret + } +} + +// WithSourceID sets the source id. +func WithSourceID(sourceID string) Option { + return func(o *options) { + o.SourceID = sourceID + } +} + +// WithGateway sets the gateway. +func WithGateway(gateway string) Option { + return func(o *options) { + o.Gateway = gateway + } +} + +// WithTimeOut sets the timeout. +func WithTimeOut(timeout time.Duration) Option { + return func(o *options) { + o.TimeOut = timeout + } +} + +// WithUserAgent sets the user agent. +func WithUserAgent(userAgent []byte) Option { + return func(o *options) { + o.UserAgent = userAgent + } +} + +// WithDebug sets the debug. +func WithDebug(debug bool) Option { + return func(o *options) { + o.Debug = debug + } +} + +// WithCallback sets the callback. +func WithCallback(callback string) Option { + return func(o *options) { + o.Callback = callback + } +} + +// WithShopNo sets the shop no. +func WithShopNo(shopNo string) Option { + return func(o *options) { + o.ShopNo = shopNo + } +} + +// WithLogPath sets the log path. +func WithLogPath(logPath string) Option { + return func(o *options) { + o.LogPath = logPath + } +} + +// WithLevel sets the log level. +func WithLevel(level Level) Option { + return func(o *options) { + o.Level = level + } +} + +// Client is the ImDada client. +type Client struct { + request *domain.Request + response *protocol.Response + log Logger + op options + gateway string +} diff --git a/domain/doc.go b/domain/doc.go new file mode 100644 index 0000000..d4727b6 --- /dev/null +++ b/domain/doc.go @@ -0,0 +1,21 @@ +/* + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * You can obtain one at https://github.com/houseme/imdadago. + * + */ + +// Package domain is the ImDaDaGo client. +package domain diff --git a/domain/imdada.go b/domain/imdada.go index 5cd6265..001e674 100644 --- a/domain/imdada.go +++ b/domain/imdada.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ // Package domain is the domain of ImDaDa. diff --git a/domain/merchant.go b/domain/merchant.go index 2310d8a..20828c6 100644 --- a/domain/merchant.go +++ b/domain/merchant.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ // Package domain is the domain of ImDaDa. diff --git a/domain/orders.go b/domain/orders.go index d8778e8..ad61c73 100644 --- a/domain/orders.go +++ b/domain/orders.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ // Package domain is the domain of ImDaDa. diff --git a/domain/recharge.go b/domain/recharge.go index 4d6d3f5..06a358c 100644 --- a/domain/recharge.go +++ b/domain/recharge.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ // Package domain is the domain of ImDaDa. diff --git a/go.mod b/go.mod index 350e9fd..45b093b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/houseme/imdada-go +module github.com/houseme/imdadago go 1.19 @@ -11,7 +11,7 @@ require ( ) require ( - github.com/BurntSushi/toml v1.2.1 // indirect + github.com/BurntSushi/toml v1.3.2 // indirect github.com/andeya/ameda v1.5.3 // indirect github.com/andeya/goutil v1.0.1 // indirect github.com/bytedance/go-tagexpr/v2 v2.9.8 // indirect @@ -22,7 +22,6 @@ require ( github.com/golang/protobuf v1.5.3 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/nyaruka/phonenumbers v1.1.7 // indirect - github.com/tidwall/gjson v1.14.4 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect diff --git a/go.sum b/go.sum index ed8f18c..910d364 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= -github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/andeya/ameda v1.5.3 h1:SvqnhQPZwwabS8HQTRGfJwWPl2w9ZIPInHAw9aE1Wlk= github.com/andeya/ameda v1.5.3/go.mod h1:FQDHRe1I995v6GG+8aJ7UIUToEmbdTJn/U26NCPIgXQ= github.com/andeya/goutil v1.0.1 h1:eiYwVyAnnK0dXU5FJsNjExkJW4exUGn/xefPt3k4eXg= @@ -7,13 +7,9 @@ github.com/andeya/goutil v1.0.1/go.mod h1:jEG5/QnnhG7yGxwFUX6Q+JGMif7sjdHmmNVjn7 github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bytedance/go-tagexpr/v2 v2.9.2/go.mod h1:5qsx05dYOiUXOUgnQ7w3Oz8BYs2qtM/bJokdLb79wRM= -github.com/bytedance/go-tagexpr/v2 v2.9.7 h1:y1b2Qv1fYFNpFEQ1jC3DCB2NZZNrKIpUYRiEj7TfUYE= -github.com/bytedance/go-tagexpr/v2 v2.9.7/go.mod h1:SyfF2dfcKGKIfTL2trRu+LW4x2mH6ehuigpkvv9JtpY= github.com/bytedance/go-tagexpr/v2 v2.9.8 h1:p1PWxiUPxAdzreRBRbC9M2k7tf1cZYkds58NLypXbg4= github.com/bytedance/go-tagexpr/v2 v2.9.8/go.mod h1:UAyKh4ZRLBPGsyTRFZoPqTni1TlojMdOJXQnEIPCX84= github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7/go.mod h1:2ZlV9BaUH4+NXIBF0aMdKKAnHTzqH+iMU4KUjAbL23Q= -github.com/bytedance/gopkg v0.0.0-20230324090325-a00d8057bef9 h1:YTSJ7dHOZHZJxCwj4WuLPAwKGIbWs2fiMY2CatwDToQ= -github.com/bytedance/gopkg v0.0.0-20230324090325-a00d8057bef9/go.mod h1:5tCTcGDVBC/YUpwmVUI14jYgkemT1CAeUyQe0J5DLUs= github.com/bytedance/gopkg v0.0.0-20230531144706-a12972768317 h1:SReMVmTCeJ5Nf0hU8nyWu7gAaFVD8mu5yvSH/+uLT1E= github.com/bytedance/gopkg v0.0.0-20230531144706-a12972768317/go.mod h1:FtQG3YbQG9L/91pbKSw787yBQPutC+457AvDW77fgUQ= github.com/bytedance/mockey v1.2.1 h1:g84ngI88hz1DR4wZTL3yOuqlEcq67MretBfQUdXwrmw= @@ -30,7 +26,6 @@ github.com/cloudwego/hertz v0.3.2/go.mod h1:hnv3B7eZ6kMv7CKFHT2OC4LU0mA4s5XPyu/S github.com/cloudwego/hertz v0.6.4 h1:H6FGXZrtjjG/MwgxYi4k8baKZEwDuz0qHgSihoymJ2o= github.com/cloudwego/hertz v0.6.4/go.mod h1:KhztQcZtMQ46gOjZcmCy557AKD29cbumGEV0BzwevwA= github.com/cloudwego/netpoll v0.2.6/go.mod h1:1T2WVuQ+MQw6h6DpE45MohSvDTKdy2DlzCx2KsnPI4E= -github.com/cloudwego/netpoll v0.3.2 h1:/998ICrNMVBo4mlul4j7qcIeY7QnEfuCCPPwck9S3X4= github.com/cloudwego/netpoll v0.3.2/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ= github.com/cloudwego/netpoll v0.4.0 h1:kJ2jMsT5FtlGSNtInnprJf386TFE/rGWzl8kp0wWxx4= github.com/cloudwego/netpoll v0.4.0/go.mod h1:xVefXptcyheopwNDZjDPcfU6kIjZXZ4nY550k1yH9eQ= @@ -59,8 +54,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -71,8 +64,6 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM= github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk= github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= -github.com/nyaruka/phonenumbers v1.1.6 h1:DcueYq7QrOArAprAYNoQfDgp0KetO4LqtnBtQC6Wyes= -github.com/nyaruka/phonenumbers v1.1.6/go.mod h1:yShPJHDSH3aTKzCbXyVxNpbl2kA+F+Ne5Pun/MvFRos= github.com/nyaruka/phonenumbers v1.1.7 h1:5UUI9hE79Kk0dymSquXbMYB7IlNDNhvu2aNlJpm9et8= github.com/nyaruka/phonenumbers v1.1.7/go.mod h1:DC7jZd321FqUe+qWSNcHi10tyIyGNXGcNbfkPvdp1Vs= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -98,8 +89,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/tidwall/gjson v1.9.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= -github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= @@ -110,8 +99,6 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= -go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= @@ -145,13 +132,9 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220110181412-a018aaa089fe/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -159,8 +142,6 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/imdada.go b/imdada.go index 5f8a338..c27898a 100644 --- a/imdada.go +++ b/imdada.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ -// Package dada is the ImDaDa-go client. -package dada +package dadago import ( "context" @@ -37,121 +36,17 @@ import ( "github.com/cloudwego/hertz/pkg/protocol" "github.com/cloudwego/hertz/pkg/protocol/consts" - "github.com/houseme/imdada-go/domain" - "github.com/houseme/imdada-go/internal/log" + "github.com/houseme/imdadago/domain" + "github.com/houseme/imdadago/internal/log" ) -// options is the configuration for the ImDada client. -type options struct { - AppKey string - AppSecret string - SourceID string - Gateway string - Callback string - ShopNo string - LogPath string // 日志路径 - Level hlog.Level // 日志级别 - TimeOut time.Duration - UserAgent []byte - Debug bool -} - -// Option the option is an ImDada option. -type Option func(o *options) - -// WithAppKey sets the app key. -func WithAppKey(appKey string) Option { - return func(o *options) { - o.AppKey = appKey - } -} - -// WithAppSecret sets the app secret. -func WithAppSecret(appSecret string) Option { - return func(o *options) { - o.AppSecret = appSecret - } -} - -// WithSourceID sets the source id. -func WithSourceID(sourceID string) Option { - return func(o *options) { - o.SourceID = sourceID - } -} - -// WithGateway sets the gateway. -func WithGateway(gateway string) Option { - return func(o *options) { - o.Gateway = gateway - } -} - -// WithTimeOut sets the timeout. -func WithTimeOut(timeout time.Duration) Option { - return func(o *options) { - o.TimeOut = timeout - } -} - -// WithUserAgent sets the user agent. -func WithUserAgent(userAgent []byte) Option { - return func(o *options) { - o.UserAgent = userAgent - } -} - -// WithDebug sets the debug. -func WithDebug(debug bool) Option { - return func(o *options) { - o.Debug = debug - } -} - -// WithCallback sets the callback. -func WithCallback(callback string) Option { - return func(o *options) { - o.Callback = callback - } -} - -// WithShopNo sets the shop no. -func WithShopNo(shopNo string) Option { - return func(o *options) { - o.ShopNo = shopNo - } -} - -// WithLogPath sets the log path. -func WithLogPath(logPath string) Option { - return func(o *options) { - o.LogPath = logPath - } -} - -// WithLevel sets the log level. -func WithLevel(level hlog.Level) Option { - return func(o *options) { - o.Level = level - } -} - -// Client is the ImDada client. -type Client struct { - request *domain.Request - response *protocol.Response - log hlog.FullLogger - op options - gateway string -} - // New creates a new ImDada client. func New(ctx context.Context, opts ...Option) *Client { op := options{ - TimeOut: 5 * time.Second, + TimeOut: 10 * time.Second, UserAgent: []byte(userAgent), Gateway: gateway, - Level: hlog.LevelDebug, + Level: Level(hlog.LevelDebug), LogPath: os.TempDir(), } @@ -161,7 +56,7 @@ func New(ctx context.Context, opts ...Option) *Client { c := &Client{ op: op, - log: log.InitLog(ctx, op.LogPath, op.Level), + log: log.InitLog(ctx, op.LogPath, hlog.Level(op.Level)), response: &protocol.Response{}, request: &domain.Request{ AppKey: op.AppKey, @@ -170,7 +65,7 @@ func New(ctx context.Context, opts ...Option) *Client { SourceID: op.SourceID, }, } - c.log.SetLevel(op.Level) + c.log.SetLevel(hlog.Level(op.Level)) c.log.CtxInfof(ctx, "im dada init client start level:%s", op.Level) return c } diff --git a/internal/log/log.go b/internal/log/log.go index 557d7f1..9383d47 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -1,5 +1,5 @@ /* - * Copyright `IMDaDa-Go` Author(https://houseme.github.io/imdada-go/). All Rights Reserved. + * Copyright `IMDaDaGo` Author(https://houseme.github.io/imdadago/). All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * You can obtain one at https://github.com/houseme/imdada-go. + * You can obtain one at https://github.com/houseme/imdadago. */ package log @@ -82,6 +82,7 @@ func InitLog(ctx context.Context, path string, level hlog.Level) hlog.FullLogger defer logger.Sync() hlog.SetLogger(logger) hlog.SetLevel(level) + logger.CtxDebugf(ctx, "init log success level:%s", level) return logger }