service

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Type string `config:"type"`

	// type: basic
	Username string `config:"username"`
	Password string `config:"password"`

	// type: bearer
	Token string `config:"token"`

	// type: jwt
	Secret string `config:"secret"`

	// type: oauth2
	Provider     string   `config:"provider"`
	ClientID     string   `config:"client_id"`
	ClientSecret string   `config:"client_secret"`
	RedirectURL  string   `config:"redirect_url"`
	Scopes       []string `config:"scopes"`
}

type HealthCheck

type HealthCheck struct {
	Enable bool `config:"enable"`

	//
	Method string  `config:"method,default=GET"`
	Path   string  `config:"path,default=/health"`
	Status []int64 `config:"status,default=[200]"`

	// Interval is the health check interval in seconds
	Interval int64 `config:"interval"`
	// Timeout is the health check timeout in seconds
	Timeout int64 `config:"timeout"`

	// ok means health check is ok, ignore real check
	Ok bool `config:"ok"`
}

type Request

type Request struct {
	Path    RequestPath       `config:"path"`
	Headers map[string]string `config:"headers"`
	Query   map[string]string `config:"query"`
}

type RequestPath

type RequestPath struct {
	DisablePrefixRewrite bool     `config:"disable_prefix_rewrite"`
	Rewrites             []string `config:"rewrites"`
}

type Response

type Response struct {
	Headers map[string]string `config:"headers"`
}

type Server added in v1.6.0

type Server struct {
	// Required fields
	Name string `config:"name"`
	Port int64  `config:"port"`

	// Optional fields
	Protocol string `config:"protocol"`
	Weight   int64  `config:"weight,default=1"`
	Disabled bool   `config:"disabled,default=false"`

	// Optional override configurations
	Request     *Request     `config:"request"`
	Response    *Response    `config:"response"`
	Auth        *Auth        `config:"auth"`
	HealthCheck *HealthCheck `config:"health_check"`
	// contains filtered or unexported fields
}

Server represents a single backend server instance

func (*Server) GetEffectiveConfig added in v1.6.0

func (s *Server) GetEffectiveConfig(base *Service) *Service

GetEffectiveConfig merges the server's override configurations with the base service configuration

func (*Server) Host added in v1.6.0

func (s *Server) Host() string

Host returns the host:port string

func (*Server) ID added in v1.6.0

func (s *Server) ID() string

ID returns a unique identifier for the server

func (*Server) IsHealthy added in v1.6.0

func (s *Server) IsHealthy() bool

IsHealthy returns the health status of the server

func (*Server) SetHealthy added in v1.6.0

func (s *Server) SetHealthy(healthy bool)

SetHealthy sets the health status of the server

func (*Server) Target added in v1.6.0

func (s *Server) Target() string

Target returns the full target URL

type Service

type Service struct {
	// === 单服务模式字段(向后兼容)===
	Name     string `config:"name"`
	Port     int64  `config:"port"`
	Protocol string `config:"protocol,default=http"`

	// === 多服务模式字段 ===
	Algorithm string   `config:"algorithm,default=round-robin"`
	Servers   []Server `config:"servers"`

	// === 共享配置 ===
	Request     Request     `config:"request"`
	Response    Response    `config:"response"`
	Auth        Auth        `config:"auth"`
	HealthCheck HealthCheck `config:"health_check"`
}

func (*Service) CheckDNS added in v1.2.0

func (s *Service) CheckDNS() (ips []string, err error)

func (*Service) Host

func (s *Service) Host() string

func (*Service) IsMultiServer added in v1.6.0

func (s *Service) IsMultiServer() bool

IsMultiServer checks if the service is configured for multi-server mode

func (*Service) Rewrite

func (s *Service) Rewrite(originPath string) (newPath string)

func (*Service) Target

func (s *Service) Target() string

Jump to

Keyboard shortcuts

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