restc

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCodeField    = "code"
	DefaultDataField    = "data"
	DefaultMessageField = "msg"
)

Functions

This section is empty.

Types

type Client

type Client interface {
	Verb(verb string) *Request
	SetHeader(headers http.Header)
}

func NewClient

func NewClient(addr string, ops ...Opt) (Client, error)

type IntoOptions

type IntoOptions struct {
	WrapCodeMsg        bool
	WrapCodeMsgMapping WrapCodeMsgMapping
}

type Opt

type Opt func(client *client) error

func WithClient

func WithClient(c *http.Client) Opt

func WithHeaders

func WithHeaders(headers http.Header) Opt

func WithRequestMiddleware

func WithRequestMiddleware(middleware RequestMiddleware) Opt

func WithRetryDelay

func WithRetryDelay(time time.Duration) Opt

func WithRetryTimes

func WithRetryTimes(times int) Opt

type PathParam

type PathParam struct {
	Name  string
	Value any
}

type QueryParam

type QueryParam struct {
	Name  string
	Value any
}

type Request

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

Request allows for building up a request to a server in a chained fashion. Any errors are stored until the end of your call, so you only have to check once.

func NewRequest

func NewRequest(c *client) *Request

func (*Request) AddHeader

func (r *Request) AddHeader(key, value string)

func (*Request) Body

func (r *Request) Body(obj any) *Request

Body makes the request use obj as the body. Optional.

func (*Request) Do

func (r *Request) Do(ctx context.Context) Result

Do format and executes the request. Returns a Result object for easy response

func (*Request) GetBody

func (r *Request) GetBody() io.Reader

func (*Request) GetParams

func (r *Request) GetParams() string

func (*Request) GetPath added in v0.63.0

func (r *Request) GetPath() string

func (*Request) GetVerb added in v0.63.0

func (r *Request) GetVerb() string

func (*Request) Params

func (r *Request) Params(args ...QueryParam) *Request

func (*Request) Path

func (r *Request) Path(path string, args ...PathParam) *Request

Path set path

func (*Request) Stream

func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error)

Stream return io.ReadCloser

func (*Request) Verb

func (r *Request) Verb(verb string) *Request

type RequestMiddleware

type RequestMiddleware func(Client, *Request) error

type Result

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

Result contains the result of calling Request.Do().

func (Result) Error

func (r Result) Error() error

Error returns the error executing the request, nil if no error occurred.

func (Result) Into

func (r Result) Into(obj any, options *IntoOptions) error

Into stores the result into obj, if possible. If obj is nil it is ignored.

func (Result) RawResponse

func (r Result) RawResponse() ([]byte, error)

func (Result) Status

func (r Result) Status() string

Status returns the status executing the request

func (Result) StatusCode

func (r Result) StatusCode() int

StatusCode returns the HTTP status code of the request. (Only valid if no error was returned.)

type WrapCodeMsgMapping

type WrapCodeMsgMapping struct {
	Code string
	Data string
	Msg  string
}

Jump to

Keyboard shortcuts

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