client

package
v0.0.0-...-da2a1ef Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02"

DateFormat is the format used for date (without time) parameters.

Variables

This section is empty.

Functions

func BindFormExplodeParam

func BindFormExplodeParam(paramName string, required bool, queryParams url.Values, dest interface{}) error

BindFormExplodeParam binds a form-style parameter with explode to a destination. Form style is the default for query and cookie parameters. This handles the exploded case where arrays come as multiple query params. Arrays: ?param=a&param=b -> []string{"a", "b"} (values passed as slice) Objects: ?key1=value1&key2=value2 -> struct{Key1, Key2} (queryParams passed)

func BindSimpleParam

func BindSimpleParam(paramName string, paramLocation ParamLocation, value string, dest interface{}) error

BindSimpleParam binds a simple-style parameter without explode to a destination. Simple style is the default for path and header parameters. Arrays: a,b,c -> []string{"a", "b", "c"} Objects: key1,value1,key2,value2 -> struct{Key1, Key2}

func BindStringToObject

func BindStringToObject(src string, dst interface{}) error

BindStringToObject binds a string value to a destination object. It handles primitives, encoding.TextUnmarshaler, and the Binder interface.

func NewAddPetRequest

func NewAddPetRequest(server string, body addPetJSONRequestBody) (*http.Request, error)

NewAddPetRequest creates a POST request for /pets with application/json body

func NewAddPetRequestWithBody

func NewAddPetRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)

NewAddPetRequestWithBody creates a POST request for /pets with any body

func NewDeletePetRequest

func NewDeletePetRequest(server string, id int64) (*http.Request, error)

NewDeletePetRequest creates a DELETE request for /pets/{id}

func NewFindPetByIDRequest

func NewFindPetByIDRequest(server string, id int64) (*http.Request, error)

NewFindPetByIDRequest creates a GET request for /pets/{id}

func NewFindPetsRequest

func NewFindPetsRequest(server string, params *FindPetsParams) (*http.Request, error)

NewFindPetsRequest creates a GET request for /pets

func StyleFormExplodeParam

func StyleFormExplodeParam(paramName string, paramLocation ParamLocation, value interface{}) (string, error)

StyleFormExplodeParam serializes a value using form style (RFC 6570) with exploding. Form style is the default for query and cookie parameters. Primitives: paramName=value Arrays: paramName=a&paramName=b&paramName=c Objects: key1=value1&key2=value2

func StyleSimpleParam

func StyleSimpleParam(paramName string, paramLocation ParamLocation, value interface{}) (string, error)

StyleSimpleParam serializes a value using simple style (RFC 6570) without exploding. Simple style is the default for path and header parameters. Arrays are comma-separated: a,b,c Objects are key,value pairs: key1,value1,key2,value2

Types

type Binder

type Binder interface {
	Bind(value string) error
}

Binder is an interface for types that can bind themselves from a string value.

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

NewClient creates a new Client with reasonable defaults.

func (*Client) AddPet

func (c *Client) AddPet(ctx context.Context, body addPetJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

AddPet makes a POST request to /pets with JSON body

func (*Client) AddPetWithBody

func (c *Client) AddPetWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

AddPetWithBody makes a POST request to /pets Creates a new pet

func (*Client) DeletePet

func (c *Client) DeletePet(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)

DeletePet makes a DELETE request to /pets/{id} Deletes a pet by ID

func (*Client) FindPetByID

func (c *Client) FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)

FindPetByID makes a GET request to /pets/{id} Returns a pet by ID

func (*Client) FindPets

func (c *Client) FindPets(ctx context.Context, params *FindPetsParams, reqEditors ...RequestEditorFn) (*http.Response, error)

FindPets makes a GET request to /pets Returns all pets

type ClientHttpError

type ClientHttpError[E any] struct {
	StatusCode int
	Body       E
	RawBody    []byte
}

ClientHttpError represents an HTTP error response from the server. The type parameter E is the type of the parsed error body.

func (*ClientHttpError[E]) Error

func (e *ClientHttpError[E]) Error() string

type ClientInterface

type ClientInterface interface {
	// FindPets makes a GET request to /pets
	FindPets(ctx context.Context, params *FindPetsParams, reqEditors ...RequestEditorFn) (*http.Response, error)
	// AddPetWithBody makes a POST request to /pets
	AddPetWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
	AddPet(ctx context.Context, body addPetJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
	// DeletePet makes a DELETE request to /pets/{id}
	DeletePet(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
	// FindPetByID makes a GET request to /pets/{id}
	FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
}

ClientInterface is the interface specification for the client.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type Date

type Date struct {
	time.Time
}

Date represents a date (without time) for OpenAPI date format.

func (Date) Format

func (d Date) Format(layout string) string

Format returns the date formatted according to layout.

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler for Date.

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler for Date.

type FindPetsParams

type FindPetsParams struct {
	// tags (optional)
	Tags *[]string `form:"tags" json:"tags"`
	// limit (optional)
	Limit *int32 `form:"limit" json:"limit"`
}

FindPetsParams defines parameters for FindPets.

type HttpRequestDoer

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

HttpRequestDoer performs HTTP requests. The standard http.Client implements this interface.

type ParamLocation

type ParamLocation int

ParamLocation indicates where a parameter is located in an HTTP request.

const (
	ParamLocationUndefined ParamLocation = iota
	ParamLocationQuery
	ParamLocationPath
	ParamLocationHeader
	ParamLocationCookie
)

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function.

type SimpleClient

type SimpleClient struct {
	*Client
}

SimpleClient wraps Client with typed responses for operations that have unambiguous response types. Methods return the success type directly, and HTTP errors are returned as *ClientHttpError[E] where E is the error type.

func NewSimpleClient

func NewSimpleClient(server string, opts ...ClientOption) (*SimpleClient, error)

NewSimpleClient creates a new SimpleClient which wraps a Client.

func (*SimpleClient) AddPet

func (c *SimpleClient) AddPet(ctx context.Context, body addPetJSONRequestBody, reqEditors ...RequestEditorFn) (petstore.Pet, error)

AddPet makes a POST request to /pets and returns the parsed response. Creates a new pet On success, returns the response body. On HTTP error, returns *ClientHttpError[petstore.Error].

func (*SimpleClient) FindPetByID

func (c *SimpleClient) FindPetByID(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (petstore.Pet, error)

FindPetByID makes a GET request to /pets/{id} and returns the parsed response. Returns a pet by ID On success, returns the response body. On HTTP error, returns *ClientHttpError[petstore.Error].

func (*SimpleClient) FindPets

func (c *SimpleClient) FindPets(ctx context.Context, params *FindPetsParams, reqEditors ...RequestEditorFn) ([]petstore.Pet, error)

FindPets makes a GET request to /pets and returns the parsed response. Returns all pets On success, returns the response body. On HTTP error, returns *ClientHttpError[petstore.Error].

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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