summaryrefslogtreecommitdiff
path: root/server/server.go
blob: bc5b77d671820d41ae2498cd27945246a77ac468 (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
package server

import (
	"fmt"
	"net"
	"net/http"
	"sakura/cfg"
	"sakura/server/api"
	"strconv"

	"github.com/spf13/pflag"
)

func Start() {
	pflag.Parse()
	fmt.Println("Server started")
	addr := net.JoinHostPort(*cfg.Host, strconv.Itoa(*cfg.Port))
	fmt.Printf("Listening on %s\n", addr)
	serveFiles()
	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)
	}
}