client

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIConfig

type APIConfig struct {
	Path    string
	Query   map[string]string // Query use for http get request for set query params example.com/x?q1=v1&q2=v2
	Headers map[string]string // Headers set http header request
}

APIConfig standard external api path address

type Client

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

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, apiConfig *APIConfig) (*Response, error)

func (*Client) Get

func (c *Client) Get(ctx context.Context, apiConfig *APIConfig) (*Response, error)

Get do get request and return response

func (*Client) GetClient

func (c *Client) GetClient() *http.Client

func (*Client) GetOrganizationID

func (c *Client) GetOrganizationID() string

func (*Client) GetValidator

func (c *Client) GetValidator() *validator.Validate

func (*Client) Post

func (c *Client) Post(ctx context.Context, apiConfig *APIConfig, apiRequest any) (*Response, error)

Post do post request and return response

func (*Client) PostFile

func (c *Client) PostFile(ctx context.Context, apiConfig *APIConfig, body *bytes.Buffer, contentType string) (*Response, error)

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, apiConfig *APIConfig, method Method, apiRequest any) (*Response, error)

type Method

type Method int

Method is http method for request

const (
	POST Method = iota + 1
	GET
	PUT
	PATCH
	DELETE
)

func (Method) String

func (i Method) String() string

type Option

type Option func(client *Client)

func Concurrency

func Concurrency(n int) Option

Concurrency changes Client's concurrency level.

func SetEmptyMessageLimit

func SetEmptyMessageLimit(limit uint) Option

func Timeout

func Timeout(d time.Duration) Option

Timeout changes Client's timeout per request.

func WithCustomBaseURL

func WithCustomBaseURL(baseURL string) Option

func WithCustomClient

func WithCustomClient(client *http.Client) Option

WithCustomClient use custom http httpClient instead default httpClient

func WithOrganizationID

func WithOrganizationID(orgID string) Option

func WithRateLimit

func WithRateLimit(every time.Duration, requestPerTime int) Option

WithRateLimit make rate limit for example every time 5 * time.Second for 50 request

type Response

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

func (*Response) GetHttpResponse

func (r *Response) GetHttpResponse() *http.Response

GetHttpResponse return http response

func (*Response) GetJSON

func (r *Response) GetJSON(response any) error

GetJSON decode response body to your response

type Transporter

type Transporter interface {
	GetClient() *http.Client
	GetValidator() *validator.Validate
	GetOrganizationID() string
	Get(ctx context.Context, apiConfig *APIConfig) (*Response, error)
	Post(ctx context.Context, apiConfig *APIConfig, apiRequest any) (*Response, error)
	PostFile(ctx context.Context, apiConfig *APIConfig, body *bytes.Buffer, contentType string) (*Response, error)
	Delete(ctx context.Context, apiConfig *APIConfig) (*Response, error)
}

func New

func New(apiKeys []string, opts ...Option) (Transporter, error)

New create openai client

Jump to

Keyboard shortcuts

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