package server import ( "embed" "fmt" "io/fs" "net" "net/http" "sakura/cfg" "sakura/server/api" "strconv" "github.com/spf13/pflag" ) //go:embed web var web embed.FS func Start() { pflag.Parse() fmt.Println("Server started") addr := net.JoinHostPort(*cfg.Host, strconv.Itoa(*cfg.Port)) fmt.Printf("Listening on %s\n", addr) sub, err := fs.Sub(web, "web") if err != nil { panic(err) } http.Handle("/", http.FileServer(http.FS(sub))) http.HandleFunc(cfg.CreateMethod+" "+cfg.CreatePath, api.GameCreate) http.HandleFunc(cfg.ConnectMethod+" "+cfg.ConnectPath, api.GameConnect) err = http.ListenAndServe(addr, nil) if err != nil { panic(err) } }