Documentation
¶
Index ¶
- Constants
- func DecodeRequestBody(w http.ResponseWriter, r *http.Request, v interface{}) error
- func NewMuxHTTPClient(user *model.User) *http.Client
- func SetAPIMux(mux *http.ServeMux)
- func StreamData[P Pointer[T], T any](c *HTTPClient, ctx context.Context, method string, path string, ...) error
- func WriteResponse(status int, w http.ResponseWriter, r *http.Request, v interface{}) error
- type HTTPClient
- func (c *HTTPClient) AppendUserAgent(userAgent string) RESTClient
- func (c *HTTPClient) ClearHeaders() RESTClient
- func (c *HTTPClient) Close()
- func (c *HTTPClient) Delete(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) DeleteHeader(key string) RESTClient
- func (c *HTTPClient) Get(ctx context.Context, path string, response interface{}) (int, error)
- func (c *HTTPClient) GetAuthToken() string
- func (c *HTTPClient) GetBaseURL() string
- func (c *HTTPClient) GetJSON(ctx context.Context, path string, response interface{}) (int, error)
- func (c *HTTPClient) Post(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) PostJSON(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) PostWithContentType(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) Put(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) PutJSON(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) PutWithContentType(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *HTTPClient) SendData(ctx context.Context, method string, path string, request interface{}, ...) (int, error)
- func (c *HTTPClient) SendDataWithContentType(ctx context.Context, method string, path string, request interface{}, ...) (int, error)
- func (c *HTTPClient) SendDataWithContentTypeAndAccept(ctx context.Context, method string, path string, request interface{}, ...) (int, error)
- func (c *HTTPClient) SetAccept(accept ...string) RESTClient
- func (c *HTTPClient) SetAuthToken(token string) RESTClient
- func (c *HTTPClient) SetBaseUrl(baseURL string) (RESTClient, error)
- func (c *HTTPClient) SetContentType(contentType string) RESTClient
- func (c *HTTPClient) SetHeader(key, value string) RESTClient
- func (c *HTTPClient) SetTimeout(timeout time.Duration) RESTClient
- func (c *HTTPClient) SetTokenFormat(format string) RESTClient
- func (c *HTTPClient) SetTokenKey(key string) RESTClient
- func (c *HTTPClient) SetUserAgent(userAgent string) RESTClient
- type MuxClient
- func (c *MuxClient) AppendUserAgent(userAgent string) RESTClient
- func (c *MuxClient) ClearHeaders() RESTClient
- func (c *MuxClient) Delete(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *MuxClient) DeleteHeader(key string) RESTClient
- func (c *MuxClient) Get(ctx context.Context, path string, response interface{}) (int, error)
- func (c *MuxClient) GetAuthToken() string
- func (c *MuxClient) GetBaseURL() string
- func (c *MuxClient) GetJSON(ctx context.Context, path string, response interface{}) (int, error)
- func (c *MuxClient) Post(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *MuxClient) PostJSON(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *MuxClient) Put(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *MuxClient) PutJSON(ctx context.Context, path string, request interface{}, response interface{}, ...) (int, error)
- func (c *MuxClient) RoundTrip(req *http.Request) (*http.Response, error)
- func (c *MuxClient) SetAccept(accept ...string) RESTClient
- func (c *MuxClient) SetAuthToken(token string) RESTClient
- func (c *MuxClient) SetBaseUrl(baseURL string) (RESTClient, error)
- func (c *MuxClient) SetContentType(contentType string) RESTClient
- func (c *MuxClient) SetHeader(key, value string) RESTClient
- func (c *MuxClient) SetTimeout(timeout time.Duration) RESTClient
- func (c *MuxClient) SetTokenFormat(format string) RESTClient
- func (c *MuxClient) SetTokenKey(key string) RESTClient
- func (c *MuxClient) SetUserAgent(userAgent string) RESTClient
- type Pointer
- type RESTClient
- type StreamResponseFunc
- type StreamWriter
Constants ¶
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 NewMuxHTTPClient ¶ added in v0.23.0
NewMuxHTTPClient creates an *http.Client that routes requests through the API mux with the given user injected into context for authentication. This allows standard HTTP clients (like mcpopenai.Client) to make in-process API calls without needing a valid auth token.
func StreamData ¶
func StreamData[P Pointer[T], T any]( c *HTTPClient, 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 HTTPClient ¶ added in v0.23.0
func NewClient ¶
func NewClient(baseURL string, token string, insecureSkipVerify bool) (*HTTPClient, error)
func NewUnixSocketClient ¶ added in v0.23.7
func NewUnixSocketClient(host string) (*HTTPClient, error)
NewUnixSocketClient creates an HTTPClient that communicates over a Unix socket or plain TCP, depending on the host string format (same formats Docker accepts). No TLS, no HTTP/2 — Docker/Podman sockets don't use them.
func (*HTTPClient) AppendUserAgent ¶ added in v0.23.0
func (c *HTTPClient) AppendUserAgent(userAgent string) RESTClient
func (*HTTPClient) ClearHeaders ¶ added in v0.23.0
func (c *HTTPClient) ClearHeaders() RESTClient
func (*HTTPClient) Close ¶ added in v0.23.0
func (c *HTTPClient) Close()
func (*HTTPClient) DeleteHeader ¶ added in v0.23.0
func (c *HTTPClient) DeleteHeader(key string) RESTClient
func (*HTTPClient) GetAuthToken ¶ added in v0.23.0
func (c *HTTPClient) GetAuthToken() string
func (*HTTPClient) GetBaseURL ¶ added in v0.23.0
func (c *HTTPClient) GetBaseURL() string
func (*HTTPClient) GetJSON ¶ added in v0.23.0
GetJSON sends a GET request with JSON accept header (thread-safe)
func (*HTTPClient) PostJSON ¶ added in v0.23.0
func (c *HTTPClient) PostJSON(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
PostJSON sends a POST request with JSON content type and JSON accept header (thread-safe)
func (*HTTPClient) PostWithContentType ¶ added in v0.23.0
func (*HTTPClient) PutJSON ¶ added in v0.23.0
func (c *HTTPClient) PutJSON(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
PutJSON sends a PUT request with JSON content type and JSON accept header (thread-safe)
func (*HTTPClient) PutWithContentType ¶ added in v0.23.0
func (*HTTPClient) SendDataWithContentType ¶ added in v0.23.0
func (c *HTTPClient) SendDataWithContentType(ctx context.Context, method string, path string, request interface{}, response interface{}, successCode int, contentType string) (int, error)
SendDataWithContentType sends a request with a specific content type (thread-safe)
func (*HTTPClient) SendDataWithContentTypeAndAccept ¶ added in v0.23.0
func (c *HTTPClient) SendDataWithContentTypeAndAccept(ctx context.Context, method string, path string, request interface{}, response interface{}, successCode int, contentType string, accept string) (int, error)
SendDataWithContentTypeAndAccept sends a request with specific content type and accept header (thread-safe)
func (*HTTPClient) SetAccept ¶ added in v0.23.0
func (c *HTTPClient) SetAccept(accept ...string) RESTClient
func (*HTTPClient) SetAuthToken ¶ added in v0.23.0
func (c *HTTPClient) SetAuthToken(token string) RESTClient
func (*HTTPClient) SetBaseUrl ¶ added in v0.23.0
func (c *HTTPClient) SetBaseUrl(baseURL string) (RESTClient, error)
func (*HTTPClient) SetContentType ¶ added in v0.23.0
func (c *HTTPClient) SetContentType(contentType string) RESTClient
func (*HTTPClient) SetHeader ¶ added in v0.23.0
func (c *HTTPClient) SetHeader(key, value string) RESTClient
func (*HTTPClient) SetTimeout ¶ added in v0.23.0
func (c *HTTPClient) SetTimeout(timeout time.Duration) RESTClient
func (*HTTPClient) SetTokenFormat ¶ added in v0.23.0
func (c *HTTPClient) SetTokenFormat(format string) RESTClient
func (*HTTPClient) SetTokenKey ¶ added in v0.23.0
func (c *HTTPClient) SetTokenKey(key string) RESTClient
func (*HTTPClient) SetUserAgent ¶ added in v0.23.0
func (c *HTTPClient) SetUserAgent(userAgent string) RESTClient
type MuxClient ¶ added in v0.23.0
type MuxClient struct {
// contains filtered or unexported fields
}
MuxClient calls API handlers directly via mux without HTTP overhead
func (*MuxClient) AppendUserAgent ¶ added in v0.23.0
func (c *MuxClient) AppendUserAgent(userAgent string) RESTClient
func (*MuxClient) ClearHeaders ¶ added in v0.23.0
func (c *MuxClient) ClearHeaders() RESTClient
func (*MuxClient) DeleteHeader ¶ added in v0.23.0
func (c *MuxClient) DeleteHeader(key string) RESTClient
func (*MuxClient) GetAuthToken ¶ added in v0.23.0
func (*MuxClient) GetBaseURL ¶ added in v0.23.0
func (*MuxClient) RoundTrip ¶ added in v0.23.0
RoundTrip implements http.RoundTripper by routing the request through the API mux with the user injected into context for authentication.
func (*MuxClient) SetAccept ¶ added in v0.23.0
func (c *MuxClient) SetAccept(accept ...string) RESTClient
func (*MuxClient) SetAuthToken ¶ added in v0.23.0
func (c *MuxClient) SetAuthToken(token string) RESTClient
func (*MuxClient) SetBaseUrl ¶ added in v0.23.0
func (c *MuxClient) SetBaseUrl(baseURL string) (RESTClient, error)
func (*MuxClient) SetContentType ¶ added in v0.23.0
func (c *MuxClient) SetContentType(contentType string) RESTClient
func (*MuxClient) SetHeader ¶ added in v0.23.0
func (c *MuxClient) SetHeader(key, value string) RESTClient
func (*MuxClient) SetTimeout ¶ added in v0.23.0
func (c *MuxClient) SetTimeout(timeout time.Duration) RESTClient
func (*MuxClient) SetTokenFormat ¶ added in v0.23.0
func (c *MuxClient) SetTokenFormat(format string) RESTClient
func (*MuxClient) SetTokenKey ¶ added in v0.23.0
func (c *MuxClient) SetTokenKey(key string) RESTClient
func (*MuxClient) SetUserAgent ¶ added in v0.23.0
func (c *MuxClient) SetUserAgent(userAgent string) RESTClient
type RESTClient ¶
type RESTClient interface {
Get(ctx context.Context, path string, response interface{}) (int, error)
Post(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
Put(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
Delete(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
PostJSON(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
PutJSON(ctx context.Context, path string, request interface{}, response interface{}, successCode int) (int, error)
GetJSON(ctx context.Context, path string, response interface{}) (int, error)
SetTimeout(timeout time.Duration) RESTClient
SetContentType(contentType string) RESTClient
SetAccept(accept ...string) RESTClient
SetUserAgent(userAgent string) RESTClient
AppendUserAgent(userAgent string) RESTClient
SetAuthToken(token string) RESTClient
SetTokenKey(key string) RESTClient
SetTokenFormat(format string) RESTClient
SetHeader(key, value string) RESTClient
DeleteHeader(key string) RESTClient
ClearHeaders() RESTClient
GetBaseURL() string
GetAuthToken() string
SetBaseUrl(baseURL string) (RESTClient, error)
}
RESTClient interface for both HTTP and Mux clients
func NewMuxClient ¶ added in v0.23.0
func NewMuxClient(user *model.User) RESTClient
NewMuxClient creates a client that calls mux directly
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
func (*StreamWriter) WriteEvent ¶ added in v0.23.0
func (sw *StreamWriter) WriteEvent(eventType string, data any) error
WriteEvent writes an SSE comment event in the format ":eventType:jsonData\n\n" This is used for tool status notifications that standard OpenAI clients ignore