server

package
v0.18.4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 27

Documentation

Overview

Package server contains the HTTP, gRPC and CoAP server implementation.

Copyright (c) Abstract Machines SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const StopWaitTime = 5 * time.Second

Variables

This section is empty.

Functions

func LoadRootCACerts added in v0.18.0

func LoadRootCACerts(input string) (*x509.CertPool, error)

func LoadX509KeyPair added in v0.18.0

func LoadX509KeyPair(certFile, keyFile string) (tls.Certificate, error)

func ReadFileOrData added in v0.18.0

func ReadFileOrData(input string) ([]byte, error)

func StopSignalHandler

func StopSignalHandler(ctx context.Context, cancel context.CancelFunc, logger *slog.Logger, svcName string, servers ...Server) error

StopSignalHandler stops the server when a signal is received.

Types

type BaseServer

type BaseServer struct {
	Ctx      context.Context
	Cancel   context.CancelFunc
	Name     string
	Address  string
	Config   Config
	Logger   *slog.Logger
	Protocol string
}

func NewBaseServer

func NewBaseServer(ctx context.Context, cancel context.CancelFunc, name string, config Config, logger *slog.Logger) BaseServer

type Config

type Config struct {
	Host              string        `env:"HOST"                       envDefault:"localhost"`
	Port              string        `env:"PORT"                       envDefault:""`
	CertFile          string        `env:"SERVER_CERT"                envDefault:""`
	KeyFile           string        `env:"SERVER_KEY"                 envDefault:""`
	ServerCAFile      string        `env:"SERVER_CA_CERTS"            envDefault:""`
	ClientCAFile      string        `env:"CLIENT_CA_CERTS"            envDefault:""`
	ReadTimeout       time.Duration `env:"SERVER_READ_TIMEOUT"        envDefault:"15s"`
	WriteTimeout      time.Duration `env:"SERVER_WRITE_TIMEOUT"       envDefault:"15s"`
	ReadHeaderTimeout time.Duration `env:"SERVER_READ_HEADER_TIMEOUT" envDefault:"5s"`
	IdleTimeout       time.Duration `env:"SERVER_IDLE_TIMEOUT"        envDefault:"60s"`
	MaxHeaderBytes    int           `env:"SERVER_MAX_HEADER_BYTES"    envDefault:"1048576"` // 1 << 20
}

Config is a struct that contains the configuration for the server.

type Server

type Server interface {
	// Start starts the server.
	Start() error
	// Stop stops the server.
	Stop() error
}

Server is an interface that defines the methods to start and stop a server.

Directories

Path Synopsis
Package coap contains the CoAP server implementation.
Package coap contains the CoAP server implementation.
Package grpc contains the gRPC server implementation.
Package grpc contains the gRPC server implementation.
Package http contains the HTTP server implementation.
Package http contains the HTTP server implementation.

Jump to

Keyboard shortcuts

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