httpclient

package
v0.1.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth interface {
	Token(ctx context.Context) (string, error)
}

func NewJWTAuth

func NewJWTAuth(client *JWTOAuthClient, opt *GetJWTAccessTokenReq) Auth

func NewTokenAuth

func NewTokenAuth(accessToken string) Auth

NewTokenAuth creates a new token authentication instance.

type Backoff

type Backoff struct {
	// contains filtered or unexported fields
}

func NewBackoff

func NewBackoff(baseDelay, maxDelay time.Duration) *Backoff

func (*Backoff) Retry

func (b *Backoff) Retry(ctx context.Context, f func() error, retryTimes int) error

func (*Backoff) Wait

func (b *Backoff) Wait(ctx context.Context, currentRetryTimes int) error

type BaseResponse

type BaseResponse struct {
	Code  int    `json:"code"`
	Msg   string `json:"msg"`
	LogID string
}

func (*BaseResponse) GetCode

func (b *BaseResponse) GetCode() int

func (*BaseResponse) GetLogID

func (b *BaseResponse) GetLogID() string

func (*BaseResponse) GetMsg

func (b *BaseResponse) GetMsg() string

func (*BaseResponse) SetLogID

func (b *BaseResponse) SetLogID(logID string)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL string, httpClient HTTPClient, auth Auth, options *ClientOptions) *Client

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, params map[string]string, resp OpenAPIResponse) error

func (*Client) GetWithRetry

func (c *Client) GetWithRetry(ctx context.Context, path string, params map[string]string, resp OpenAPIResponse, retryTimes int) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any, resp OpenAPIResponse) error

func (*Client) PostStream added in v0.1.12

func (c *Client) PostStream(ctx context.Context, path string, body any) (*http.Response, error)

func (*Client) PostWithRetry

func (c *Client) PostWithRetry(ctx context.Context, path string, body any, resp OpenAPIResponse, retryTimes int) error

func (*Client) UploadFile

func (c *Client) UploadFile(ctx context.Context, path string, fileName string, reader io.Reader, form map[string]string, resp OpenAPIResponse) error

type ClientOptions

type ClientOptions struct {
	Timeout        time.Duration
	UploadTimeout  time.Duration
	HeaderEnricher func(ctx context.Context, req *http.Request)
}

type GetJWTAccessTokenReq

type GetJWTAccessTokenReq struct {
	TTL         time.Duration `json:"ttl,omitempty"`          // Token validity period (in seconds)
	Scope       *Scope        `json:"scope,omitempty"`        // Permission scope
	SessionName *string       `json:"session_name,omitempty"` // Session name
	AccountID   *int64        `json:"account_id,omitempty"`   // Account ID
}

GetJWTAccessTokenReq represents options for getting JWT OAuth token

type GrantType

type GrantType string

GrantType represents the OAuth grant type

const (
	GrantTypeAuthorizationCode GrantType = "authorization_code"
	GrantTypeDeviceCode        GrantType = "urn:ietf:params:oauth:grant-type:device_code"
	GrantTypeJWTCode           GrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer"
	GrantTypeRefreshToken      GrantType = "refresh_token"
)

func (GrantType) String

func (r GrantType) String() string

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient an interface for making HTTP requests

type JWTOAuthClient

type JWTOAuthClient struct {
	*OAuthClient
	// contains filtered or unexported fields
}

JWTOAuthClient represents the JWT OAuth core

func NewJWTOAuthClient

func NewJWTOAuthClient(param NewJWTOAuthClientParam, opts ...OAuthClientOption) (*JWTOAuthClient, error)

NewJWTOAuthClient creates a new JWT OAuth core

func (*JWTOAuthClient) GetAccessToken

func (c *JWTOAuthClient) GetAccessToken(ctx context.Context, opts *GetJWTAccessTokenReq) (*OAuthToken, error)

GetAccessToken gets the access token, using options pattern

type NewJWTOAuthClientParam

type NewJWTOAuthClientParam struct {
	ClientID      string
	PublicKey     string
	PrivateKeyPEM string
	TTL           time.Duration
}

type OAuthClient

type OAuthClient struct {
	// contains filtered or unexported fields
}

OAuthClient represents the base OAuth core structure

type OAuthClientOption

type OAuthClientOption func(*oauthOption)

func WithAuthBaseURL

func WithAuthBaseURL(baseURL string) OAuthClientOption

WithAuthBaseURL adds base URL

func WithAuthHttpClient

func WithAuthHttpClient(client HTTPClient) OAuthClientOption

func WithAuthWWWURL

func WithAuthWWWURL(wwwURL string) OAuthClientOption

WithAuthWWWURL adds base URL

type OAuthToken

type OAuthToken struct {
	BaseResponse
	AccessToken  string `json:"access_token"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"refresh_token,omitempty"`
}

OAuthToken represents the OAuth token response

type OpenAPIResponse

type OpenAPIResponse interface {
	GetCode() int
	GetMsg() string
	GetLogID() string
	SetLogID(string)
}

type Scope

type Scope struct {
	AccountPermission   *ScopeAccountPermission   `json:"account_permission"`
	AttributeConstraint *ScopeAttributeConstraint `json:"attribute_constraint,omitempty"`
}

Scope represents the OAuth scope

type ScopeAccountPermission

type ScopeAccountPermission struct {
	PermissionList []string `json:"permission_list"`
}

ScopeAccountPermission represents the account permissions in the scope

type ScopeAttributeConstraint

type ScopeAttributeConstraint struct {
	ConnectorBotChatAttribute *ScopeAttributeConstraintConnectorBotChatAttribute `json:"connector_bot_chat_attribute"`
}

ScopeAttributeConstraint represents the attribute constraints in the scope

type ScopeAttributeConstraintConnectorBotChatAttribute

type ScopeAttributeConstraintConnectorBotChatAttribute struct {
	BotIDList []string `json:"bot_id_list"`
}

ScopeAttributeConstraintConnectorBotChatAttribute represents the bot chat attributes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL