Jobs & Workflows https://armen.surge.sh
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
armen/internal/config/config.go

75 lines
1.7 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### config ####### Copyright (c) 2021 mls-361 ################################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package config
import (
"forge.chapril.org/mls-361/errors"
"forge.chapril.org/armen/armen/internal/components"
"forge.chapril.org/armen/armen/internal/config/data"
"forge.chapril.org/armen/armen/internal/config/yaml"
)
type config struct {
data *data.Data
}
func newConfig() *config {
return &config{
data: new(data.Data),
}
}
// Load AFAIRE.
func Load(ccs *components.Components) (components.Config, error) {
cc := newConfig()
config, ok := ccs.Application.LookupEnv("CONFIG")
if ok {
switch config {
case "yaml":
if err := yaml.LoadConfig(ccs.Application, cc.data); err != nil {
return nil, err
}
default:
return nil, errors.New( ////////////////////////////////////////////////////////////////////////////////////
"this configuration mode is not valid",
"mode", config,
)
}
}
if err := cc.data.Validate(); err != nil {
return nil, err
}
return cc, nil
}
// Data AFAIRE.
func (cc *config) Data() *data.Data {
return cc.data
}
// Logger AFAIRE.
func (cc *config) Logger() *data.Logger {
return cc.data.Logger
}
// Server AFAIRE.
func (cc *config) Server() *data.Server {
return cc.data.Server
}
// Storage AFAIRE.
func (cc *config) Storage() *data.Storage {
return cc.data.Storage
}
/*
######################################################################################################## @(°_°)@ #######
*/