service

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package service provides common types used by services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

A Client is a struct used by services to make HTTP requests.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v any) (resp *http.Response, err error)

Do performs an HTTP request.

If v is nil, the response body is not closed, and the caller must close it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body any, opts ...RequestOpt) (*http.Request, error)

NewRequest creates a new HTTP request.

type Doer

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

A Doer is an interface for performing HTTP requests.

type ErrUnexpectedStatusCode

type ErrUnexpectedStatusCode struct {
	Expected int
	Actual   int
	Response *http.Response
}

An ErrUnexpectedStatusCode is an error returned when the HTTP response has an unexpected status code.

In includes the expected and actual codes, as well as the response.

func (ErrUnexpectedStatusCode) Error

func (e ErrUnexpectedStatusCode) Error() string

Error implements the error interface.

type RequestOpt

type RequestOpt func(*http.Request)

A RequestOpt is a functional option for configuring a Request.

func WithAPIKey

func WithAPIKey(key string) RequestOpt

WithAPIKey sets the API key for the request.

The default service key is used if this option is not provided or the value is empty.

type Service

type Service struct {
	Client Client
}

A Service is a common type for services, which wrap OpenAI API requests.

func New

func New(baseURL *url.URL, key string, doer Doer) *Service

New creates a new Service.

Jump to

Keyboard shortcuts

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