Files
zeekay 285bb5a76b rename: ziti → zt across all paths
- Repo names: ziti-* → zt-*
- Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt
- Docker images: hanzozt/ziti-* → hanzozt/zt-*
- C/Java/JS symbols: ziti_* → zt_*
- File and directory names updated
2026-02-18 18:34:10 -08:00

54 lines
1.0 KiB
Go

package main
import (
"fmt"
"github.com/hanzozt/sdk-golang/zt"
"net"
"net/http"
"os"
"strconv"
"time"
)
func main() {
http.HandleFunc("/hello", hello)
http.HandleFunc("/add", add)
if err := http.Serve(createZitiListener(), nil); err != nil {
panic(err)
}
}
func hello(w http.ResponseWriter, req *http.Request) {
host, _ := os.Hostname()
_, _ = fmt.Fprintf(w, "ztfied hello from %s", host)
}
func add(w http.ResponseWriter, req *http.Request) {
a, _ := strconv.Atoi(req.URL.Query().Get("a"))
b, _ := strconv.Atoi(req.URL.Query().Get("b"))
c := a + b
_, _ = fmt.Fprintf(w, "ztfied a+b=%d+%d=%d", a, b, c)
}
func createZitiListener() net.Listener {
cfg, err := zt.NewConfigFromFile(os.Args[1])
if err != nil {
panic(err)
}
options := zt.ListenOptions{
ConnectTimeout: 5 * time.Minute,
}
ctx, err := zt.NewContext(cfg)
if err != nil {
panic(err)
}
listener, err := ctx.ListenWithOptions(os.Args[2], &options)
if err != nil {
fmt.Printf("Error binding service %+v\n", err)
panic(err)
}
return listener
}