Created
July 5, 2017 18:23
-
-
Save beeekind/4ecc899279c891ac9c04632d89de956e to your computer and use it in GitHub Desktop.
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 twelvefactor_ping | |
import ( | |
"github.com/b3ntly/twelvefactor_ping/ping" | |
"net/http" | |
"os" | |
"log" | |
"fmt" | |
) | |
var ( | |
PORT = getenv("PORT", "9090") | |
DEFAULT_RESPONSE = getenv("DEFAULT_RESPONSE", "PONG") | |
DEFAULT_LOGGER = log.New(os.Stdout, "", log.Lshortfile) | |
) | |
func getenv(key string, _default string) string { | |
if val := os.Getenv(key); val != "" { | |
return val | |
} | |
return _default | |
} | |
func buildServer(handler func(w http.ResponseWriter, r *http.Request)) *http.Server { | |
return &http.Server{ | |
Addr: fmt.Sprintf(":%s", PORT), | |
Handler: http.HandlerFunc(handler), | |
} | |
} | |
func listen(s *http.Server){ | |
DEFAULT_LOGGER.Fatal(s.ListenAndServe()) | |
} | |
func main(){ | |
service := ping.New(DEFAULT_RESPONSE, DEFAULT_LOGGER) | |
server := buildServer(service.Endpoint) | |
listen(server) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment