native

package
v4.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package native implements seven of the proxy-node package's v2 routes in the package itself. Legacy handlers and native routes share the rows, so a route can switch between them at any time, and the answers are byte-compatible with the legacy handlers (internal/tests/proxynodecompat).

  • The load balancer list, detail, creation, update and deletion work on the kernel's v2_load_balancer table, adopted in place (kernel.storage.adopt). Only these routes use it.
  • A node's runtime logs come from the adopted v2_node_log table, which the kernel's agent control writes when nodes report logs.
  • The node statistics, and whether a node exists, come from the kernel view kapi_node_status_v1: each node's id, status, last check and traffic counters.

The package never reads v2_node or v2_node_protocol. v2_node holds each node's API key, key hash and shared secret, which the kernel's node authentication checks (UniProxy, the node API, the agent WebSocket and gRPC control stream, agent package downloads): a package that could read or write them could act as any node, and so read every subscriber's proxy credentials. Both are protected kernel tables. The other 24 routes stay bridged; packages/proxy-node/control lists why for each.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadBalancer

type LoadBalancer struct {
	ID            uint   `gorm:"primaryKey"`
	Name          string `gorm:"size:100"`
	GroupID       uint   `gorm:"index"`
	Strategy      string `gorm:"size:20;default:round-robin"`
	HealthCheck   bool   `gorm:"default:true"`
	CheckInterval int    `gorm:"default:60"`
	CheckTimeout  int    `gorm:"default:10"`
	NodeWeights   string `gorm:"type:text"`
	Enabled       bool   `gorm:"default:true"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

LoadBalancer is a v2_load_balancer row. Its column defaults are the kernel model's: GORM writes them for zero values on create, so a new load balancer always starts with health checks on and enabled.

func (LoadBalancer) TableName

func (LoadBalancer) TableName() string

TableName is the adopted kernel table.

type NodeLog

type NodeLog struct {
	ID         uint `gorm:"primaryKey"`
	NodeID     uint
	Level      string
	Source     string
	Message    string
	TraceID    string
	FieldsJSON string
	LoggedAt   *time.Time
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

NodeLog is a v2_node_log row: a runtime log line a node reported.

func (NodeLog) TableName

func (NodeLog) TableName() string

TableName is the adopted kernel table.

type Service

type Service struct {
	// Open returns the package's storage connection, on which the adopted
	// tables and the kapi_node_status_v1 view are visible.
	Open func(ctx context.Context) (*gorm.DB, error)
	// Now defaults to time.Now.
	Now func() time.Time
}

Service holds what the native routes need.

func (*Service) CreateLoadBalancer

func (s *Service) CreateLoadBalancer(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)

CreateLoadBalancer is POST /api/v2/admin/loadbalancers.

func (*Service) DeleteLoadBalancer

func (s *Service) DeleteLoadBalancer(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)

DeleteLoadBalancer is DELETE /api/v2/admin/loadbalancers/:id. Deleting a load balancer that does not exist succeeds, as in the kernel.

func (*Service) GetLoadBalancer

GetLoadBalancer is GET /api/v2/admin/loadbalancers/:id.

func (*Service) GetNodeLogs

GetNodeLogs is GET /api/v2/admin/nodes/:id/logs: a node's runtime logs, newest first, filtered by level (normalized as the kernel stores it), source and a search in the message, source and trace id.

func (*Service) GetNodeStats

GetNodeStats is GET /api/v2/admin/nodes/stats. A node is online when it checked in within five minutes, whatever its status; offline is what is neither online nor pending.

func (*Service) Handlers

func (s *Service) Handlers() map[string]pluginhostsdk.NativeHandler

Handlers returns the native handlers by route id.

func (*Service) ListLoadBalancers

func (s *Service) ListLoadBalancers(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)

ListLoadBalancers is GET /api/v2/admin/loadbalancers.

func (*Service) UpdateLoadBalancer

func (s *Service) UpdateLoadBalancer(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)

UpdateLoadBalancer is PUT /api/v2/admin/loadbalancers/:id: the request applied to the stored row, which is then saved whole.

Jump to

Keyboard shortcuts

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