-
Notifications
You must be signed in to change notification settings - Fork 0
/
bancha.go
86 lines (73 loc) · 2.49 KB
/
bancha.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"github.com/labstack/echo"
"io/ioutil"
"fmt"
"github.com/urfave/cli"
"os"
"github.com/fatih/color"
)
var (
port string
basePath string
blue = color.New(color.BgBlue).SprintFunc()
green = color.New(color.FgGreen).SprintFunc()
)
const (
name = "Ban Chá! ʕ•ᴥ•ʔ"
version = "1.0.0"
description = "Ban chá! A Simple HTTP Server with go. Debug/Log Porpose!"
banner = `
██████╗ █████╗ ███╗ ██╗ ██████╗██╗ ██╗ █████╗
██╔══██╗██╔══██╗████╗ ██║██╔════╝██║ ██║██╔══██╗
██████╔╝███████║██╔██╗ ██║██║ ███████║███████║
██╔══██╗██╔══██║██║╚██╗██║██║ ██╔══██║██╔══██║
██████╔╝██║ ██║██║ ╚████║╚██████╗██║ ██║██║ ██║
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝
Simple http server to log!
Powered by Luis Vieira ʕ•ᴥ•ʔ
`
)
func main() {
app := cli.NewApp()
app.Name = name
app.Version = version
app.Description = description
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "port, p",
Value: "8085",
Usage: "port for the server",
Destination: &port,
},
cli.StringFlag{
Name: "basePath, b",
Value: "/",
Usage: "the base bath for the server",
Destination: &basePath,
},
}
fmt.Printf("%s\n", green(banner))
app.Action = func(c *cli.Context) error {
e := echo.New()
e.HideBanner = true
e.Debug = true
fmt.Printf("base path: %s\n", green(basePath))
fmt.Printf("serving port: %s\n", green(port))
e.Any(basePath, printRequest)
e.Start(":" + port)
return nil
}
app.Run(os.Args)
}
func printRequest(c echo.Context) error {
s, _ := ioutil.ReadAll(c.Request().Body)
fmt.Printf("%s\n", blue("=============HEADERS============="))
for k, v := range c.Request().Header {
fmt.Printf("%s %s\n", k, v)
}
fmt.Printf("%s\n", blue("=============BODY============="))
//fmt.Printf("This is a %s and this is %s.\n", yellow("warning"), red("error"))
fmt.Printf("Json Received: %s\n", s)
return c.String(204, "")
}