forked from multiprocessio/httpmirror
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
35 lines (30 loc) · 668 Bytes
/
Copy pathmain.go
File metadata and controls
35 lines (30 loc) · 668 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
package main
import (
"log"
"net/http"
"os"
"time"
)
func mirrorHandler(writer http.ResponseWriter, request *http.Request) {
request.Write(writer)
}
func cookieHandler(writer http.ResponseWriter, request *http.Request) {
cookie := &http.Cookie{}
cookie.Name = "test"
cookie.Value = time.Now().Format(time.RFC3339)
http.SetCookie(writer, cookie)
}
func main() {
// Port is last argument
port := "8080"
for _, arg := range os.Args[1:] {
port = arg
}
log.Println("Listening on :" + port)
http.HandleFunc("/", mirrorHandler)
http.HandleFunc("/cookie", cookieHandler)
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatal(err)
}
}