-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathreporter.go
48 lines (39 loc) · 981 Bytes
/
reporter.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
package proxy
import (
"fmt"
"net/http"
"github.com/fatih/color"
"github.com/go-openapi/errors"
)
type Reporter interface {
Success(req *http.Request)
Error(req *http.Request, err error)
Warning(req *http.Request, msg string)
Report()
}
type LogReporter struct {
}
func (r *LogReporter) Success(req *http.Request) {
fmt.Fprintf(color.Output, "%s %s %s\n",
color.GreenString("✔"), req.Method, req.URL,
)
}
func (r *LogReporter) Error(req *http.Request, err error) {
fmt.Fprintf(color.Output, "%s %s %s\n",
color.RedString("✗"), req.Method, req.URL,
)
if cErr, ok := err.(*errors.CompositeError); ok {
for i, err := range cErr.Errors {
fmt.Printf(" %d) %s\n", i+1, err)
}
} else {
fmt.Printf(" => %s\n", err)
}
}
func (r *LogReporter) Warning(req *http.Request, msg string) {
fmt.Fprintf(color.Output, "%s %s %s\n",
color.YellowString("!"), req.Method, req.URL,
)
fmt.Printf(" WARNING: %s\n", msg)
}
func (r *LogReporter) Report() {}