forked from PicPay/picpay-jr-devops-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
38 lines (30 loc) · 802 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/go-redis/redis"
"github.com/rs/cors"
)
func main() {
redis_host := "redis"
redis_port := "6379"
mux := http.NewServeMux()
mux.HandleFunc("/health", func(writer http.ResponseWriter, request *http.Request) {
if request.Method == "OPTIONS" {
writer.WriteHeader(http.StatusOK)
return
}
fmt.Fprintf(writer, "up")
})
mux.HandleFunc("/data", func(writer http.ResponseWriter, request *http.Request) {
client := redis.NewClient(&redis.Options{Addr: redis_host + ":" + redis_port})
key := client.Get("SHAREDKEY")
fmt.Fprintf(writer, key.Val())
})
handler := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedHeaders: []string{"*"},
}).Handler(mux)
log.Fatal(http.ListenAndServe(":8080", handler))
}