server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package server provides configuration management for the dehydrated-api-go server. It handles loading and validating server configuration from YAML files, including server settings, plugin configurations, and logging options.

Package server provides the HTTP server implementation for the dehydrated-api-go application. It handles server lifecycle management, configuration loading, and graceful shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Server configuration
	Port int `yaml:"port"` // Port number for the HTTP server (1-65535)

	// Dehydrated configuration
	DehydratedBaseDir string `yaml:"dehydratedBaseDir"` // Base directory for dehydrated client files

	// DehydratedConfigFile specifies the path to the dehydrated configuration file.
	// This file is typically located under the base directory and contains
	// dehydrated client-specific settings.
	DehydratedConfigFile string `yaml:"dehydratedConfigFile"`

	// EnableWatcher determines whether the file watcher is active.
	// When enabled, the server monitors for changes in the dehydrated configuration.
	EnableWatcher bool `yaml:"enableWatcher"`

	// Logging configuration
	Logging *logger.Config `yaml:"logging"` // Configuration for the application logger

	// Authentication configuration
	Auth *auth.Config `yaml:"auth"` // Azure AD authentication configuration

	Plugins map[string]config.PluginConfig `yaml:"plugins"`
	// contains filtered or unexported fields
}

Config holds the application configuration for the dehydrated-api-go server. It includes settings for the HTTP server, plugin management, dehydrated client, and logging configuration.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config instance with default values. The default configuration includes: - Port: 3000 - DehydratedBaseDir: "." - DehydratedConfigFile: "config" - EnableWatcher: false - Logging: default logger configuration

func (*Config) DomainsFile

func (c *Config) DomainsFile() string

DomainsFile returns the absolute path to the domains.txt file. This file contains the list of domains managed by the dehydrated client.

func (*Config) Load

func (c *Config) Load(path string) *Config

Load loads configuration from a YAML file and merges it with defaults. If the file doesn't exist or has invalid content, the default configuration is returned. The method merges non-zero values from the file with the existing configuration.

func (*Config) String

func (c *Config) String() string

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid and returns an error if any issues are found. It validates: - Port number (must be between 1 and 65535) - Dehydrated base directory (must exist) - Plugin configurations (paths must exist and be absolute)

func (*Config) WithBaseDir

func (c *Config) WithBaseDir(dir string) *Config

WithBaseDir sets the dehydrated base directory in the configuration. This method returns the config instance for method chaining.

type Server

type Server struct {
	Version   string
	Commit    string
	BuildTime string

	Config *Config
	Logger *zap.Logger
	// contains filtered or unexported fields
}

Server represents a running server instance that manages the HTTP server lifecycle. It handles server startup, shutdown, and maintains the application state.

func NewServer

func NewServer() *Server

NewServer creates a new server instance.

func (*Server) GetPort

func (s *Server) GetPort() int

GetPort returns the port number that the server is listening on.

func (*Server) PrintDehydratedConfig

func (s *Server) PrintDehydratedConfig()

func (*Server) PrintInfo

func (s *Server) PrintInfo(v, i bool)

func (*Server) PrintServerConfig

func (s *Server) PrintServerConfig()

func (*Server) PrintVersion

func (s *Server) PrintVersion()

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown gracefully shuts down the server and its associated resources.

func (*Server) Start

func (s *Server) Start()

Start starts the server and begins listening for requests.

func (*Server) WithConfig

func (s *Server) WithConfig(path string) *Server

func (*Server) WithDomainService

func (s *Server) WithDomainService() *Server

func (*Server) WithLogger

func (s *Server) WithLogger() *Server

func (*Server) WithVersionInfo

func (s *Server) WithVersionInfo(v, c, b string) *Server

Jump to

Keyboard shortcuts

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