diff options
author | Andinus <andinus@nand.sh> | 2020-03-27 21:20:12 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-03-27 21:20:12 +0530 |
commit | 3dee7955670274b92ad8b3931e6c36995f1ee418 (patch) | |
tree | c312153b27a2e6e32e900112978696c7aae312b8 /cmd | |
parent | 97f36a08c7a5e3bd7921a26af89eee8ad9b3e3d7 (diff) | |
download | perseus-3dee7955670274b92ad8b3931e6c36995f1ee418.tar.gz |
Add registration handler
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/perseus/main.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/perseus/main.go b/cmd/perseus/main.go index 1533a3c..b94793e 100644 --- a/cmd/perseus/main.go +++ b/cmd/perseus/main.go @@ -1,10 +1,36 @@ package main import ( + "fmt" + "log" + "net/http" + "os" + "time" + + "tildegit.org/andinus/perseus/handler/web" "tildegit.org/andinus/perseus/storage" ) func main() { db := storage.Init() defer db.Conn.Close() + + envPort, exists := os.LookupEnv("PERSEUS_PORT") + if !exists { + envPort = "8080" + } + addr := fmt.Sprintf("127.0.0.1:%s", envPort) + + srv := &http.Server{ + Addr: addr, + WriteTimeout: 8 * time.Second, + ReadTimeout: 8 * time.Second, + } + + http.HandleFunc("/register", func(w http.ResponseWriter, r *http.Request) { + web.HandleRegister(w, r, db) + }) + + log.Printf("main/main.go: listening on port %s...", envPort) + log.Fatal(srv.ListenAndServe()) } |