server

package
v0.0.0-...-d32eb86 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectName          = "APISERVER"
	DefaultConfigType    = "yaml"
	DefaultEnvKeyReplace = "_"
)

ProjectName defines the name of this API server project. Constants for default configurations.

Variables

This section is empty.

Functions

func LoadConfig

func LoadConfig(cfg string, defaultName string) error

LoadConfig loads the API server configuration from a given file or a default location.

Types

type APIServer

type APIServer struct {
	SecureServingInfo   *SecureServingInfo
	InsecureServingInfo *InsecureServingInfo
	ShutdownTimeout     time.Duration
	*gin.Engine

	RateLimit *RateLimitInfo
	// contains filtered or unexported fields
}

APIServer wraps the gin.Engine with specific configurations and capabilities.

func (*APIServer) Close

func (s *APIServer) Close()

Close gracefully shuts down both the insecure and secure servers.

func (*APIServer) InstallAPIs

func (s *APIServer) InstallAPIs()

InstallAPIs installs specific endpoints to the server based on its configuration.

func (*APIServer) InstallMiddlewares

func (s *APIServer) InstallMiddlewares()

InstallMiddlewares sets up any global middlewares for the server.

func (*APIServer) Run

func (s *APIServer) Run() error

Run starts the API server. It sets up and runs both the insecure and secure servers.

func (*APIServer) Setup

func (s *APIServer) Setup()

Setup customizes gin settings, mainly for debugging purposes.

type CertKey

type CertKey struct {
	CertFile string // Path to the PEM-encoded certificate.
	KeyFile  string // Path to the PEM-encoded private key associated with the certificate.
}

CertKey represents the certificate and key configuration for secure serving.

type CompletedConfig

type CompletedConfig struct {
	*Config
}

CompletedConfig represents a configuration that has been finalized and is ready for use.

func NewCompletedConfig

func NewCompletedConfig(c *Config) CompletedConfig

func (CompletedConfig) New

func (c CompletedConfig) New() (*APIServer, error)

New initializes and returns a new APIServer instance based on the completed configuration.

type Config

type Config struct {
	SecureServing   *SecureServingInfo
	InsecureServing *InsecureServingInfo
	Jwt             *JwtInfo
	Mode            string
	Middlewares     []string
	Healthz         bool
	EnableProfiling bool
	EnableMetrics   bool
	RateLimit       *RateLimitInfo
}

Config represents the main configuration structure for the API server.

func NewConfig

func NewConfig() *Config

NewConfig creates and returns a new Config instance with default settings.

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete finalizes the Config by setting any missing values and returns a CompletedConfig.

type DefaultConfig

type DefaultConfig struct {
	HomeDir    string
	EnvPrefix  string
	ConfigPath string
	JwtRealm   string
}

DefaultConfig contains default values for server configurations.

type InsecureServingInfo

type InsecureServingInfo struct {
	Address string
}

InsecureServingInfo contains the configuration for serving the API over HTTP.

type JwtInfo

type JwtInfo struct {
	Realm      string
	Key        string
	Timeout    time.Duration
	MaxRefresh time.Duration
}

JwtInfo defines configuration parameters for JWT-based authentication.

type RateLimitInfo

type RateLimitInfo struct {
	RequsetPerSecond float64 // Number of tokens generated per second.
	Burst            int     // Maximum burst size.
}

RateLimitConfig represents the configuration for rate limiting.

type SecureServingInfo

type SecureServingInfo struct {
	BindAddress string
	BindPort    int
	CertKey     CertKey
}

SecureServingInfo encapsulates the configuration for serving the API over HTTPS.

func (*SecureServingInfo) Address

func (s *SecureServingInfo) Address() string

Address constructs a complete address by combining BindAddress and BindPort.

Jump to

Keyboard shortcuts

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