config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config provides unified configuration loading helpers for service layer services. This package eliminates duplication across service entry points by providing: - Environment variable and secret loading with fallbacks - Hex address prefix trimming - CSV parsing - Byte size parsing - Port configuration - Chain configuration helpers

Index

Constants

This section is empty.

Variables

View Source
var ServiceNameMapping = map[string]string{
	"oracle":      "neooracle",
	"neofeeds":    "neofeeds",
	"neoaccounts": "neoaccounts",
	"neocompute":  "neocompute",
	"neoflow":     "neoflow",
	"vrf":         "neovrf",
	"tx-proxy":    "txproxy",
	"requests":    "neorequests",
}

ServiceNameMapping provides mapping from old service names to new Neo names

Functions

func ChainConfigValue

func ChainConfigValue(chainMeta map[string]string, envKey string, secretKey string, defaultValue string) string

ChainConfigValue gets a chain configuration value with fallback. Priority: chain meta config -> environment variable -> secret -> default

func EnvOrSecret

func EnvOrSecret(m *marble.Marble, envKey string, defaultValue string) string

EnvOrSecret retrieves a configuration value from environment or Marble secrets. Priority: 1. Marble secret (production/TEE mode) 2. Environment variable 3. Default value (if provided)

This is the preferred way to load configuration values in Marble services.

func EnvOrSecretBytes

func EnvOrSecretBytes(m *marble.Marble, envKey string) ([]byte, error)

EnvOrSecretBytes is like EnvOrSecret but returns raw bytes for binary values.

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv retrieves an environment variable with optional default. This is a simple wrapper for os.Getenv without Marble secret support. For services running in Marble, use EnvOrSecret instead.

func GetEnvBool

func GetEnvBool(key string, defaultValue bool) bool

GetEnvBool retrieves a boolean environment variable with optional default. Accepts: "true", "1", "yes", "y" (case-insensitive) as true.

func GetEnvInt

func GetEnvInt(key string, defaultValue int) int

GetEnvInt retrieves an integer environment variable with optional default. Returns 0 if the value is invalid.

func GetNeoServiceName

func GetNeoServiceName(oldName string) string

GetNeoServiceName converts old service name to new Neo name

func GetPort

func GetPort(serviceID string, defaultPort int) int

GetPort retrieves the service port from config or environment.

func ParseBoolOrDefault

func ParseBoolOrDefault(raw string, defaultValue bool) bool

ParseBoolOrDefault parses a boolean string or returns the default. Accepts: "true", "1", "yes", "y" (case-insensitive) as true.

func ParseByteSize

func ParseByteSize(raw string) (int64, error)

ParseByteSize parses a size string like "1GB", "512MB" into bytes. Supported suffixes: B, KB, MB, GB, TB (and their lowercase variants).

func ParseDurationOrDefault

func ParseDurationOrDefault(raw string, defaultDuration time.Duration) time.Duration

ParseDurationOrDefault parses a duration string or returns the default.

func ParseEnvDuration

func ParseEnvDuration(key string) (time.Duration, bool)

ParseEnvDuration parses a duration from the environment variable with the given key. Returns the parsed duration and true if successful, or 0 and false if not set or invalid.

func ParseEnvInt

func ParseEnvInt(key string) (int, bool)

ParseEnvInt parses an integer from the environment variable with the given key. Returns the parsed value and true if successful, or 0 and false if not set or invalid.

func ParseInt64OrDefault

func ParseInt64OrDefault(raw string, defaultValue int64) int64

ParseInt64OrDefault parses an int64 string or returns the default.

func ParseIntOrDefault

func ParseIntOrDefault(raw string, defaultValue int) int

ParseIntOrDefault parses an integer string or returns the default.

func ParseUint32OrDefault

func ParseUint32OrDefault(raw string, defaultValue uint32) uint32

ParseUint32OrDefault parses a uint32 string or returns the default.

func RequireEnvOrSecret

func RequireEnvOrSecret(m *marble.Marble, envKey string) string

RequireEnvOrSecret retrieves a required configuration value. Returns empty string and logs error if not found.

func SplitAndTrimCSV

func SplitAndTrimCSV(raw string) []string

SplitAndTrimCSV splits a CSV string and trims each part. Empty values are filtered out.

Types

type DefaultTimeouts

type DefaultTimeouts struct {
	HTTP     time.Duration
	RPC      time.Duration
	Database time.Duration
	TxProxy  time.Duration
	Service  time.Duration
}

DefaultTimeouts returns standard timeout values for different operations.

func GetDefaultTimeouts

func GetDefaultTimeouts() DefaultTimeouts

GetDefaultTimeouts returns default timeout values.

type ServiceSettings

type ServiceSettings struct {
	// Enabled determines if the service should run.
	Enabled bool `yaml:"enabled" json:"enabled"`

	// Port is the HTTP port for the service.
	Port int `yaml:"port" json:"port"`

	// Description is a human-readable description.
	Description string `yaml:"description" json:"description"`

	// Extra holds any additional service-specific configuration.
	Extra map[string]any `yaml:"extra,omitempty" json:"extra,omitempty"`
}

ServiceSettings holds configuration for a single service from services.yaml.

type ServicesConfig

type ServicesConfig struct {
	Services map[string]*ServiceSettings `yaml:"services" json:"services"`
}

ServicesConfig holds configuration for all services.

func DefaultServicesConfig

func DefaultServicesConfig() *ServicesConfig

DefaultServicesConfig returns the default services configuration

func LoadServicesConfig

func LoadServicesConfig() (*ServicesConfig, error)

LoadServicesConfig loads the services configuration from config/services.yaml

func LoadServicesConfigFromPath

func LoadServicesConfigFromPath(path string) (*ServicesConfig, error)

LoadServicesConfigFromPath loads the services configuration from a specific path

func LoadServicesConfigOrDefault

func LoadServicesConfigOrDefault() *ServicesConfig

LoadServicesConfigOrDefault loads services config or returns default if file not found

func (*ServicesConfig) DisabledServices

func (c *ServicesConfig) DisabledServices() []string

DisabledServices returns a list of disabled service IDs.

func (*ServicesConfig) EnabledServices

func (c *ServicesConfig) EnabledServices() []string

EnabledServices returns a list of enabled service IDs.

func (*ServicesConfig) GetSettings

func (c *ServicesConfig) GetSettings(serviceID string) *ServiceSettings

GetSettings returns the settings for a service. Returns nil if the service is not found.

func (*ServicesConfig) IsEnabled

func (c *ServicesConfig) IsEnabled(serviceID string) bool

IsEnabled checks if a service is enabled in the configuration. Returns false if the service is not found in config.

Jump to

Keyboard shortcuts

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