microservice

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseConfig

type BaseConfig struct {
	LogLevel           string `yaml:"log_level"`
	HTTPPort           string `yaml:"http_port"`
	ProjectID          string `yaml:"project_id"`
	CredentialsFile    string `yaml:"credentials_file"`
	ServiceName        string `yaml:"service_name"`
	DataflowName       string `yaml:"dataflow_name"`
	ServiceDirectorURL string `yaml:"service_director_url"`
}

BaseConfig holds common configuration fields for all services.

type BaseServer

type BaseServer struct {
	Logger   *slog.Logger
	HTTPPort string
	// contains filtered or unexported fields
}

BaseServer provides common functionalities for microservice servers, including lifecycle management, graceful shutdown, and standard observability endpoints.

func NewBaseServer

func NewBaseServer(logger *slog.Logger, httpPort string) *BaseServer

NewBaseServer creates and initializes a new BaseServer. It automatically registers the following reserved observability paths:

  • /healthz: Liveness probe
  • /readyz: Readiness probe
  • /metrics: Prometheus metrics (via VictoriaMetrics)

func (*BaseServer) GetHTTPPort

func (s *BaseServer) GetHTTPPort() string

GetHTTPPort returns the actual network port the server is listening on.

func (*BaseServer) Mux

func (s *BaseServer) Mux() *http.ServeMux

Mux returns the underlying ServeMux for registering additional handlers. Note: Do not register paths that collide with standard observability endpoints.

func (*BaseServer) SetReady

func (s *BaseServer) SetReady(ready bool)

SetReady allows the consuming service to signal that it is ready to serve traffic. This controls the status code of the /readyz endpoint.

func (*BaseServer) SetReadyChannel

func (s *BaseServer) SetReadyChannel(ch chan struct{})

SetReadyChannel allows the consuming service to provide a channel that will be closed when the HTTP server effectively starts listening on the TCP port.

func (*BaseServer) Shutdown

func (s *BaseServer) Shutdown(ctx context.Context) error

Shutdown gracefully stops the HTTP server.

func (*BaseServer) Start

func (s *BaseServer) Start() error

Start is a blocking call that starts the HTTP server. It returns only when the server is closed or fails to start.

type Service

type Service interface {
	Start(ctx context.Context) error
	Shutdown(ctx context.Context) error
	Mux() *http.ServeMux
	GetHTTPPort() string
}

Service defines the common interface for all microservices.

Jump to

Keyboard shortcuts

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