func LoadEnvConfiguration(filename string) *EnvConfiguration { conf := configure.New() glog.V(0).Infof("Loading configuration from 1. shell variables") conf.Use(configure.NewEnvironment()) if filename != "" { glog.V(0).Infof("Loading configuration from 2. json file: %s", filename) if file, err := os.Open(filename); err != nil { // TODO What if we wanted to pass all configuration via env variables, not possible as of today glog.Fatalf("Could not open Environment configuration file: %s", filename) } else { file.Close() conf.Use(configure.NewJSONFromFile(filename)) } } // environment specifics checkerPhoneNumber := conf.String("GOLAM_CHECKER_NUMBER", "", "the checker phone number to automate new messages check") checkerName := conf.String("GOLAM_CHECKER_NAME", "", "to enhance the welcome message of the new messages checker") recorderEndpoint := conf.String("GOLAM_RECORDER_ENDPOINT", "", "to receive the recordings") recorderUsername := conf.String("GOLAM_RECORDER_USERNAME", "", "credentials to the recorder endpoint") recorderPassword := conf.String("GOLAM_RECORDER_PASSWORD", "", "credentials to the recorder endpoint") audioEndpoint := conf.String("GOLAM_AUDIO_ENDPOINT", "", "audio files server") transcriptsEmail := conf.String("GOLAM_TRANSCRIPTS_EMAIL", "", "to receive transcripts via email") dbFilename := conf.String("GOLAM_DATABASE_PATH", "messages.db", "path to the messages database") dbResetAtStartup := conf.Bool("GOLAM_DATABASE_RESET", true, "flag to empty messages at startup") conf.Parse() var env EnvConfiguration env.RecorderEndpoint = *recorderEndpoint env.RecorderUsername = *recorderUsername env.RecorderPassword = *recorderPassword env.AudioServerEndpoint = *audioEndpoint env.TranscriptsReceiver = "mailto:" + *transcriptsEmail env.CheckerPhoneNumber = *checkerPhoneNumber env.CheckerFirstName = *checkerName env.DBfilename = *dbFilename env.DBresetAtStartup = *dbResetAtStartup return &env }
// Load default messages from file // The file is in json format and contains one or more of the entries: // - GOLAM_VOICE // - GOLAM_WELCOME // - GOLAM_WELCOME_ALT // - GOLAM_CHECK_NO_MESSAGE // - GOLAM_CHECK_NEW_MESSAGES // - GOLAM_RECORDING_OK // - GOLAM_RECORDING_FAILED // If an entry is not present, a default english message is added func LoadMessagesConfiguration(filename string) *I18nMessages { conf := configure.New() glog.V(0).Infof("Loading env preferences from 1. env variables") conf.Use(configure.NewEnvironment()) if filename != "" { glog.V(0).Infof("Loading messages from: %s", filename) if file, err := os.Open(filename); err != nil { glog.Warningf("Could not open Messages definition, switching to default values", filename) } else { file.Close() conf.Use(configure.NewJSONFromFile(filename)) } } // messages defaultVoice := conf.String("GOLAM_VOICE", "Vanessa", "defaults to English") welcome := conf.String("GOLAM_WELCOME", "Welcome, please leave a message after the beep", "to enhance the welcome message of the new messages checker") welcomeAlt := conf.String("GOLAM_WELCOME_ALT", "Sorry we do not take any message currently, please call again later", "alternative message if storage service could not be started") checkNoMessage := conf.String("GOLAM_CHECK_NO_MESSAGE", "Hello %s, no new messages. Have a good day !", "") checkNewMessage := conf.String("GOLAM_CHECK_NEW_MESSAGES", "Hello %s, you have %d new messages", "") recordingOK := conf.String("GOLAM_RECORDING_OK", "Your message is recorded. Have a great day !", "") recordingFailed := conf.String("GOLAM_RECORDING_FAILED", "Sorry, we could not record your message. Please try again later", "") conf.Parse() var messages I18nMessages messages.DefaultVoice = tropo.GetVoice(*defaultVoice) messages.WelcomeMessage = *welcome messages.WelcomeAltMessage = *welcomeAlt messages.CheckNewMessages = *checkNewMessage messages.CheckNoMessage = *checkNoMessage messages.RecordingOKMessage = *recordingOK messages.RecordingFailedMessage = *recordingFailed return &messages }
package main import ( "github.com/paked/configure" ) var ( config = configure.New() configBind = config.String("bind", ":5327", "Bind with IP address and port") configDomainName = config.String("domain-name", "serf.", "Domain name") configSerfRPCAddress = config.String("serf", "127.0.0.1:7373", "Serf RPC Address") configSerfRPCAuthKey = config.String("serf-auth", "", "Serf RPC auth key") configCustomDomainNameFile = config.String("custom", "", "Custom domain name file path") // SerfFilterTable is a global table of serf filters loaded at boot SerfFilterTable serfFilterTable ) func init() { config.Use(configure.NewEnvironment()) config.Use(configure.NewFlagWithUsage(usage)) } func usage() string { return `Usage: serf-dns [options] Options: -h This help --bind Bind to interface and port (default: 0.0.0.0:5327) --domain-name Specify domain name (default: serf.) --serf Serf RPC address (default: 127.0.0.1:7373) --serf-auth Serf RPC authentication key (default: empty)
package main import ( "fmt" "net/http" "github.com/dgrijalva/jwt-go" "github.com/gorilla/mux" _ "github.com/lib/pq" "github.com/paked/configure" "github.com/paked/pay/models" "github.com/paked/restrict" ) var ( conf = configure.New() dbName = conf.String("db-name", "postgres", "DB_NAME") dbUser = conf.String("db-user", "postgres", "DB_USER") dbPass = conf.String("db-pass", "postgres", "DB_PASS") dbService = conf.String("db-service", "jarvis", "DB_SERVICE") dbPort = conf.String("db-port", "5432", "DB_PORT") crypto = conf.String("crypto", "/crypto/app.rsa", "Your crypto") ) type Ping struct { ID int64 `db:"id"` Message string `db:"message"` }