agentproxy

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Forward

func Forward(targetURL, proxyURL string, w http.ResponseWriter, r *http.Request) error

Forward reverse-proxies the request to the target agent URL. Supports streaming via FlushInterval -1. Strips agent forwarding headers and increments hop counter.

func ForwardMiddleware

func ForwardMiddleware(cfg ForwardConfig) gin.HandlerFunc

ForwardMiddleware checks for X-Vaala-Agent-ID / X-Vaala-Agent-Tag headers and forwards the request to the target agent if found.

func ResolveAddress

func ResolveAddress(addresses []Address, addressTag, preferredTag, cacheKey string) (string, error)

ResolveAddress selects the best address for the target agent. Priority: addressTag -> preferredTag -> auto-probe (first reachable, cached 60s).

func ResolveProxyURL

func ResolveProxyURL(agentProxyURL, globalProxyURL string) string

ResolveProxyURL returns the proxy URL to use for forwarding. Priority: per-agent > global default.

Types

type Address

type Address struct {
	URL string `json:"url"`
	Tag string `json:"tag"`
}

func ParseAddresses

func ParseAddresses(raw string) []Address

ParseAddresses parses the JSON http_addresses field.

type AgentAddressFetcher

type AgentAddressFetcher func(agentID string) []Address

AgentAddressFetcher fetches merged addresses for an agent in agent mode. It combines DB sync with push-updated addresses.

type AgentResolver

type AgentResolver func(agentID, agentTag string) *models.Agent

AgentResolver resolves an agent by ID or tag.

type ForwardConfig

type ForwardConfig struct {
	SelfID            string
	Resolver          AgentResolver
	MasterAddrFetcher MasterAddressFetcher // master 模式使用 (新增)
	AgentAddrFetcher  AgentAddressFetcher  // agent 模式使用 (新增)
	GlobalProxyURL    string
	PreferredAddrTag  string
	IsMaster          bool // 区分 master/agent 模式 (新增)
}

ForwardConfig configures the forwarding middleware.

type MasterAddressFetcher

type MasterAddressFetcher func(agentID string, dbHTTPAddrs string) []Address

MasterAddressFetcher fetches merged addresses for an agent in master mode. It combines DB config with memory auto-detected addresses.

type RouteForwarder

type RouteForwarder struct {
	SelfID         string
	GetAgent       func(agentID string) *models.Agent
	GetAgentsByTag func(tag string) []*models.Agent
	GlobalProxyURL string
	PreferredTag   string
}

RouteForwarder holds dependencies needed for ForwardByRoute.

func (*RouteForwarder) ForwardByRoute

func (rf *RouteForwarder) ForwardByRoute(c *gin.Context, route *models.AgentRoute) (bool, error)

ForwardByRoute resolves the target agent from an AgentRoute and forwards the request. Returns true if the request was forwarded, false if it should be processed locally.

Jump to

Keyboard shortcuts

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