/* Package config provides types and methods for managing this application's config options and flags */ package config import ( "codeberg.org/vlbeaudoin/serpents" "github.com/spf13/pflag" "github.com/spf13/viper" ) type Config struct { API APIConfig Bottin BottinConfig DB DBConfig Web WebConfig } type APIConfig struct { Key string Port int } type BottinConfig struct { API struct { Host string Key string Port int Protocol string } } type DBConfig struct { Database string Host string Password string Port int User string UseSSL bool `mapstructure:"use_ssl"` } type WebConfig struct { API struct { Host string Key string Port int Protocol string } Password string Port int User string } func UnmarshalConfig() (cfg Config, err error) { return cfg, viper.Unmarshal(&cfg) } // RegisterFlags adds persistent flags necessary to the application to the specified *cobra.Command func RegisterFlags(flagSet *pflag.FlagSet) error { // api.port ; --api-port if err := serpents.Int(flagSet, "api.port", "api-port", 3182, "API server port"); err != nil { return err } // api.key ; --api-key if err := serpents.String(flagSet, "api.key", "api-key", "bottinag", "API server key"); err != nil { return err } // bottin.api.host if err := serpents.String(flagSet, "bottin.api.host", "bottin-api-host", "localhost", "Bottin API server host"); err != nil { return err } // bottin.api.key if err := serpents.String(flagSet, "bottin.api.key", "bottin-api-key", "bottin", "Bottin API server key"); err != nil { return err } // bottin.api.port if err := serpents.Int(flagSet, "bottin.api.port", "bottin-api-port", 1312, "Bottin API server port"); err != nil { return err } // bottin.api.protocol if err := serpents.String(flagSet, "bottin.api.protocol", "bottin-api-protocol", "http", "Bottin API server protocol"); err != nil { return err } // db.database if err := serpents.String(flagSet, "db.database", "db-database", "bottinag", "PostgreSQL database"); err != nil { return err } // db.host if err := serpents.String(flagSet, "db.host", "db-host", "db", "PostgreSQL host"); err != nil { return err } // db.password if err := serpents.String(flagSet, "db.password", "db-password", "bottinag", "PostgreSQL password"); err != nil { return err } // db.port if err := serpents.Int(flagSet, "db.port", "db-port", 5432, "PostgreSQL port"); err != nil { return err } // db.user if err := serpents.String(flagSet, "db.user", "db-user", "bottinag", "PostgreSQL user"); err != nil { return err } // db.use_ssl if err := serpents.Bool(flagSet, "db.use_ssl", "db-use-ssl", false, "PostgreSQL use_ssl"); err != nil { return err } // web.api.host if err := serpents.String(flagSet, "web.api.host", "web-api-host", "localhost", "Webserver API client host"); err != nil { return err } // web.api.key if err := serpents.String(flagSet, "web.api.key", "web-api-key", "bottinag", "Webserver API client key"); err != nil { return err } // web.api.port if err := serpents.Int(flagSet, "web.api.port", "web-api-port", 3182, "Webserver API client port"); err != nil { return err } // web.api.protocol if err := serpents.String(flagSet, "web.api.protocol", "web-api-protocol", "http", "Webserver API client protocol"); err != nil { return err } // web.password ; --web-password if err := serpents.String(flagSet, "web.password", "web-password", "bottinag", "Webserver basic auth password"); err != nil { return err } // web.port ; --web-port if err := serpents.Int(flagSet, "web.port", "web-port", 3183, "Webserver port"); err != nil { return err } // web.user ; --web-user if err := serpents.String(flagSet, "web.user", "web-user", "bottinag", "Webserver basic auth username"); err != nil { return err } return nil }