blob: f6773cbd128ae85072e2d302fb28d2f7fd4d9ca5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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)
}
}
|