You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/http"
"time"
"p83.nl/go/websub-hub/cmd/hubserver/storage"
)
func init() {
log.SetFlags(log.Ldate | 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 host:port")
flag.Parse()
log.Printf("Using arguments http=%s baseurl=%s database=%s", *hostPort, *baseURL, *database)
dsn := fmt.Sprintf("postgres://%v:%v@%s/?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))
}