handler

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package handler provides HTTP client functionality and request building utilities for interacting with the dify API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PutRequestBuilder

func PutRequestBuilder(pool *sync.Pool, v *RequestBuilder)

PutRequestBuilder puts a RequestBuilder back into the pool.

Types

type Builder

type Builder interface {
	// BaseURL sets the base url for the request
	BaseURL(baseURL string) Builder
	// Path sets the Path relative to the base URL (e.g., "/v1/users").
	Path(path string) Builder
	// PathParm add a path parameter to the request Path.
	PathParm(param string) Builder
	// Token sets the token used in the request headers
	Token(token string) Builder
	// Method sets the http Method
	Method(method string) Builder
	// Body sets the request Body payload
	Body(body any) Builder
	// Query add a Query struct to the request.
	Query(queryStruct any) Builder
	// Headers .
	Headers(headers map[string]string) Builder
	// Build return the Request
	Build() (Request, error)
}

Builder defines the interface for building an API request.

type Client

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

Client is a http client that execute requests.

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient returns a client to execute requests.

func (*Client) Send

func (c *Client) Send(ctx context.Context, req Request) (*Response, error)

Send sends a HTTP request and returns response.

func (*Client) SendStream

func (c *Client) SendStream(ctx context.Context, req Request, evh chan *Event) error

SendStream sends an HTTP request and returns streaming responses via the provided channel.

type ClientOption

type ClientOption func(options *ClientOptions)

ClientOption defines a functional option for configuring the client.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the timeout duration for the http client.

type ClientOptions

type ClientOptions struct {
	Timeout time.Duration
}

ClientOptions defines config options for the client.

type Event added in v0.1.1

type Event struct {
	Type string
	Data io.Reader
	Done bool
}

Event is an http server-sent event

type Request

type Request struct {
	BaseURL   string
	AuthToken string
	Path      string
	Method    string
	Body      any
	Headers   map[string]string
	Query     []any
}

Request holds the config for a http request.

type RequestBuilder

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

RequestBuilder implements the Builder interface for constructing a Request.

func GetRequestBuilder

func GetRequestBuilder(pool *sync.Pool) *RequestBuilder

GetRequestBuilder gets a RequestBuilder from the provided pool.

func NewRequestBuilder

func NewRequestBuilder() *RequestBuilder

NewRequestBuilder creates a new instance of RequestBuilder.

func (*RequestBuilder) BaseURL

func (r *RequestBuilder) BaseURL(baseURL string) Builder

BaseURL sets the base URL for the request.

func (*RequestBuilder) Body

func (r *RequestBuilder) Body(body any) Builder

Body sets the request Body.

func (*RequestBuilder) Build

func (r *RequestBuilder) Build() (Request, error)

Build return a request.

func (*RequestBuilder) Headers

func (r *RequestBuilder) Headers(headers map[string]string) Builder

Headers add header to the request.

func (*RequestBuilder) Method

func (r *RequestBuilder) Method(method string) Builder

Method sets the HTTP Method.

func (*RequestBuilder) Path

func (r *RequestBuilder) Path(path string) Builder

Path sets the request Path.

func (*RequestBuilder) PathParm

func (r *RequestBuilder) PathParm(param string) Builder

PathParm add a path parameter to the request Path.

func (*RequestBuilder) Query

func (r *RequestBuilder) Query(queryStruct any) Builder

Query add a Query struct to the request.

func (*RequestBuilder) Reset

func (r *RequestBuilder) Reset()

Reset the builder's request.

func (*RequestBuilder) Token

func (r *RequestBuilder) Token(token string) Builder

Token sets the authentication token.

type Response

type Response struct {
	StatusCode int
	Body       []byte
	Headers    http.Header
}

Response holds the response data for an API request.

Jump to

Keyboard shortcuts

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