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() { hostPort := flag.String("http", ":80", "host and port to listen on") baseURL := flag.String("baseurl", "", "baseurl that the server should response with") database := flag.String("database", "localhost:9999", "database hostpost") flag.Parse() log.Printf("Using arguments http=%s baseurl=%s database=%s", *hostPort, *baseURL, *database) 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)) }