diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-12 04:06:35 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-12 04:06:35 -0400 |
commit | bd5e602dc1d7dcef03a2d0a01f3f03e1f27c06a0 (patch) | |
tree | ac6b9be4e24f0c920e5b2df881880a90c13ecf7b /main.go | |
parent | 7a9dce46dffd9aec48910f0d0fceac00c8ed25da (diff) | |
download | getwtxt-bd5e602dc1d7dcef03a2d0a01f3f03e1f27c06a0.tar.gz |
commented some
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 10 |
1 files changed, 9 insertions, 1 deletions
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 } |