From 3dee7955670274b92ad8b3931e6c36995f1ee418 Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 27 Mar 2020 21:20:12 +0530 Subject: Add registration handler --- cmd/perseus/main.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cmd') 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()) } -- cgit 1.4.1-2-gfad0