websub-hub/cmd/hubserver/main.go
Peter Stuifzand 07d94a789a
Some checks failed
continuous-integration/drone/push Build is failing
Add arguments for database
2019-03-18 22:06:55 +01:00

51 lines
1.1 KiB
Go

package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/http"
"time"
"p83.nl/go/websub-hub/cmd/hubserver/storage"
)
func init() {
log.SetFlags(log.Ltime | log.Lshortfile)
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func randStringBytes(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
type Stat struct {
Updates int
LastUpdate time.Time
}
func main() {
var hostPort,baseURL,database string
flag.StringVar(&hostPort, "http", ":80", "host and port to listen on")
flag.StringVar(&baseURL, "baseurl", "", "baseurl that the server should response with")
flag.StringVar(&database, "database", "localhost:9999", "database hostpost")
flag.Parse()
dsn := fmt.Sprintf("postgres://%v:%v@%s/hub?sslmode=disable", "postgres", "simple", database)
store, err := storage.New(dsn)
if err != nil {
log.Fatal(err)
}
defer store.Close()
handler := &subscriptionHandler{store, baseURL}
http.Handle("/", handler)
log.Fatal(http.ListenAndServe(hostPort, nil))
}