func initFlags(c *config) { pflag.StringSliceVar(&c.etcdServers, "etcd-servers", []string{}, "The comma-seprated list of etcd servers to use") pflag.StringVar(&c.key, "key", "", "The key to use for the lock") pflag.StringVar(&c.whoami, "whoami", "", "The name to use for the reservation. If empty use os.Hostname") pflag.Uint64Var(&c.ttl, "ttl-secs", 30, "The time to live for the lock.") pflag.StringVar(&c.src, "source-file", "", "The source file to copy from.") pflag.StringVar(&c.dest, "dest-file", "", "The destination file to copy to.") pflag.DurationVar(&c.sleep, "sleep", 5*time.Second, "The length of time to sleep between checking the lock.") }
func initFlags(c *config) { pflag.StringSliceVar(&c.etcdServers, "etcd-servers", []string{}, "The comma-seprated list of etcd servers to use") pflag.BoolVar(&c.etcdSecure, "etcd-secure", false, "Set to true if etcd has https") pflag.StringVar(&c.etcdCertfile, "etcd-certfile", "", "Etcd TLS cert file, needed if etcd-secure") pflag.StringVar(&c.etcdKeyfile, "etcd-keyfile", "", "Etcd TLS key file, needed if etcd-secure") pflag.StringVar(&c.etcdCafile, "etcd-cafile", "", "Etcd CA file, needed if etcd-secure") pflag.StringVar(&c.key, "key", "", "The key to use for the lock") pflag.StringVar(&c.whoami, "whoami", "", "The name to use for the reservation. If empty use os.Hostname") pflag.Uint64Var(&c.ttl, "ttl-secs", 30, "The time to live for the lock.") pflag.StringVar(&c.src, "source-file", "", "The source file to copy from.") pflag.StringVar(&c.dest, "dest-file", "", "The destination file to copy to.") pflag.DurationVar(&c.sleep, "sleep", 5*time.Second, "The length of time to sleep between checking the lock.") }
func main() { pflag.BoolVar(&sentinelMode, "sentinel-mode", false, "Whether using Sentinel") pflag.StringVar(&redisAddress, "redis-addr", ":6379", "Redis address, can be ignored while setting sentinel mode") pflag.StringVar(&conf.MasterName, "master-name", "mymaster", "Redis Sentinel master name") pflag.StringSliceVar(&conf.Addresses, "sentinel-ips", []string{"172.31.33.2:26379", "172.31.33.3:26379", "172.31.75.4:26379"}, "Sentinel failover addresses") pflag.Parse() if sentinelMode { fmt.Println("block to wait connection") var err error //go func() {store, err = connectSentinel()}() store, err = connectSentinel() if err != nil { fmt.Println("Failed to create connection! Please contact SysOps") return } } else { //store = sessions.NewCookieStore([]byte("something-very-secret")) //store = sessions.NewFilesystemStore("", []byte("something-very-secret")) //store, err := redistore.NewRediStore(10, "tcp", ".6379", "", []byte("secret-key")) redistore, err := redistore.NewRediStore(10, "tcp", redisAddress, "", []byte("authentication-secret-key")) if err != nil { fmt.Println("Failed to ping Redis! Please contact SysOps") return } store = redistore } gob.Register(&Person{}) port := os.Getenv("PORT") if port == "" { port = "80" } router := mux.NewRouter() router.HandleFunc("/signup/{signup}", makeHandler(signupHandler)).Methods("GET", "POST") router.HandleFunc("/signin/{signin}", makeHandler(signinHandler)).Methods("GET", "POST") router.HandleFunc("/profile/{profile}", makeHandler(profileHandler)).Methods("GET", "POST") router.HandleFunc("/signout/{signout}", makeHandler(signoutHandler)).Methods("GET", "POST") //router.HandleFunc("/index.html", makeHandler(indexHandler)).Methods("GET") // substituted by following statement router.HandleFunc("/{others}", func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) others := vars["others"] if m := indexRegex.FindStringSubmatch(strings.ToLower(others)); m != nil { indexHandler(w, r, others[:len("index")]) return } http.NotFound(w, r) }).Methods("GET") router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { http.Redirect(w, r, "/index.html", http.StatusFound) } }).Methods("GET") http.Handle("/", router) loadTemplates() fmt.Printf("Listening on port %s\n", port) log.Fatal(http.ListenAndServe(":"+port, nil)) }