From bd5e602dc1d7dcef03a2d0a01f3f03e1f27c06a0 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Sun, 12 May 2019 04:06:35 -0400 Subject: commented some --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 92b8971..3611c05 100644 --- a/main.go +++ b/main.go @@ -15,10 +15,13 @@ const getwtxt = "0.1" func main() { log.Printf("getwtxt " + getwtxt + "\n") + // more precise path-based routing index := mux.NewRouter() api := index.PathPrefix("/api").Subrouter() + // gorilla/mux makes path validation painless index.HandleFunc("/", indexHandler) + index.HandleFunc("/api", apiBaseHandler) api.HandleFunc("/", apiBaseHandler) api.HandleFunc("/{format:(?:plain)}", apiFormatHandler) api.Path("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets)}"). @@ -27,8 +30,11 @@ func main() { api.HandleFunc("/{format:(?:plain)}/tags", apiTagsBaseHandler) api.HandleFunc("/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}", apiTagsHandler) + // format the port for the http.Server object portnum := fmt.Sprintf(":%v", confObj.port) - + // defines options for the http server. + // handlers.CompressHandler gzips all responses. + // Write/Read timeouts are self explanatory. server := &http.Server{ Handler: handlers.CompressHandler(index), Addr: portnum, @@ -36,9 +42,11 @@ func main() { ReadTimeout: 15 * time.Second, } + log.Printf("Listening on port %v\n", confObj.port) err := server.ListenAndServe() if err != nil { log.Printf("%v\n", err) } + closelog <- true } -- cgit 1.4.1-2-gfad0