package main import ( "flag" "fmt" "log" "math/rand" "net" "net/url" "os" "regexp" "strings" "time" "github.com/gomodule/redigo/redis" "github.com/hoisie/web" ) const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" // Base strings for RandStringBytesMaskImprSrc const ( letterIdxBits = 6 // 6 bits to represent a letter index letterIdxMask = 1<= 0; { if remain == 0 { cache, remain = src.Int63(), letterIdxMax } if idx := int(cache & letterIdxMask); idx < len(letterBytes) { b[i] = letterBytes[idx] i-- } cache >>= letterIdxBits remain-- } return string(b) } func main() { flag.StringVar(&domain, "domain", "localhost", "Domain to write to the URLs") flag.StringVar(&redisServer, "redis", "localhost:6379", "ip/hostname of the redis server to connect") flag.StringVar(&listenAddr, "addr", "localhost:8080", "Address to listen for connections") flag.StringVar(&path, "path", "", "Path to the base URL (https://localhost/PATH/... remember to append a / at the end") flag.StringVar(&proto, "proto", "https", "proto to the base URL (HTTPS://localhost/path/... no real https here just to set the url (for like a proxy offloading https") version := flag.Bool("v", false, "prints current version") flag.Parse() if *version { fmt.Printf("%s", appVersion) os.Exit(0) } if path != "" && !strings.HasSuffix(path, "/") { path = path + "/" } web.Post("/", shortner) web.Get("/(.*)", redirect) log.Printf("Domain: %s, Redis: %s\n", domain, redisServer) web.Run(listenAddr) }