-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (32 loc) · 774 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
39
40
41
package main
import (
"fmt"
"log"
"net/http"
"os"
)
var counter = 0
var lastWords []string
func handler(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname()
lastWord := r.URL.Path[1:]
if lastWord == "favicon.ico" {
fmt.Fprintf(w, "Request: %v\nHostname: %v\nWords:%v", counter, hostname, lastWords)
return
}
counter++
if lastWord == "clear" {
lastWords = []string{}
} else if lastWord == "exit" {
os.Exit(1)
} else if lastWord != "" {
lastWords = append(lastWords, lastWord)
}
fmt.Fprintf(w, "Request: %v\nHostname: %v\nVersion: 2\nWords:%v", counter, hostname, lastWords)
}
func main() {
port := "8080"
log.Println("Listening in :" + port)
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":"+port, nil))
}