-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
31 lines (27 loc) · 706 Bytes
/
Copy pathmain.go
File metadata and controls
31 lines (27 loc) · 706 Bytes
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
package main
import (
"fmt"
"os"
"net/http"
"strconv"
)
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func SimpleServer(w http.ResponseWriter, r *http.Request) {
response_code_str := getEnv("RESPONSE_CODE", "404")
response_code, err := strconv.Atoi(response_code_str)
if err != nil {
fmt.Println("Invalid response code")
}
response_text := getEnv("RESPONSE_TEXT", "default backend - " + response_code_str)
w.WriteHeader(response_code)
fmt.Fprintf(w, response_text)
}
func main() {
http.HandleFunc("/", SimpleServer)
http.ListenAndServe(":8080", nil)
}