pastebin/main.go

49 lines
918 B
Go
Raw Normal View History

2017-07-03 06:42:34 +00:00
package main
import (
"log"
2017-07-03 06:57:32 +00:00
"time"
2017-07-03 06:42:34 +00:00
"github.com/boltdb/bolt"
"github.com/namsral/flag"
)
var (
db *bolt.DB
cfg Config
)
func main() {
var (
config string
dbpath string
bind string
fqdn string
2017-07-03 06:57:32 +00:00
expiry time.Duration
2017-07-03 06:42:34 +00:00
)
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")
2017-07-03 06:57:32 +00:00
flag.DurationVar(&expiry, "expiry", 5*time.Minute, "expiry time for pastes")
2017-07-03 06:42:34 +00:00
flag.Parse()
2017-07-03 06:57:32 +00:00
if expiry.Seconds() < 60 {
log.Fatalf("expiry of %s is too small", expiry)
}
2017-07-03 06:42:34 +00:00
// TODO: Abstract the Config and Handlers better
cfg.fqdn = fqdn
cfg.expiry = expiry
var err error
db, err = bolt.Open(dbpath, 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()
NewServer(bind, cfg).ListenAndServe()
}