http

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package http 提供 HTTP API 调用工具

支持 REST API、GraphQL 等 HTTP 调用场景。

Index

Constants

View Source
const (
	// MaxResponseBodySize 最大响应体大小(10MB)
	// 防止恶意服务器返回超大响应导致 OOM
	MaxResponseBodySize = 10 * 1024 * 1024
)

Variables

This section is empty.

Functions

func Tools

func Tools(opts ...Option) []tool.Tool

Tools 返回 HTTP 相关工具集合

Types

type GraphQLInput

type GraphQLInput struct {
	Query     string         `json:"query" description:"GraphQL 查询语句"`
	Variables map[string]any `json:"variables,omitempty" description:"查询变量"`
}

GraphQLInput GraphQL 查询输入

type GraphQLOutput

type GraphQLOutput struct {
	Data   any      `json:"data"`
	Errors []string `json:"errors,omitempty"`
}

GraphQLOutput GraphQL 查询输出

type GraphQLTool

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

GraphQLTool GraphQL 工具

func NewGraphQLTool

func NewGraphQLTool(endpoint string, opts ...Option) *GraphQLTool

NewGraphQLTool 创建 GraphQL 工具

func (*GraphQLTool) Tool

func (t *GraphQLTool) Tool() tool.Tool

Tool 返回 GraphQL 工具

type HTTPTool

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

HTTPTool HTTP API 调用工具

func NewHTTPTool

func NewHTTPTool(opts ...Option) *HTTPTool

NewHTTPTool 创建 HTTP 工具

type Option

type Option func(*HTTPTool)

Option HTTP 工具选项

func WithAllowPrivateNetwork

func WithAllowPrivateNetwork() Option

WithAllowPrivateNetwork 允许访问内网地址(默认禁止,防止 SSRF)

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL 设置基础 URL

func WithHeaders

func WithHeaders(headers map[string]string) Option

WithHeaders 设置默认请求头

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout 设置超时时间

type RequestInput

type RequestInput struct {
	URL     string            `json:"url" description:"请求 URL"`
	Method  string            `json:"method" description:"HTTP 方法 (GET/POST/PUT/DELETE)"`
	Headers map[string]string `json:"headers,omitempty" description:"请求头"`
	Body    string            `json:"body,omitempty" description:"请求体 (JSON 字符串)"`
}

RequestInput GET 请求输入

type RequestOutput

type RequestOutput struct {
	StatusCode int               `json:"status_code"`
	Headers    map[string]string `json:"headers"`
	Body       string            `json:"body"`
}

RequestOutput 请求输出

Jump to

Keyboard shortcuts

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