-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (31 loc) · 764 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
func main() {
initializeService()
r := mux.NewRouter()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Hello world")
})
http.Handle("/", r)
var serverPort = os.Getenv("SERVICE_INTERNAL_PORT")
if serverPort == "" {
serverPort = "80"
}
log.Println(fmt.Sprintf("Starting server, listening [port %s]", serverPort))
log.Fatal(http.ListenAndServe(":"+serverPort, nil))
}
func initializeService() {
log.Println(fmt.Sprintf("Service started [PID %d]", os.Getpid()))
err := godotenv.Load()
if err != nil {
log.Print("No .env file, using env variables as they are")
}
}