Skip to content

Instantly share code, notes, and snippets.

@temirov
Created October 9, 2018 19:57
Show Gist options
  • Save temirov/9cc811b6a21ed80ebe269b08e77ddb34 to your computer and use it in GitHub Desktop.
Save temirov/9cc811b6a21ed80ebe269b08e77ddb34 to your computer and use it in GitHub Desktop.
A partial (non-compilable) example of usage of "serviceapi" package
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