-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.go
More file actions
39 lines (34 loc) · 1.02 KB
/
example.go
File metadata and controls
39 lines (34 loc) · 1.02 KB
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
package gohttp
import (
"fmt"
"strings"
)
// RouteHandler routehandler
type RouteHandler struct {
BaseHTTPHandler
}
// GET method
func (ctx *RouteHandler) GET() {
ctx.Output(ctx.RouterList.String())
}
// InfoHandler info handler
type InfoHandler struct {
BaseHTTPHandler
}
// GET method
func (ctx *InfoHandler) GET() {
ctx.ResponseWriter.Header().Set("Content-Type", "text/plain")
result := []string{fmt.Sprintf("\nMethod: %s", ctx.Request.Method),
fmt.Sprintf("Protocol: %s", ctx.Request.Proto),
fmt.Sprintf("Host: %s", ctx.Request.Host),
fmt.Sprintf("RemoteAddr: %s", ctx.Request.RemoteAddr),
fmt.Sprintf("RequestURI: %q", ctx.Request.RequestURI),
fmt.Sprintf("URL: %#v", ctx.Request.URL),
fmt.Sprintf("Body.ContentLength: %d (-1 means unknown)", ctx.Request.ContentLength),
fmt.Sprintf("Close: %v (relevant for HTTP/1 only)", ctx.Request.Close),
fmt.Sprintf("TLS: %#v", ctx.Request.TLS),
fmt.Sprintf("\nHeaders: \n"),
}
ctx.Output(strings.Join(result, "\n"))
ctx.Request.Header.Write(ctx.ResponseWriter)
}