summary refs log tree commit diff stats
path: root/cmd
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-27 21:20:12 +0530
committerAndinus <andinus@nand.sh>2020-03-27 21:20:12 +0530
commit3dee7955670274b92ad8b3931e6c36995f1ee418 (patch)
treec312153b27a2e6e32e900112978696c7aae312b8 /cmd
parent97f36a08c7a5e3bd7921a26af89eee8ad9b3e3d7 (diff)
downloadperseus-3dee7955670274b92ad8b3931e6c36995f1ee418.tar.gz
Add registration handler
Diffstat (limited to 'cmd')
-rw-r--r--cmd/perseus/main.go26
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())
 }
'>171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275