You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rogueserver/pokerogue-server.go

54 lines
1.5 KiB
Go

package main
import (
"encoding/gob"
"flag"
"log"
"net/http"
"github.com/pagefaultgames/pokerogue-server/api"
"github.com/pagefaultgames/pokerogue-server/db"
)
func main() {
// flag stuff
addr := flag.String("addr", "0.0.0.0:80", "network address for api to listen on")
wwwpath := flag.String("wwwpath", "www", "path to static content to serve")
tlscert := flag.String("tlscert", "", "path to tls certificate to use for https")
tlskey := flag.String("tlskey", "", "path to tls private key to use for https")
dbuser := flag.String("dbuser", "pokerogue", "database username")
dbpass := flag.String("dbpass", "", "database password")
dbproto := flag.String("dbproto", "tcp", "protocol for database connection")
dbaddr := flag.String("dbaddr", "localhost", "database address")
dbname := flag.String("dbname", "pokeroguedb", "database name")
flag.Parse()
// register gob types
gob.Register([]interface{}{})
gob.Register(map[string]interface{}{})
// get database connection
err := db.Init(*dbuser, *dbpass, *dbproto, *dbaddr, *dbname)
if err != nil {
log.Fatalf("failed to initialize database: %s", err)
}
// start web server
mux := http.NewServeMux()
api.Init(mux)
mux.Handle("/", http.FileServer(http.Dir(*wwwpath)))
if *tlscert != "" && *tlskey != "" {
err = http.ListenAndServeTLS(*addr, *tlscert, *tlskey, mux)
} else {
err = http.ListenAndServe(*addr, mux)
}
if err != nil {
log.Fatalf("failed to create http server or server errored: %s", err)
}
}