mirror of
https://github.com/openziti/zrok.git
synced 2025-07-16 14:15:05 +02:00
* added first iteration decorator for zrok and example flask server * update requirements. Add context managing for share and access. Updated pastebin example to better cleanup * setup and sample tweaks * small linting updates and example changes * A few small fixes * fix long description * Update the ignore file. Considering moving location of this. * Added flake8 linting for builds * use python 3.10 * move setup python to its own block * added back in the py name * update changelogs and add readme --------- Signed-off-by: Cam Otts <otts.cameron@gmail.com> Co-authored-by: Kenneth Bingham <kenneth.bingham@netfoundry.io>
52 lines
956 B
Go
52 lines
956 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/openziti/zrok/environment"
|
|
"github.com/openziti/zrok/sdk/golang/sdk"
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func helloZrok(w http.ResponseWriter, r *http.Request) {
|
|
io.WriteString(w, "Hello zrok!\n")
|
|
}
|
|
|
|
func main() {
|
|
root, err := environment.LoadRoot()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
shr, err := sdk.CreateShare(root, &sdk.ShareRequest{
|
|
BackendMode: sdk.TcpTunnelBackendMode,
|
|
ShareMode: sdk.PublicShareMode,
|
|
Frontends: []string{"public"},
|
|
Target: "http-server",
|
|
})
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer func() {
|
|
if err := sdk.DeleteShare(root, shr); err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
|
|
conn, err := sdk.NewListener(shr.Token, root)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
fmt.Println("Access server at the following endpoints: ", strings.Join(shr.FrontendEndpoints, "\n"))
|
|
|
|
http.HandleFunc("/", helloZrok)
|
|
|
|
if err := http.Serve(conn, nil); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|