Skip to content

Instantly share code, notes, and snippets.

@kazeburo
Created May 25, 2023 06:24
Show Gist options
  • Save kazeburo/795c8602e26aca66301e0142bcc024ea to your computer and use it in GitHub Desktop.
Save kazeburo/795c8602e26aca66301e0142bcc024ea to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
"net/http"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"golang.ngrok.com/ngrok"
"golang.ngrok.com/ngrok/config"
)
func main() {
err := run(context.Background())
if err != nil {
log.Fatal(err)
}
}
func helloHandler(c echo.Context) error {
return c.String(http.StatusOK, "Hello from CloudShell")
}
func run(ctx context.Context) error {
t, err := ngrok.Listen(
ctx,
config.HTTPEndpoint(),
ngrok.WithAuthtokenFromEnv(),
ngrok.WithHeartbeatInterval(10*time.Second),
)
if err != nil {
return err
}
log.Printf("tunnel created: %s", t.URL())
e := echo.New()
e.Use(middleware.Logger())
e.GET("/", helloHandler)
return http.Serve(t, e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment