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
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Config ...
|
// Config ...
|
||||||
type Config struct {
|
type Config struct {
|
||||||
expiry int
|
expiry time.Duration
|
||||||
fqdn string
|
fqdn string
|
||||||
}
|
}
|
||||||
|
9
main.go
9
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
"github.com/namsral/flag"
|
"github.com/namsral/flag"
|
||||||
@ -18,16 +19,20 @@ func main() {
|
|||||||
dbpath string
|
dbpath string
|
||||||
bind string
|
bind string
|
||||||
fqdn string
|
fqdn string
|
||||||
expiry int
|
expiry time.Duration
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.StringVar(&config, "config", "", "config file")
|
flag.StringVar(&config, "config", "", "config file")
|
||||||
flag.StringVar(&dbpath, "dbpth", "urls.db", "Database path")
|
flag.StringVar(&dbpath, "dbpth", "urls.db", "Database path")
|
||||||
flag.StringVar(&bind, "bind", "0.0.0.0:8000", "[int]:<port> to bind to")
|
flag.StringVar(&bind, "bind", "0.0.0.0:8000", "[int]:<port> to bind to")
|
||||||
flag.StringVar(&fqdn, "fqdn", "localhost", "FQDN for public access")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
if expiry.Seconds() < 60 {
|
||||||
|
log.Fatalf("expiry of %s is too small", expiry)
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Abstract the Config and Handlers better
|
// TODO: Abstract the Config and Handlers better
|
||||||
cfg.fqdn = fqdn
|
cfg.fqdn = fqdn
|
||||||
cfg.expiry = expiry
|
cfg.expiry = expiry
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/GeertJohan/go.rice"
|
"github.com/GeertJohan/go.rice"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
@ -94,7 +93,7 @@ func NewServer(bind string, config Config) *Server {
|
|||||||
bind: bind,
|
bind: bind,
|
||||||
config: config,
|
config: config,
|
||||||
router: httprouter.New(),
|
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")),
|
templates: templice.New(rice.MustFindBox("templates")),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user