Documentation
¶
Index ¶
- Constants
- func DecodeRequestBody(w http.ResponseWriter, r *http.Request, v interface{}) error
- func StreamData[P Pointer[T], T any](c *RESTClient, ctx context.Context, method string, path string, ...) error
- func WriteResponse(status int, w http.ResponseWriter, r *http.Request, v interface{}) error
- type Pointer
- type RESTClient
- func (c *RESTClient) AppendUserAgent(userAgent string) *RESTClient
- func (c *RESTClient) ClearHeaders() *RESTClient
- func (c *RESTClient) Close()
- func (c *RESTClient) Delete(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *RESTClient) DeleteHeader(key string) *RESTClient
- func (c *RESTClient) Get(ctx context.Context, path string, response interface{}) (int, error)
- func (c *RESTClient) Post(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *RESTClient) Put(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *RESTClient) SendData(ctx context.Context, method string, path string, request interface{}, ...) (int, error)
- func (c *RESTClient) SetAccept(accept ...string) *RESTClient
- func (c *RESTClient) SetAuthToken(token string) *RESTClient
- func (c *RESTClient) SetBaseUrl(baseURL string) (*RESTClient, error)
- func (c *RESTClient) SetContentType(contentType string) *RESTClient
- func (c *RESTClient) SetHeader(key, value string) *RESTClient
- func (c *RESTClient) SetTimeout(timeout time.Duration) *RESTClient
- func (c *RESTClient) SetTokenFormat(format string) *RESTClient
- func (c *RESTClient) SetTokenKey(key string) *RESTClient
- func (c *RESTClient) SetUserAgent(userAgent string) *RESTClient
- type StreamResponseFunc
- type StreamWriter
Constants ¶
View Source
const ( ContentTypeJSON = "application/json" ContentTypeMsgPack = "application/msgpack" )
Variables ¶
This section is empty.
Functions ¶
func DecodeRequestBody ¶
func DecodeRequestBody(w http.ResponseWriter, r *http.Request, v interface{}) error
DecodeRequestBody decodes JSON or Msgpack data from the request body into a struct
func StreamData ¶
func StreamData[P Pointer[T], T any]( c *RESTClient, ctx context.Context, method string, path string, request interface{}, fn func(P) (bool, error), ) error
Thin generic wrapper - only this small function is duplicated per type
func WriteResponse ¶
WriteResponse encodes and writes a JSON or Msgpack response
Types ¶
type RESTClient ¶
func NewClient ¶
func NewClient(baseURL string, token string, insecureSkipVerify bool) (*RESTClient, error)
func (*RESTClient) AppendUserAgent ¶
func (c *RESTClient) AppendUserAgent(userAgent string) *RESTClient
func (*RESTClient) ClearHeaders ¶
func (c *RESTClient) ClearHeaders() *RESTClient
func (*RESTClient) Close ¶
func (c *RESTClient) Close()
func (*RESTClient) DeleteHeader ¶
func (c *RESTClient) DeleteHeader(key string) *RESTClient
func (*RESTClient) SetAccept ¶ added in v0.19.0
func (c *RESTClient) SetAccept(accept ...string) *RESTClient
func (*RESTClient) SetAuthToken ¶
func (c *RESTClient) SetAuthToken(token string) *RESTClient
func (*RESTClient) SetBaseUrl ¶
func (c *RESTClient) SetBaseUrl(baseURL string) (*RESTClient, error)
func (*RESTClient) SetContentType ¶
func (c *RESTClient) SetContentType(contentType string) *RESTClient
func (*RESTClient) SetHeader ¶
func (c *RESTClient) SetHeader(key, value string) *RESTClient
func (*RESTClient) SetTimeout ¶
func (c *RESTClient) SetTimeout(timeout time.Duration) *RESTClient
func (*RESTClient) SetTokenFormat ¶
func (c *RESTClient) SetTokenFormat(format string) *RESTClient
func (*RESTClient) SetTokenKey ¶
func (c *RESTClient) SetTokenKey(key string) *RESTClient
func (*RESTClient) SetUserAgent ¶
func (c *RESTClient) SetUserAgent(userAgent string) *RESTClient
type StreamResponseFunc ¶
type StreamWriter ¶
type StreamWriter struct {
// contains filtered or unexported fields
}
StreamWriter writes chunks using Server-Sent Events
func NewStreamWriter ¶ added in v0.19.0
func NewStreamWriter(w http.ResponseWriter, r *http.Request) *StreamWriter
NewStreamWriter creates a new stream writer
func (*StreamWriter) WriteChunk ¶
func (sw *StreamWriter) WriteChunk(chunk interface{}) error
WriteChunk writes a single chunk as SSE
func (*StreamWriter) WriteEnd ¶
func (sw *StreamWriter) WriteEnd() error
WriteEnd signals the end of the stream
Click to show internal directories.
Click to hide internal directories.