diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..357d366 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pastebin diff --git a/config.go b/config.go index 2cb4796..c949bfb 100644 --- a/config.go +++ b/config.go @@ -1,7 +1,11 @@ package main +import ( + "time" +) + // Config ... type Config struct { - expiry int + expiry time.Duration fqdn string } diff --git a/main.go b/main.go index bc2a6a5..6e46eee 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "time" "github.com/boltdb/bolt" "github.com/namsral/flag" @@ -18,16 +19,20 @@ func main() { dbpath string bind string fqdn string - expiry int + expiry time.Duration ) flag.StringVar(&config, "config", "", "config file") flag.StringVar(&dbpath, "dbpth", "urls.db", "Database path") flag.StringVar(&bind, "bind", "0.0.0.0:8000", "[int]: to bind to") flag.StringVar(&fqdn, "fqdn", "localhost", "FQDN for public access") - flag.IntVar(&expiry, "expiery", 5, "expiry time (mins) for passte") + flag.DurationVar(&expiry, "expiry", 5*time.Minute, "expiry time for pastes") flag.Parse() + if expiry.Seconds() < 60 { + log.Fatalf("expiry of %s is too small", expiry) + } + // TODO: Abstract the Config and Handlers better cfg.fqdn = fqdn cfg.expiry = expiry diff --git a/server.go b/server.go index e9414ba..cc5b522 100644 --- a/server.go +++ b/server.go @@ -5,7 +5,6 @@ import ( "log" "net/http" "net/url" - "time" "github.com/GeertJohan/go.rice" "github.com/julienschmidt/httprouter" @@ -94,7 +93,7 @@ func NewServer(bind string, config Config) *Server { bind: bind, config: config, router: httprouter.New(), - store: cache.New(5*time.Minute, 10*time.Minute), + store: cache.New(cfg.expiry, cfg.expiry*2), templates: templice.New(rice.MustFindBox("templates")), }