Skip to content

Commit

Permalink
Merge pull request #138 from ngrok/del/update-example-copy
Browse files Browse the repository at this point in the history
update example var names
  • Loading branch information
bobzilladev authored Nov 16, 2023
2 parents 8b5875b + 8ce6216 commit 716fe70
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions examples/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ func main() {
}

func run(ctx context.Context) error {
tun, err := ngrok.Listen(ctx,
ln, err := ngrok.Listen(ctx,
config.HTTPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
)
if err != nil {
return err
}

log.Println("tunnel created:", tun.URL())
log.Println("Ingress established at:", ln.URL())

return http.Serve(tun, http.HandlerFunc(handler))
return http.Serve(ln, http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 3 additions & 3 deletions examples/logging/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func run(ctx context.Context, lvlName string) error {
return err
}

tun, err := ngrok.Listen(ctx,
ln, err := ngrok.Listen(ctx,
config.HTTPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
ngrok.WithLogger(&logger{lvl}),
Expand All @@ -56,9 +56,9 @@ func run(ctx context.Context, lvlName string) error {
return err
}

log.Println("tunnel created:", tun.URL())
log.Println("Ingress established at:", ln.URL())

return http.Serve(tun, http.HandlerFunc(handler))
return http.Serve(ln, http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions examples/ngrok-forward-lite/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Naïve ngrok agent implementation.
// Sets up a single tunnel and forwards it to another service.
// Sets up a single listener and forwards it to another service.

package main

Expand Down Expand Up @@ -67,7 +67,7 @@ func run(ctx context.Context, backend *url.URL) error {
return err
}

l.Log(ctx, ngrok_log.LogLevelInfo, "tunnel created", map[string]any{
l.Log(ctx, ngrok_log.LogLevelInfo, "ingress established", map[string]any{
"url": fwd.URL(),
})

Expand Down
10 changes: 5 additions & 5 deletions examples/ngrok-http-lite/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Naïve ngrok agent implementation.
// Sets up a single tunnel and connects to an arbitrary HTTP server.
// Sets up a single listener and connects to an arbitrary HTTP server.

package main

Expand Down Expand Up @@ -38,7 +38,7 @@ func main() {
fmt.Fprintln(w, "Hello from ngrok-go!")
})}

// Serve with tunnel backend
// Serve with listener backend
if err := run(context.Background(), server); err != nil {
log.Fatal(err)
}
Expand All @@ -50,16 +50,16 @@ func main() {
}

func run(ctx context.Context, server *http.Server) error {
tunnel, err := ngrok.ListenAndServeHTTP(ctx,
ln, err := ngrok.ListenAndServeHTTP(ctx,
server,
config.HTTPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
ngrok.WithLogger(&logger{lvl: ngrok_log.LogLevelDebug}),
)

if err == nil {
l.Log(ctx, ngrok_log.LogLevelInfo, "tunnel created", map[string]any{
"url": tunnel.URL(),
l.Log(ctx, ngrok_log.LogLevelInfo, "ingress established", map[string]any{
"url": ln.URL(),
})
}

Expand Down
6 changes: 3 additions & 3 deletions examples/slog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func run(ctx context.Context, lvlName string) error {
h := slog.HandlerOptions{Level: programLevel}.NewTextHandler(os.Stdout)
slog.SetDefault(slog.New(h))

tun, err := ngrok.Listen(ctx,
ln, err := ngrok.Listen(ctx,
config.HTTPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
ngrok.WithLogger(slogadapter.NewLogger(slog.Default())),
Expand All @@ -59,9 +59,9 @@ func run(ctx context.Context, lvlName string) error {
return err
}

slog.Info("tunnel created", "url", tun.URL())
slog.Info("Ingress established", "url", ln.URL())

return http.Serve(tun, http.HandlerFunc(handler))
return http.Serve(ln, http.HandlerFunc(handler))
}

func handler(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 3 additions & 3 deletions examples/tcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func main() {
}

func run(ctx context.Context) error {
tun, err := ngrok.Listen(ctx,
ln, err := ngrok.Listen(ctx,
config.TCPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
)
if err != nil {
return err
}

log.Println("started tunnel:", tun.URL())
log.Println("Ingress established at:", ln.URL())

return runListener(ctx, tun)
return runListener(ctx, ln)
}

func runListener(ctx context.Context, l net.Listener) error {
Expand Down

0 comments on commit 716fe70

Please sign in to comment.