Documentation
¶
Overview ¶
Package libParams provides application parameter configuration management.
Index ¶
- func EncryptParams[T any](keyByte, ivByte []byte, paramFile string, params *ApplicationParams[T]) error
- func GetValueFromMap[T any](name string, mp map[string]T) *T
- func LogRotate(logger *lumberjack.Logger)
- func Write[T any](params *ApplicationParams[T], path string) error
- type ApplicationParams
- func (m ApplicationParams[SpecialParams]) GetConstants(name string) *Constants
- func (m ApplicationParams[SpecialParams]) GetDB(name string) *DbParams
- func (m ApplicationParams[SpecialParams]) GetLogging() LogParams
- func (m ApplicationParams[SpecialParams]) GetNetwork(name string) *NetworkParams
- func (m ApplicationParams[SpecialParams]) GetParam(group, name string) *string
- func (m ApplicationParams[SpecialParams]) GetRemoteAPI(name string) *libCallApi.RemoteAPI
- func (m ApplicationParams[SpecialParams]) GetSecureParam(group, name string) *SecurityParam
- func (m ApplicationParams[SpecialParams]) GetSecurityModule(name string) *SecurityModule
- func (m ApplicationParams[SpecialParams]) GetSpecificParams(_ string) any
- func (m ApplicationParams[SpecialParams]) SetDB(name string, db *DbParams)
- type Constants
- type DbParams
- type LogParams
- type NetworkParams
- type ParamInterface
- type ParametersMap
- type SecureParametersMap
- type SecurityModule
- type SecurityParam
- type SplunkParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncryptParams ¶ added in v0.16.1
func EncryptParams[T any](keyByte, ivByte []byte, paramFile string, params *ApplicationParams[T]) error
EncryptParams encrypts all plain secure parameters and DB addresses, writing the result to paramFile.
func GetValueFromMap ¶ added in v0.16.0
GetValueFromMap returns a pointer to the value associated with name in mp, or nil if not found.
func LogRotate ¶ added in v0.9.29
func LogRotate(logger *lumberjack.Logger)
LogRotate starts a background goroutine that rotates the lumberjack logger hourly.
Types ¶
type ApplicationParams ¶ added in v0.16.0
type ApplicationParams[SpecialParams any] struct { Network map[string]NetworkParams `yaml:"networks"` // Definition of all networks, all networks will be started at startup Logging LogParams `yaml:"logging"` DB map[string]DbParams `yaml:"db"` // Database connection strings SecurityModule map[string]SecurityModule `yaml:"securityModule"` // Security modules if exists RemoteAPIs map[string]libCallApi.RemoteAPI `yaml:"remoteApis"` // List of remote-api definition Constants map[string]Constants `yaml:"constants"` // Constants used in app [response constants should be placed here] ParameterGroups map[string]ParametersMap `yaml:"parameterGroups"` // Simple string parameters groupped by names SecureParameterGroups map[string]SecureParametersMap `yaml:"secureParameterGroups"` // Encrypted string parameters, will be parsed at startup Specific *SpecialParams `yaml:"specific"` // Application specific args, should be parsed as yaml Metrics *ginprom.Prometheus `json:"-"` // Applications metrics storage }
ApplicationParams holds the default application parameters.
func DecryptParams ¶ added in v0.16.1
func DecryptParams[T any](keyByte, ivByte []byte, params *ApplicationParams[T]) (*ApplicationParams[T], error)
DecryptParams decrypts all secure parameters and populates remote API and security module fields.
func Load ¶ added in v0.16.1
func Load[T any](path string) (*ApplicationParams[T], error)
Load reads and unmarshals the application parameters from the YAML file at path.
func ParsePrams ¶ added in v0.16.2
func ParsePrams[T any](paramFile string, keys [][]byte) (*ApplicationParams[T], error)
ParsePrams loads and decrypts application parameters from paramFile using the provided keys.
func (ApplicationParams[SpecialParams]) GetConstants ¶ added in v0.16.0
func (m ApplicationParams[SpecialParams]) GetConstants(name string) *Constants
GetConstants returns the constants block with the given name.
func (ApplicationParams[SpecialParams]) GetDB ¶ added in v0.16.0
func (m ApplicationParams[SpecialParams]) GetDB(name string) *DbParams
GetDB returns the database parameters for the given name.
func (ApplicationParams[SpecialParams]) GetLogging ¶ added in v0.16.0
func (m ApplicationParams[SpecialParams]) GetLogging() LogParams
GetLogging returns the logging parameters for the application.
func (ApplicationParams[SpecialParams]) GetNetwork ¶ added in v0.16.0
func (m ApplicationParams[SpecialParams]) GetNetwork(name string) *NetworkParams
GetNetwork returns the network parameters for the given name.
func (ApplicationParams[SpecialParams]) GetParam ¶ added in v0.16.1
func (m ApplicationParams[SpecialParams]) GetParam(group, name string) *string
GetParam returns the string parameter value for the given group and name.
func (ApplicationParams[SpecialParams]) GetRemoteAPI ¶ added in v0.28.1
func (m ApplicationParams[SpecialParams]) GetRemoteAPI(name string) *libCallApi.RemoteAPI
GetRemoteAPI returns the remote API definition with the given name.
func (ApplicationParams[SpecialParams]) GetSecureParam ¶ added in v0.16.1
func (m ApplicationParams[SpecialParams]) GetSecureParam(group, name string) *SecurityParam
GetSecureParam returns the security parameter for the given group and name.
func (ApplicationParams[SpecialParams]) GetSecurityModule ¶ added in v0.16.0
func (m ApplicationParams[SpecialParams]) GetSecurityModule(name string) *SecurityModule
GetSecurityModule returns the security module with the given name.
func (ApplicationParams[SpecialParams]) GetSpecificParams ¶ added in v0.16.0
func (m ApplicationParams[SpecialParams]) GetSpecificParams(_ string) any
GetSpecificParams returns the application-specific parameters.
func (ApplicationParams[SpecialParams]) SetDB ¶ added in v0.16.2
func (m ApplicationParams[SpecialParams]) SetDB(name string, db *DbParams)
SetDB sets the database parameters for the given name.
type Constants ¶ added in v0.16.0
type Constants struct {
ErrorDesc map[string]string `yaml:"errorDesc"`
MessageDesc map[string]string `yaml:"messageDesc"`
}
Constants holds error and message description maps used for response formatting.
type DbParams ¶ added in v0.16.0
type DbParams struct {
DataBaseType string `yaml:"dbType"`
DataBaseAddress SecurityParam `yaml:"dbAddress"`
Db *sql.DB `yaml:"-"`
Orm *gorm.DB `yaml:"-"`
}
DbParams holds database connection configuration and runtime DB/ORM handles.
type LogParams ¶ added in v0.16.0
type LogParams struct {
LogPath string `yaml:"logPath"`
LogSize int `yaml:"logSize"`
LogCompress bool `yaml:"logCompress"`
SkipPaths []string `yaml:"skipPaths"`
LogHeader string `yaml:"logHeader"`
UseSlog bool `yaml:"useSlog"`
Splunk *SplunkParams `yaml:"splunkParams"`
}
LogParams holds logging-related configuration parameters.
func (LogParams) GetHeaderName ¶ added in v0.16.2
GetHeaderName returns the configured log header name.
func (LogParams) GetLogCompress ¶ added in v0.16.2
GetLogCompress returns whether log compression is enabled.
func (LogParams) GetLogPath ¶ added in v0.16.2
GetLogPath returns the configured log file path.
func (LogParams) GetLogSize ¶ added in v0.16.2
GetLogSize returns the configured maximum log file size.
func (LogParams) GetSkipPaths ¶ added in v0.16.2
GetSkipPaths returns the list of request paths excluded from logging.
type NetworkParams ¶ added in v0.16.0
type NetworkParams struct {
Port string `yaml:"port"`
StaticPort string `yaml:"staticPort"`
StaticPath string `yaml:"staticPath"`
///////////////////// TLS ////////////////////////////////////////////
TLSPort string `yaml:"tlsPort"`
TLSKey string `yaml:"tlsKey"`
TLSCert string `yaml:"tlsCert"`
}
NetworkParams holds network-related configuration parameters.
type ParamInterface ¶ added in v0.9.1
type ParamInterface interface {
GetNetwork(name string) *NetworkParams
GetLogging() LogParams
GetDB(name string) *DbParams
SetDB(name string, db *DbParams)
GetSecurityModule(name string) *SecurityModule
GetRemoteAPI(name string) *libCallApi.RemoteAPI
GetParam(group, name string) *string
GetSecureParam(group, name string) *SecurityParam
GetConstants(name string) *Constants
GetSpecificParams(name string) any
}
ParamInterface defines the accessor methods for application parameters.
type ParametersMap ¶ added in v0.16.0
ParametersMap holds a group of simple string parameters keyed by name.
type SecureParametersMap ¶ added in v0.16.0
type SecureParametersMap struct {
SecureParams map[string]SecurityParam `yaml:"secureParams"`
}
SecureParametersMap holds a group of encrypted security parameters keyed by name.
type SecurityModule ¶ added in v0.16.0
type SecurityModule struct {
Type string `yaml:"type"`
Params map[string]string `yaml:"params"`
libCrypto.Sm
}
SecurityModule defines a security module with its type, parameters, and crypto implementation.
type SecurityParam ¶ added in v0.16.0
SecurityParam represents a single parameter that may be stored in plain or encrypted form.
func Decrypt ¶ added in v0.16.1
func Decrypt(key, iv, name string, field SecurityParam) (*SecurityParam, error)
Decrypt decrypts the given field using the provided key and IV, returning the plain value.
func FillCipher ¶ added in v0.16.1
func FillCipher(key, iv string, field SecurityParam) (*SecurityParam, error)
FillCipher encrypts the given field if it is plain, using the provided key and IV.
type SplunkParams ¶ added in v0.16.0
type SplunkParams struct {
URL string `yaml:"url"` // Splunk HEC endpoint (e.g., "https://<splunk-server>:8088/services/collector/event")
Token string `yaml:"token"` // HEC token
SourceType string `yaml:"source"` // Splunk source type
Source string `yaml:"sourceType"` // Splunk source
Index string `yaml:"index"` // Splunk index
RawHandler bool `yaml:"rawHandler"`
SkipTLSVerify bool `yaml:"skipTlsVerify"` // when true, skips TLS certificate verification (use only for internal collectors with self-signed certs)
}
SplunkParams holds configuration for the Splunk logger.