-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.go
More file actions
42 lines (30 loc) · 729 Bytes
/
Copy pathsite.go
File metadata and controls
42 lines (30 loc) · 729 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
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"strings"
"net/http"
"os"
"time"
)
func main() {
http.HandleFunc("/", hello)
http.HandleFunc("/env", env)
fmt.Println("listening...")
err := http.ListenAndServe(":80", nil)
if err != nil {
panic(err)
}
time.Sleep(500 * time.Millisecond)
fmt.Println("Hello World!")
}
func hello(res http.ResponseWriter, req *http.Request) {
fmt.Fprintln(res, "Hello World!")
}
func env(res http.ResponseWriter, req *http.Request) {
env := os.Environ()
fmt.Fprintln(res, "List of Environtment variables : \n")
for index, value := range env {
name := strings.Split(value, "=") // split by = sign
fmt.Fprintf(res, "[%d] %s : %v\n", index, name[0], name[1])
}
}