-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhandler.go
34 lines (29 loc) · 862 Bytes
/
handler.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
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"os"
)
var quotes = []string{
"Talk is cheap. Show me the code.",
"First, solve the problem. Then, write the code.",
"Experience is the name everyone gives to their mistakes.",
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand.",
}
func quotesHandler(w http.ResponseWriter, r *http.Request) {
// Get a random quote
message := quotes[rand.Intn(len(quotes))]
// Write the response
fmt.Fprint(w, message)
}
func main() {
listenAddr := ":8080"
if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok {
listenAddr = ":" + val
}
http.HandleFunc("/api/GetQuotes", quotesHandler)
log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr)
log.Fatal(http.ListenAndServe(listenAddr, nil))
}