feat(muxterm): scaffold Go module with main.go entry point

This commit is contained in:
Ken
2026-05-28 06:06:36 +00:00
parent 9db70593c2
commit 595d08ba5a
3 changed files with 56 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
module github.com/muxplex/muxterm
go 1.22
require (
github.com/creack/pty v1.1.24
github.com/gorilla/websocket v1.5.3
)
+2
View File
@@ -0,0 +1,2 @@
github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"encoding/json"
"flag"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
addr := flag.String("addr", "127.0.0.1:7682", "listen address")
secret := flag.String("secret", os.Getenv("MUXTERM_SECRET"), "shared secret (or set MUXTERM_SECRET)")
flag.Parse()
if *secret == "" {
log.Fatal("secret is required: use --secret or set MUXTERM_SECRET")
}
pool := NewPool()
// Graceful shutdown on SIGTERM/SIGINT
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
go func() {
<-sig
pool.CloseAll()
os.Exit(0)
}()
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
HandleWebSocket(pool, *secret, w, r)
})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
})
log.Printf("muxterm listening on %s", *addr)
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal(err)
}
}