Skip to content

Commit

Permalink
add ngrok integration example
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Jan 21, 2024
1 parent ec2064d commit cc1dbac
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version-file: './go.mod'
check-latest: true
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2017-2023, Gerasimos (Makis) Maropoulos ([email protected])
Copyright (c) 2017-2024, Gerasimos (Makis) Maropoulos ([email protected])
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func main() {

## Examples


* [basic](_examples/basic/main.go)
* [output per level](_examples/level-output/main.go)
* [child](_examples/child/main.go)
Expand All @@ -320,6 +321,8 @@ func main() {
* [scan](_examples/scan/main.go)
* [logurs integration](_examples/integrations/logrus/main.go)
* [log.Logger std integration](_examples/integrations/std/main.go)
* [ngrok integration](_examples/ngrok-logger/main.go) **NEW**
* [postgres integration](https://github.com/kataras/pgx-golog) **NEW**
* [new instance](_examples/instance/main.go)

## 🔥 Benchmarks
Expand Down
28 changes: 28 additions & 0 deletions _examples/ngrok-logger/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module github.com/kataras/golog/_examples/ngrok-logger

go 1.21

replace github.com/kataras/golog => ../../

require (
github.com/kataras/golog v0.0.0-00010101000000-000000000000
golang.ngrok.com/ngrok v1.7.0
xorm.io/xorm v1.3.6
)

require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/inconshreveable/log15 v3.0.0-testing.3+incompatible // indirect
github.com/inconshreveable/log15/v3 v3.0.0-testing.5 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kataras/pio v0.0.13 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.ngrok.com/muxado/v2 v2.0.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.12.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
317 changes: 317 additions & 0 deletions _examples/ngrok-logger/go.sum

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions _examples/ngrok-logger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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())
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ go 1.21

require github.com/kataras/pio v0.0.13

require golang.org/x/sys v0.13.0 // indirect
require golang.org/x/sys v0.16.0 // indirect
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/kataras/pio v0.0.13 h1:x0rXVX0fviDTXOOLOmr4MUxOabu1InVSTu5itF8CXCM=
github.com/kataras/pio v0.0.13/go.mod h1:k3HNuSw+eJ8Pm2lA4lRhg3DiCjVgHlP8hmXApSej3oM=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit cc1dbac

Please sign in to comment.