init (#1)
Reviewed-on: #1 Co-authored-by: Tobias Trabelsi <lerentis@uploadfilter24.eu> Co-committed-by: Tobias Trabelsi <lerentis@uploadfilter24.eu>
This commit is contained in:
34
internal/config.go
Normal file
34
internal/config.go
Normal file
@ -0,0 +1,34 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/configor"
|
||||
)
|
||||
|
||||
type Config = struct {
|
||||
LogLevel string `default:"Info" env:"METALLB_IP_FLOATER_LOGLEVEL"`
|
||||
LabelSelector string `default:"kops.k8s.io/instance-role=Node" env:"METALLB_IP_FLOATER_LABELSELECTOR"`
|
||||
Protocol string `default:"http" env:"METALLB_IP_FLOATER_PROTOCOL"`
|
||||
HcloudToken string `default:"" env:"METALLB_IP_FLOATER_HCLOUD_TOKEN"`
|
||||
FloatingIPName string `default:"" env:"METALLB_IP_FLOATER_FLOATING_IP_NAME"`
|
||||
DryRun bool `default:"false" env:"METALLB_IP_FLOATER_DRY_RUN"`
|
||||
}
|
||||
|
||||
func GenConfig() (cfg *Config, err error) {
|
||||
|
||||
cfg = &Config{}
|
||||
|
||||
err = configor.New(&configor.Config{
|
||||
ENVPrefix: "METALLB_IP_FLOATER",
|
||||
AutoReload: true,
|
||||
Silent: true,
|
||||
AutoReloadInterval: time.Minute}).Load(cfg, "config.json")
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Error generating Config: %s", err.Error()))
|
||||
}
|
||||
return cfg, nil
|
||||
|
||||
}
|
Reference in New Issue
Block a user