Skip to content

Commit

Permalink
added fasthttp example
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrusjc committed Apr 4, 2024
1 parent 2fba2d6 commit 056ab25
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/fasthttp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"context"
"fmt"
"log"

"github.com/valyala/fasthttp"
"golang.ngrok.com/ngrok"
"golang.ngrok.com/ngrok/config"
)

func main() {
if err := run(context.Background()); err != nil {
log.Fatalf("main: %v", err)
}
}

func run(ctx context.Context) error {
tun, err := ngrok.Listen(ctx,
config.HTTPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
)
if err != nil {
return err
}
log.Println("tunnel created:", tun.URL())

var serv fasthttp.Server

serv.Handler = func(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello! You're requesting %q", ctx.RequestURI())
}

serv.Serve(tun)

return nil
}

0 comments on commit 056ab25

Please sign in to comment.