Documentation ¶
Overview ¶
Package service provides a service definition.
Index ¶
- Constants
- Variables
- type BuildInfo
- type Engine
- type Environment
- type IKernel
- type Kernel
- type Option
- func WithBodyLimit(value int) Option
- func WithBuildInfo(repository, commit, when string) Option
- func WithCertificateFile(value string) Option
- func WithCertificateKeyFile(value string) Option
- func WithConcurrency(value int) Option
- func WithDatabase(value *database.Options) Option
- func WithDescription(value string) Option
- func WithDisableStartupMessage(value bool) Option
- func WithDomain(value string) Option
- func WithEnablePrintRoutes(value bool) Option
- func WithEnableTrustedProxyCheck(value bool) Option
- func WithErrorHandler(value func(*fiber.Ctx, error) error) Option
- func WithIdleTimeout(value time.Duration) Option
- func WithKernel(value IKernel) Option
- func WithName(value string) Option
- func WithNetwork(value string) Option
- func WithPort(value int32) Option
- func WithReadBufferSize(value int) Option
- func WithReadTimeout(value time.Duration) Option
- func WithRuntime(value *Runtime) Option
- func WithShutdownTimeout(value time.Duration) Option
- func WithTrustedProxies(values []string) Option
- func WithViews(value fiber.Views) Option
- func WithWriteBufferSize(value int) Option
- func WithWriteTimeout(value time.Duration) Option
- type Options
- type Provider
- type ResourceRequirements
- type Runtime
- type RuntimeProbe
- type Service
Constants ¶
const ( InvalidCommit = "A commit must be a valid git commit hash." InvalidPlatform = "A platform must be a valid, supported platforms are: linux/amd64, linux/arm64." InvalidOS = "An operating system must be a valid, supported operating systems are: linux." InvalidArchitecture = "An architecture must be a valid, supported architectures are: amd64, arm64." )
const ( DefaultName = "service" DefaultPort = 3000 DefaultNetwork = "tcp4" DefaultBodyLimit = 4 * 1024 * 1024 DefaultConcurrency = 256 * 1024 DefaultReadTimeout = 5 * time.Second DefaultWriteTimeout = 5 * time.Second DefaultIdleTimeout = 65 * time.Second DefaultShutdownTimeout = 10 * time.Second DefaultReadBufferSize = 4 * 1024 DefaultWriteBufferSize = 4 * 1024 DefaultEnableTrustedProxyCheck = false DefaultCompressedFileSuffix = ".gz" DefaultConfigDirectory = "/etc/leliuga" DefaultConfigFile = "config.yaml" )
Default values for the HTTP server
const ( DefaultPathMonitoring = "/monitoring" DefaultPathDiscovery = "/discovery" )
Default paths for the service
const ( DefaultServiceNamespace = "leliuga" DefaultServiceAccountName = "leliuga" DefaultServiceReplicas = 1 DefaultServiceResourcesLimitCPU = "2000m" DefaultServiceResourcesLimitMemory = "1Gi" DefaultServiceResourcesLimitEphemeralStorage = "1Gi" DefaultServiceResourcesRequestCPU = "100m" DefaultServiceResourcesRequestMemory = "32Mi" DefaultServiceResourcesRequestEphemeralStorage = "100Mi" DefaultServiceProbeInitialDelaySeconds = 3 DefaultServiceProbeTimeoutSeconds = 1 DefaultServiceProbePeriodSeconds = 10 DefaultServiceProbeSuccessThreshold = 1 DefaultServiceProbeFailureThreshold = 3 )
Default values for the Service runtime
const ( // DefaultImageVendor is the default image vendor for the service container DefaultImageVendor = "ghcr.io/leliuga" // DefaultImagePrefix is the default image prefix for the service container DefaultImagePrefix = DefaultImageVendor + "/service" // DefaultBaseImage is the default base image for the service container DefaultBaseImage = DefaultImageVendor + "/base" // DefaultGolangImage is the default golang image for the service container DefaultGolangImage = DefaultImageVendor + "/golang" )
Default values for the image
const ( DefaultDomain = "leliuga.com" DefaultApplicationName = "Leliuga" DefaultVendor = `Leliuga` )
const (
InvalidNamespace = "A namespace must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character."
)
Variables ¶
var ( CommitRegex = regexp.MustCompile(`^[a-f0-9]{7,40}$`) PlatformRegex = regexp.MustCompile(`^(linux\/(amd64|arm64))$`) ArchitectureRegex = regexp.MustCompile(`^(amd64|arm64)$`) OSRegex = regexp.MustCompile(`^linux$`) )
var ( EngineNames = map[Engine]string{ EngineKubernetes: "Kubernetes", EngineDockerSwarm: "Docker Swarm", } )
var ( EnvironmentNames = map[Environment]string{ EnvironmentDevelopment: "development", EnvironmentStaging: "staging", EnvironmentProduction: "production", } )
var (
NamespaceRegex = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
)
var ( ProviderNames = map[Provider]string{ ProviderAws: "Amazon Web Service", ProviderAzure: "Azure", ProviderBareMetal: "Bare Metal", ProviderDo: "Digital Ocean", ProviderGcp: "Google Cloud Platform", } )
Functions ¶
This section is empty.
Types ¶
type BuildInfo ¶
type BuildInfo struct { Repository string `json:"repository"` Commit string `json:"commit"` When string `json:"when"` GoVersion string `json:"go_version"` Platform string `json:"platform"` OS string `json:"os"` Architecture string `json:"architecture"` }
BuildInfo defines the build information for a Service.
func NewBuildInfo ¶
NewBuildInfo creates a new BuildInfo.
type Engine ¶
type Engine uint8
Engine defines the engine for a Service runtime.
func (Engine) MarshalJSON ¶
MarshalJSON outputs the Engine as a json.
func (*Engine) UnmarshalJSON ¶
UnmarshalJSON parses the Engine from json.
type Environment ¶
type Environment uint8
Environment defines the environment in which the Service is running.
const ( EnvironmentInvalid Environment = iota // EnvironmentDevelopment EnvironmentStaging EnvironmentProduction )
func ParseEnvironment ¶
func ParseEnvironment(value string) Environment
ParseEnvironment parses the Environment from string.
func (Environment) MarshalJSON ¶
func (e Environment) MarshalJSON() ([]byte, error)
MarshalJSON outputs the Environment as a json.
func (Environment) String ¶
func (e Environment) String() string
String outputs the Environment as a string.
func (*Environment) UnmarshalJSON ¶
func (e *Environment) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the Environment from json.
func (Environment) Validate ¶
func (e Environment) Validate() bool
Validate returns true if the Environment is valid.
type IKernel ¶ added in v0.0.3
type IKernel interface { // Boot the kernel. Boot(*Service) error // Shutdown the kernel. Shutdown(context.Context) error // Set an instance to the kernel. Set(key string, instance any) // Get an instance from the kernel. Get(key string) any // Has an instance from the kernel. Has(key string) bool // Instances returns all instances from the kernel. Instances() types.Map[any] }
IKernel represents the service kernel interface.
type Kernel ¶ added in v0.0.3
type Kernel struct { IKernel // contains filtered or unexported fields }
Kernel represents the service kernel.
type Option ¶
type Option func(o *Options)
Option represents the service option.
func WithBodyLimit ¶
WithBodyLimit sets the body limit for the service.
func WithBuildInfo ¶
WithBuildInfo sets the build info for the service.
func WithCertificateFile ¶
WithCertificateFile sets the certificate file for the service.
func WithCertificateKeyFile ¶
WithCertificateKeyFile sets the certificate key file for the service.
func WithConcurrency ¶
WithConcurrency sets the concurrency for the service.
func WithDatabase ¶
WithDatabase sets the database for the service.
func WithDescription ¶ added in v0.0.9
WithDescription sets the description for the service.
func WithDisableStartupMessage ¶ added in v0.0.3
WithDisableStartupMessage sets the disable startup message for the service.
func WithEnablePrintRoutes ¶
WithEnablePrintRoutes sets the enable print routes for the service.
func WithEnableTrustedProxyCheck ¶
WithEnableTrustedProxyCheck sets the enable trusted proxy check for the service.
func WithErrorHandler ¶
WithErrorHandler sets the error handler for the service.
func WithIdleTimeout ¶
WithIdleTimeout sets the idle timeout for the service.
func WithKernel ¶ added in v0.0.3
WithKernel sets the kernel for the service.
func WithNetwork ¶
WithNetwork sets the network for the service.
func WithReadBufferSize ¶
WithReadBufferSize sets the read buffer size for the service.
func WithReadTimeout ¶
WithReadTimeout sets the read timeout for the service.
func WithRuntime ¶
WithRuntime sets the runtime for the service.
func WithShutdownTimeout ¶
WithShutdownTimeout sets the shutdown timeout for the service.
func WithTrustedProxies ¶
WithTrustedProxies sets the trusted proxies for the service.
func WithWriteBufferSize ¶
WithWriteBufferSize sets the write buffer size for the service.
func WithWriteTimeout ¶
WithWriteTimeout sets the write timeout for the service.
type Options ¶
type Options struct { Name string `json:"name"` Description string `json:"description"` Port int32 `json:"port" env:"PORT"` Network string `json:"network"` Domain string `json:"domain" env:"DOMAIN"` CertificateFile string `json:"certificate_file" env:"CERTIFICATE_FILE"` CertificateKeyFile string `json:"certificate_key_file" env:"CERTIFICATE_KEY_FILE"` Views fiber.Views `json:"-"` BodyLimit int `json:"body_limit" env:"BODY_LIMIT"` Concurrency int `json:"concurrency" env:"CONCURRENCY"` ReadTimeout time.Duration `json:"read_timeout" env:"READ_TIMEOUT"` WriteTimeout time.Duration `json:"write_timeout" env:"WRITE_TIMEOUT"` IdleTimeout time.Duration `json:"idle_timeout" env:"IDLE_TIMEOUT"` ShutdownTimeout time.Duration `json:"shutdown_timeout" env:"SHUTDOWN_TIMEOUT"` ReadBufferSize int `json:"read_buffer_size" env:"READ_BUFFER_SIZE"` WriteBufferSize int `json:"write_buffer_size" env:"WRITE_BUFFER_SIZE"` EnableTrustedProxyCheck bool `json:"enable_trusted_proxy_check" env:"ENABLE_TRUSTED_PROXY_CHECK"` TrustedProxies []string `json:"trusted_proxies" env:"TRUSTED_PROXIES"` DisableStartupMessage bool `json:"disable_startup_message" env:"DISABLE_STARTUP_MESSAGE"` EnablePrintRoutes bool `json:"enable_print_routes" env:"ENABLE_PRINT_ROUTES"` BuildInfo *BuildInfo `json:"build_info"` Runtime *Runtime `json:"runtime" env:"RUNTIME"` Database *database.Options `json:"database" env:"DATABASE"` ErrorHandler func(*fiber.Ctx, error) error `json:"-"` Kernel IKernel `json:"-"` }
Options represents the service options.
type Provider ¶
type Provider uint8
Provider defines the cloud provider for a Service runtime.
func ParseProvider ¶
ParseProvider parses the Provider from string.
func (Provider) MarshalJSON ¶
MarshalJSON outputs the Provider as a json.
func (*Provider) UnmarshalJSON ¶
UnmarshalJSON parses the Provider from json.
type ResourceRequirements ¶
type ResourceRequirements struct { Limits corev1.ResourceList `json:"limits" env:"LIMITS"` Requests corev1.ResourceList `json:"requests" env:"REQUESTS"` }
ResourceRequirements defines the resource requirements for a Service.
type Runtime ¶
type Runtime struct { Provider Provider `json:"provider" env:"PROVIDER"` Region string `json:"region" env:"REGION"` Zone string `json:"zone" env:"ZONE"` Namespace string `json:"namespace" env:"NAMESPACE"` ServiceAccountName string `json:"service_account_name" env:"SERVICE_ACCOUNT_NAME"` Engine Engine `json:"engine" env:"ENGINE"` Replicas int32 `json:"replicas" env:"REPLICAS"` Resources *ResourceRequirements `json:"resources" env:"RESOURCES"` Probe *RuntimeProbe `json:"probe" env:"PROBE"` }
Runtime defines the runtime for a Service.
func (*Runtime) ToResourceRequirements ¶
func (r *Runtime) ToResourceRequirements() corev1.ResourceRequirements
ToResourceRequirements converts the Runtime to a ResourceRequirements.
func (*Runtime) Validate ¶
Validate makes Runtime validatable by implementing validation.Validatable interface.
type RuntimeProbe ¶
type RuntimeProbe struct { InitialDelaySeconds int32 `json:"initial_delay_seconds" env:"INITIAL_DELAY_SECONDS"` TimeoutSeconds int32 `json:"timeout_seconds" env:"TIMEOUT_SECONDS"` PeriodSeconds int32 `json:"period_seconds" env:"PERIOD_SECONDS"` SuccessThreshold int32 `json:"success_threshold" env:"SUCCESS_THRESHOLD"` FailureThreshold int32 `json:"failure_threshold" env:"FAILURE_THRESHOLD"` }
RuntimeProbe defines the runtime probe for a Service.