func main() { var showVersion, nameFromForm bool var port, name, upload, download, dir, fileID string flag.StringVar(&port, "port", "8081", "ip port of the server, defaults to 8081") flag.StringVar(&name, "name", "Recorder", "name of the service, defaults to Recorder") flag.StringVar(&upload, "upload", "upload", "route to store files, defaults to /upload") flag.StringVar(&download, "download", "download", "route to serve files, defaults to /downlaod") flag.StringVar(&dir, "directory", ".", "directory to store and serve files, defaults to .") flag.StringVar(&fileID, "formID", ".", "identifier of the file to updload, mandatory in current version") flag.BoolVar(&nameFromForm, "nameFromForm", false, "if set to true, names uploaded file with filename found in form, by default, the filename is extracted from URI") flag.BoolVar(&showVersion, "version", false, "display version") flag.Parse() if showVersion { glog.Infof("%s version %s\n", name, version) return } if _, err := strconv.Atoi(port); err != nil { glog.Errorf("Invalid port: %s (%s)\n", port, err) return } service := &recorder.Recorder{ UploadRoute: "/" + upload + "/", UploadDirectory: dir, FormIdentifier: fileID, // as specified in tropo documentation NameFileFromForm: nameFromForm, DownloadRoute: "/" + download + "/", DownloadDirectory: dir, } glog.V(1).Infof("Recorder configuration %s", service) glog.Infof("Starting %s, version: %s\n", name, version) if err := server.Run(port, service, version, name); err != nil { glog.Errorf("Service exited with error: %s\n", err) glog.Flush() os.Exit(255) return } glog.Info("Service exited gracefully\n") glog.Flush() }
func main() { // Read arguments (prevail) var showVersion bool var port, name, envPref, messagesPref string flag.StringVar(&port, "port", "8080", "ip port of the server, defaults to 8080") flag.StringVar(&name, "name", "AnsweringMachine", "name of the service, defaults to AnsweringMachine") flag.StringVar(&envPref, "env", "env.json", "environment configuration file") flag.StringVar(&messagesPref, "messages", "messages-en.json", "defaults messages, defaults to messages-en.json") flag.BoolVar(&showVersion, "version", false, "display version") flag.Parse() if showVersion { glog.Infof("%s version %s\n", name, version) return } if _, err := strconv.Atoi(port); err != nil { glog.Errorf("Invalid port: %s (%s)\n", port, err) } // Read configuration (env variables then properties, then default values) env := machine.LoadEnvConfiguration(envPref) messages := machine.LoadMessagesConfiguration(messagesPref) service := machine.NewAnsweringMachine(env, messages) glog.Infof("Starting %s, version: %s\n", name, version) if err := server.Run(port, service, version, name); err != nil { glog.Errorf("Service exited with error: %s\n", err) glog.Flush() os.Exit(255) return } glog.Info("Service exited gracefully\n") glog.Flush() }