Skip to content

Instantly share code, notes, and snippets.

@gawen
Created October 27, 2022 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gawen/02e210d020cc8e183759d69df2ea2330 to your computer and use it in GitHub Desktop.
Save gawen/02e210d020cc8e183759d69df2ea2330 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
"time"
"github.com/ngrok/ngrok-go"
ngrokconfig "github.com/ngrok/ngrok-go/config"
)
func main() {
ctx := context.TODO()
session, err := ngrok.Connect(ctx,
ngrok.WithAuthtoken("XXX"),
)
if err != nil {
log.Fatal(err)
}
defer session.Close()
tunnel, err := session.StartTunnel(ctx, ngrokconfig.HTTPEndpoint(
ngrokconfig.WithDomain("domain.eu.ngrok.io"),
ngrokconfig.WithScheme("https"),
ngrokconfig.WithForwardsTo("localhost:8080"),
))
if err != nil {
log.Fatal(err)
}
_ = tunnel
for {
time.Sleep(time.Hour)
}
}
12:55:21.876 TRC open stream :ngrok err=null id=XXX obj=csess reqtype=0
12:55:21.876 TRC encode request :ngrok err=null id=XXX obj=csess req={"ClientId":"","Extra":{"Arch":"arm64","Authtoken":"XXX","ClientType":"library","ConfigVersion":"","Cookie":"","CustomCAs":false,"CustomInterface":false,"Fingerprint":null,"HeartbeatInterval":10000000000,"HeartbeatTolerance":15000000000,"Hostname":"","Metadata":"","MutualTLS":false,"OS":"darwin","ProxyType":"","RestartUnsupportedError":"the agent has not defined a callback for this operation","ServiceRun":false,"StopUnsupportedError":"the agent has not defined a callback for this operation","UpdateUnsupportedError":"the agent has not defined a callback for this operation","UserAgent":"","Ve... sid=5
12:55:21.922 TRC decoded response :ngrok err=null id=XXX obj=csess resp={"ClientId":"XXX","Error":"","Extra":{"AccountName":"XXX","Banner":"Try our new native Go library: https://github.com/ngrok/ngrok-go","Cookie":"XXX","PlanName":"Pro","Region":"eu","SessionDuration":0,"Version":"prod"},"Version":"2"} sid=5
12:55:21.922 INF client session established :ngrok id=XXX obj=csess
12:55:21.923 TRC open stream :ngrok clientid=XXX err=null id=XXX obj=csess reqtype=1
12:55:21.923 TRC encode request :ngrok clientid=XXX err=null id=XXX obj=csess req={"Extra":{"IPPolicyRef":"","Metadata":"","Token":""},"ForwardsTo":"localhost:8080","Id":"","Opts":{"Auth":"","BasicAuth":null,"CircuitBreaker":null,"Compression":null,"HostHeaderRewrite":false,"Hostname":"XXX","IPRestriction":null,"LocalURLScheme":"","MutualTLSCA":null,"OAuth":null,"OIDC":null,"ProxyProto":0,"RequestHeaders":null,"ResponseHeaders":null,"Subdomain":"","WebhookVerification":null,"WebsocketTCPConverter":null},"Proto":"https"} sid=7
12:55:21.972 TRC decoded response :ngrok clientid=XXX err=null id=XXX obj=csess resp={"Error":"","Extra":{"Token":"zXZnlokG6k/qCPMQa0NFNk5RVhTql7Ky$+yLmEc/xa0S7c59cVjMD9lLWN83u7lb0PEoWTtMcE3BHVhYFLHrzrxUuVbRUmK6nY9mISmMUi1ifrewphHUkkKbdwxyTg0gjyxUBx/tYzHDdM8zxd/xvN7U63xGZoFXYtr32PmDUXJ+5b0mvpozaaaJBL/JZz+T1A637ZP2Ret8hYAxBnLVvSI0EWAI7FbFJG+Xiw3lM5btZro3xbf0QTK3BXAVuIECJ+Y8NkHi/YxXNtGi0fcCpVBKYtYaKeYmdJpCYmer3JygwSdMXWDfnxw0pUBgr9ttev8Ge5wr8ka5af52qgA5hIckcXoOeIWtDrIMND94mRnxWTDBUKmqxfIN9hxsdMycJFj5edewlXV23enVD9yMhu9YtCi1x+VMfZgqeB7Tch/V7/i76LkCJfIgJktj3Wub3atZTtfz9Kurng1YsL0NRbp5NbgTwhhCF9g46o1kThi9lfmEW96nC3dzEkGcW3B3fm9uC7pVoCcHV5TEecGugcKW/Mb4N//cMarYJyZzSTqy0WtvcfP+PMpBYlMr9C2t9hGNR0nhBJexz3+8gb7JxDrH0Wz/9W2... sid=7
// connected
12:55:31.892 TRC heartbeat received :ngrok clientid=XXX id=XXX latency_ms=15 obj=csess
12:55:41.897 TRC heartbeat received :ngrok clientid=XXX id=XXX latency_ms=19 obj=csess
12:55:51.898 TRC heartbeat received :ngrok clientid=XXX id=XXX latency_ms=21 obj=csess
// CTRL+C
12:55:53.571 INF terminated received
12:55:53.571 INF exiting...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment