Created
October 9, 2018 19:57
-
-
Save temirov/9cc811b6a21ed80ebe269b08e77ddb34 to your computer and use it in GitHub Desktop.
A partial (non-compilable) example of usage of "serviceapi" package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"flag" | |
"fmt" | |
"lib/serviceapi" | |
"github.com/google/uuid" | |
"log" | |
"net/http" | |
) | |
func startHTTPServer(address string, handler *http.ServeMux, readTimeout *time.Duration, writeTimeout *time.Duration) { | |
httpServer := http.Server{ | |
Addr: address, | |
Handler: handler, | |
ReadTimeout: *readTimeout, | |
WriteTimeout: *writeTimeout, | |
} | |
defer utils.CheckFunc(httpServer.Close) | |
httpStartMessage := fmt.Sprintf("starting server at %s", address) | |
fmt.Println(httpStartMessage) | |
log.Fatal(httpServer.ListenAndServe()) | |
} | |
func main() { | |
flag.Parse() | |
addr := fmt.Sprintf("%s:%d", httpIP, httpPort) | |
handler := serviceapi.Handlers() | |
handler.HandleFunc(recommendationsPath, recommendationsHandle) | |
timeout := 1 * time.Second | |
startHTTPServer(addr, handler, &timeout, &timeout) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment