-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
53 lines (40 loc) · 1.34 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/rynop/abp-fargate/pkg/blogserver"
"github.com/rynop/abp-fargate/pkg/imageserver"
"github.com/rynop/abp-fargate/pkg/serverhooks"
"github.com/rynop/abp-fargate/rpc/publicservices"
)
func setupRoutes() http.Handler {
mux := http.NewServeMux()
svrHooks := serverhooks.NewServerHooks()
blogServerHandler := publicservices.NewBlogServer(&blogserver.Server{}, svrHooks)
wrappedBlogHandler := serverhooks.AddHeadersToContext(blogServerHandler)
mux.Handle(publicservices.BlogPathPrefix, wrappedBlogHandler)
imageHandler := publicservices.NewImageServer(&imageserver.Server{}, svrHooks)
wrappedImageHandler := serverhooks.AddHeadersToContext(imageHandler)
mux.Handle(publicservices.ImagePathPrefix, wrappedImageHandler)
appStage, _ := os.LookupEnv("APP_STAGE")
mux.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "pong. stage:"+appStage)
})
return mux
}
func main() {
//Dump all env vars
for _, pair := range os.Environ() {
fmt.Println(pair)
}
mux := setupRoutes()
listenPort, exists := os.LookupEnv("LISTEN_PORT")
if !exists {
listenPort = "8080"
}
appStage, _ := os.LookupEnv("APP_STAGE")
log.Print("Listening on " + listenPort + " in stage " + appStage + " docker image: --CodeImage--")
http.ListenAndServe(":"+listenPort, mux)
}