zero-configuration library to use Cloudflare Tunnel in your Go application without deploying a separate service.
Note that this ties you to a particular version of cloudflared, so you may want to use a separate service in production in case they break the API.
cloudflared tunnel --url http://localhost:12345equivalent code if you want to use it in your Go application:
package main
import (
"fmt""context""github.com/wizzard0/trycloudflared"
)
funcmain() {
// start your http server on port 12345// e.g. http.ListenAndServe(":12345", nil)// ...ctx, cancel:=context.WithCancel(context.Background())
// this will expose localhost:12345 via https://something.trycloudflare.comurl, err:=trycloudflared.CreateCloudflareTunnel(ctx, 12345)
iferr!=nil {
panic(err)
}
// url is the URL of the tunnelfmt.Println(url)
// do something with the tunnel// ...// cancel the tunnel when donecancel()
}