-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhandler.go
57 lines (43 loc) · 1.16 KB
/
handler.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
package main
import (
"context"
"os"
"strings"
"net/http"
"golang.ngrok.com/ngrok"
)
func (r *runner) handler(w http.ResponseWriter, req *http.Request) {
r.logreq(req)
for key, value := range responseHeaders {
w.Header().Set(key, value)
}
_, err := w.Write([]byte(r.ID))
if err != nil {
log.Warn("cannot write response", "err", err)
}
}
func (r *runner) notify(sigCh chan os.Signal) error {
sig := <-sigCh
return r.end(sig)
}
func connected(ctx context.Context, sess ngrok.Session) {
log.InfoContext(ctx, sessOK)
}
func disconnected(ctx context.Context, sess ngrok.Session, err error) {
var errs, msgs []string
if strings.Contains(err.Error(), ":") {
errs = strings.Split(err.Error(), "\n")
msgs = strings.Split(errs[0], ":")
for i, msg := range msgs {
msgs[i] = strings.TrimSpace(msg)
}
log.ErrorContext(ctx, msgs[0], "err", msgs[1])
// NOTE(dwisiswant0): yea I don't want to handle with `ngrok.Error`
// 'cuz that'll produces switch..case [CHANGE MY MIND]
if strings.Contains(err.Error(), authFailed) {
log.InfoContext(ctx, infGetAuthtokenMsg, "ref", infGetAuthtokenRef)
os.Exit(2)
}
}
log.ErrorContext(ctx, err.Error())
}