Skip to content

Commit

Permalink
Merge branch 'release/v1.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Nov 5, 2024
2 parents cede997 + aa6438d commit a2d1ad2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ">=1.21.0"
go-version: ">=1.22.0"
cache-dependency-path: |
${{ env.GOPATH }}/${{ env.package }}/go.mod
${{ env.GOPATH }}/${{ env.package }}/go.sum
Expand Down
23 changes: 8 additions & 15 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,16 @@ type SDKClient struct {
}

// NewSDKClient init sdk client
func NewSDKClient(appID string, secret string) *SDKClient {
return &SDKClient{
func NewSDKClient(appID string, secret string, opts ...Option) *SDKClient {
ret := &SDKClient{
httpClient: defaultHttpClient(),
appID: appID,
secret: secret,
}
}

func (c *SDKClient) SetHttpClient(httpClient *http.Client) {
c.httpClient = httpClient
}

func (c *SDKClient) WithTracer(namespace string) {
c.tracer = NewOtel(namespace, c.AppID())
}

// SetDebug set debug mode
func (c *SDKClient) SetDebug(debug bool) {
c.debug = debug
for _, opt := range opts {
opt(ret)
}
return ret
}

func (c *SDKClient) AppID() string {
Expand Down
24 changes: 24 additions & 0 deletions core/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package core

import "net/http"

type Option = func(c *SDKClient)

func WithHttpClient(httpClient *http.Client) Option {
return func(c *SDKClient) {
c.httpClient = httpClient
}
}

func WithTracer(namespace string) Option {
return func(c *SDKClient) {
c.tracer = NewOtel(namespace, c.AppID())
}
}

// SetDebug set debug mode
func WithDebug(debug bool) Option {
return func(c *SDKClient) {
c.debug = debug
}
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module github.com/bububa/baidu-marketing

go 1.21
go 1.22

require (
go.opentelemetry.io/otel v1.29.0
go.opentelemetry.io/otel/metric v1.29.0
go.opentelemetry.io/otel/trace v1.29.0
go.opentelemetry.io/otel v1.31.0
go.opentelemetry.io/otel/metric v1.31.0
go.opentelemetry.io/otel/trace v1.31.0
)

require (
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw=
go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8=
go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc=
go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8=
go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4=
go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit a2d1ad2

Please sign in to comment.