Skip to content

Commit

Permalink
support customize signRequestFunc for sc client (#66)
Browse files Browse the repository at this point in the history
* Update options.go

support customize signRequestFunc  for sc client

* Update client.go

support customize signRequestFunc for sc-client
  • Loading branch information
Wanghb1 authored Dec 28, 2024
1 parent 09f3c3d commit 29f8e09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ type Client struct {
watchers map[string]bool
mutex sync.Mutex
// addresspool mutex
poolMutex sync.Mutex
wsDialer *websocket.Dialer
poolMutex sync.Mutex
wsDialer *websocket.Dialer
// record the websocket connection with the service center
conns map[string]*websocket.Conn
revision string
Expand Down Expand Up @@ -162,6 +162,10 @@ func (c *Client) buildClientOptions(opt Options) *httpclient.Options {
if !opt.EnableAuth {
return options
}
if opt.SignRequest != nil {
options.SignRequest = opt.SignRequest
return options
}
// when the authentication is enabled, the token of automatic renewal is added to the request header
if opt.TokenExpiration == 0 {
opt.TokenExpiration = DefaultTokenExpiration
Expand Down
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sc
import (
"context"
"crypto/tls"
"net/http"
"time"

"github.com/go-chassis/cari/rbac"
Expand All @@ -22,6 +23,7 @@ type Options struct {
AuthUser *rbac.AuthUser
AuthToken string
TokenExpiration time.Duration
SignRequest func(*http.Request) error
}

// CallOptions is options when you call a API
Expand Down

0 comments on commit 29f8e09

Please sign in to comment.