Repsect -expiry configuration
This commit is contained in:
parent
3c42d7d878
commit
43a32970d3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
pastebin
|
@ -1,7 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Config ...
|
||||
type Config struct {
|
||||
expiry int
|
||||
expiry time.Duration
|
||||
fqdn string
|
||||
}
|
||||
|
9
main.go
9
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]:<port> 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
|
||||
|
@ -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")),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user