-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
52 lines (42 loc) · 1.23 KB
/
main.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
package main
import (
"context"
"fmt"
"github.com/kataras/golog"
"golang.ngrok.com/ngrok"
"golang.ngrok.com/ngrok/config"
"golang.ngrok.com/ngrok/log"
)
// $ go get golang.ngrok.com/ngrok@latest
// $ go run main.go
type ngrokLoggerAdapter struct {
logger *golog.Logger
}
// Log(context context.Context, level LogLevel, msg string, data map[string]interface{})
// Log implements the ngrok.Logger interface.
func (l *ngrokLoggerAdapter) Log(context context.Context, level log.LogLevel, msg string, data map[string]interface{}) {
l.logger.Info(msg, golog.Fields(data))
}
func main() {
logger := golog.New()
tun, err := ngrok.Listen(context.Background(),
config.HTTPEndpoint(
config.WithDomain("domain.com"),
// config.WithMutualTLSCA(ca),
config.WithForwardsTo("http://localhost:80"),
config.WithCircuitBreaker(0.8),
// config.WithCompression(),
// config.WithProxyProto(config.ProxyProtoV2),
config.WithScheme(config.SchemeHTTPS),
),
ngrok.WithLogger(&ngrokLoggerAdapter{logger: logger /* OR golog.Default */}),
ngrok.WithAuthtoken("NGROK_AUTH_TOKEN"),
// ngrok.WithServer("tunnel.ngrok.com:443"),
ngrok.WithRegion("us"),
)
if err != nil {
logger.Fatal(err)
}
defer tun.Close()
fmt.Println(tun.URL())
}