mirror of
https://github.com/foomo/gotsrpc.git
synced 2025-10-16 12:35:35 +00:00
35 lines
694 B
Go
35 lines
694 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"os/exec"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/foomo/gotsrpc/v2/example/nullable/service"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
fs := http.FileServer(http.Dir("./client"))
|
|
ws := service.NewDefaultServiceGoTSRPCProxy(&service.Handler{})
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
switch {
|
|
case strings.HasPrefix(r.URL.Path, "/service/"):
|
|
ws.ServeHTTP(w, r)
|
|
default:
|
|
fs.ServeHTTP(w, r)
|
|
}
|
|
})
|
|
|
|
go func() {
|
|
time.Sleep(time.Second)
|
|
_ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run()
|
|
}()
|
|
|
|
panic(http.ListenAndServe("localhost:3000", mux)) //nolint:gosec
|
|
}
|