func main() { flag.Parse() path := flag.Arg(0) config, _ = simpleconfig.NewConfig(path) host := config.GetStringDefault("redis.netaddress", "tcp:localhost:6379") db := config.GetIntDefault("redis.database", 0) passwd := config.GetStringDefault("redis.password", "") filenotfound = config.GetStringDefault("filenotfound", "https://www.youtube.com/watch?v=oHg5SJYRHA0") redis = godis.New(host, db, passwd) router := mux.NewRouter() router.HandleFunc("/shorten/{url:(.*$)}", shorten) router.HandleFunc("/{short:([a-zA-Z0-9]+$)}", resolve) router.HandleFunc("/{short:([a-zA-Z0-9]+)\\+$}", info) router.HandleFunc("/info/{short:[a-zA-Z0-9]+}", info) router.HandleFunc("/latest/{data:[0-9]+}", latest) router.HandleFunc("/{fileName:(.*$)}", static) listen := config.GetStringDefault("listen", "0.0.0.0") port := config.GetStringDefault("port", "9999") s := &http.Server{ Addr: listen + ":" + port, Handler: router, } s.ListenAndServe() }
func main() { err := godotenv.Load() if err != nil { log.Fatal("Error loading .env file") } flag.Parse() path := flag.Arg(0) var format = logging.MustStringFormatter("%{level} %{message}") logging.SetFormatter(format) config, _ = simpleconfig.NewConfig(path) var loglevel logging.Level switch os.Getenv("LOGLEVEL") { case "debug": loglevel = logging.DEBUG case "critical": loglevel = logging.CRITICAL case "error": loglevel = logging.ERROR case "info": loglevel = logging.INFO case "notice": loglevel = logging.NOTICE case "warning": loglevel = logging.WARNING } logging.SetLevel(loglevel, "info") log.Debug("Starting kurz") filenotfound = os.Getenv("FILE_NOT_FOUND_URL") // TODO: Restore this feature allowedHostNames = []string{} log.Debug("Will short URLs from following sites: %q", allowedHostNames) redis = redis_instance() router := mux.NewRouter() router.HandleFunc("/shorten/{url:(.*$)}", shorten) router.HandleFunc("/{short:([a-zA-Z0-9]+$)}", resolve) router.HandleFunc("/{short:([a-zA-Z0-9]+)\\+$}", info) router.HandleFunc("/info/{short:[a-zA-Z0-9]+}", info) router.HandleFunc("/latest/{data:[0-9]+}", latest) router.HandleFunc("/{fileName:(.*$)}", static) listen := os.Getenv("LISTEN_ADDRESS") port := os.Getenv("LISTEN_PORT") log.Info("Listening %s:%s", listen, port) s := &http.Server{ Addr: listen + ":" + port, Handler: router, } s.ListenAndServe() }