-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpsvr03.go
More file actions
32 lines (25 loc) · 738 Bytes
/
httpsvr03.go
File metadata and controls
32 lines (25 loc) · 738 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
32
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
fmt.Printf("Starting server at port 8055\n")
log.Fatal(http.ListenAndServe(":8055", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
// declare and init a value for name to be "guest"
name := "guest"
// check to see if they actually provided a value
// for the name parameter
keys, ok := r.URL.Query()["name"]
// if they passed a parameter called "name"
if ok {
name = keys[0] // in the event they used "name" param
// multiple times, we just get the
// first instance
}
fmt.Fprintf(w, "Hello %s!\n", name)
}