config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 17 Imported by: 1

Documentation

Overview

Package config provides gateway configuration related functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServer

func NewServer(opt ...server.Option) *server.Server

NewServer parses the yaml config file to quickly start the server with multiple services. The config file is ./trpc_go.yaml by default and can be set by the flag -conf. This method should be called only once.

func RegisterConfLoader

func RegisterConfLoader(provider string, loader Loader)

RegisterConfLoader register a router config loader

func RegisterCustomTransOpts

func RegisterCustomTransOpts(protocol string, f CustomTransportOpts)

RegisterCustomTransOpts registers custom protocol options

func RegisterRouteLoader

func RegisterRouteLoader(protocol string, f LoadRouterFunc)

RegisterRouteLoader registers a route loading function

Types

type Config

type Config struct {
	Global struct {
		ConfProvider string `yaml:"conf_provider"` // Routing configuration provider, file, etcd etc.
	}
	Server struct {
		Service []*ServiceConfig // Configuration of a single service
	}
}

Config is the implementation of trpc configuration, divided into four major sections: global configuration (global), server configuration (server), client configuration (client), and plugin configuration (plugins).

type CustomTransportOpts

type CustomTransportOpts func(opts ...ServerOption)

CustomTransportOpts defines a function type for custom options

func GetCustomTransOpts

func GetCustomTransOpts(protocol string) CustomTransportOpts

GetCustomTransOpts returns custom protocol options

type LoadRouterFunc

type LoadRouterFunc func(provider string) error

LoadRouterFunc is a function type for dynamically loading routers

func GetRouteLoader

func GetRouteLoader(protocol string) LoadRouterFunc

GetRouteLoader returns a route loading function

type Loader

type Loader interface {
	// LoadConf 加载配置
	LoadConf(ctx context.Context, protocol string) error
}

Loader is the interface for configuration loaders.

func GetConfLoader

func GetConfLoader(provider string) Loader

GetConfLoader returns a router config loader

type ServerOption

type ServerOption func(o *ServerOptions)

ServerOption defines a function that can be used to configure a ServerOptions.

func WithMaxCons

func WithMaxCons(cons int) ServerOption

WithMaxCons sets the maximum number of concurrent connections.

func WithMaxConsPerIP

func WithMaxConsPerIP(cons int) ServerOption

WithMaxConsPerIP sets the maximum number of concurrent connections per IP.

func WithMaxRequestBodySize

func WithMaxRequestBodySize(size int) ServerOption

WithMaxRequestBodySize sets the maximum size of the request body.

func WithReadBufferSize

func WithReadBufferSize(size int) ServerOption

WithReadBufferSize sets the size of the buffer for reading the request.

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) ServerOption

WithReadTimeout sets the maximum duration for reading the request.

func WithReusePort

func WithReusePort(b bool) ServerOption

WithReusePort sets the reuse port option.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) ServerOption

WithWriteTimeout sets the maximum duration for writing the response.

type ServerOptions

type ServerOptions struct {
	transport.ServerTransportOptions
	// Handler is the handler to use for the server.
	Handler fasthttp.RequestHandler
	// MaxCons is the maximum number of concurrent connections.
	MaxCons int
	// MaxConsPerIP is the maximum number of concurrent connections per IP.
	MaxConsPerIP int
	// ReadTimeout is the maximum duration for reading the request.
	ReadTimeout time.Duration
	// WriteTimeout is the maximum duration for writing the response.
	WriteTimeout time.Duration
	// MaxRequestBodySize is the maximum size of the request body.
	MaxRequestBodySize int
	// ReadBufferSize is the size of the buffer for reading the request.
	ReadBufferSize int
}

ServerOptions are server settings options.

type ServiceConfig

type ServiceConfig struct {
	IP       string   `yaml:"ip"` // IP address to listen to.
	Name     string   // Service name in the format: trpc.app.server.service. Used for naming the service.
	Nic      string   // Network Interface Card (NIC) to listen to. No need to configure.
	Port     uint16   // Port to listen to.
	Address  string   // Address to listen to. If set, ipport will be ignored. Otherwise, ipport will be used.
	Network  string   // Network type like tcp/udp.
	Protocol string   // Protocol type like trpc.
	Timeout  int      // Longest time in milliseconds for a handler to handle a request.
	Idletime int      // Maximum idle time in milliseconds for a server connection. Default is 1 minute.
	Registry string   // Registry to use, e.g., polaris.
	Filter   []string // Filters for the service.

	// additional configuration settings for the trpc framework.
	// MaxCons refers to the maximum number of allowed connections for a service.
	MaxCons int `yaml:"max_cons"`
	// MaxConsPerIP refers to the maximum number of allowed connections per individual IP address.
	MaxConsPerIP int `yaml:"max_cons_per_ip"`
	// MaxRequestBodySize refers to the maximum size or volume allowed for the request body in a request.
	MaxRequestBodySize string `yaml:"max_request_body_size"`
	// ReadBufferSize  refers to the size or capacity of the read buffer,
	// which is used for storing incoming data during the reading process.
	ReadBufferSize string `yaml:"read_buffer_size"`
}

ServiceConfig is the configuration for each service. A single service process can support multiple services.

Directories

Path Synopsis
Package configmock is a generated GoMock package.
Package configmock is a generated GoMock package.

Jump to

Keyboard shortcuts

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