diff --git a/.gitignore b/.gitignore index 97f8b5c..3028a8b 100644 --- a/.gitignore +++ b/.gitignore @@ -160,9 +160,9 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -# OPENCSGO +### CSGOWTF ### .login_key .sentry .server.json -opencsgo.db - +csgowtfd.db +config.yaml diff --git a/README.md b/README.md index 06aa06d..20be975 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# opencsgo +# CSGOWTFD + +CSGOW.TF's backend written in Go. diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 1c4a7c5..0000000 --- a/config.yaml +++ /dev/null @@ -1,13 +0,0 @@ -logging: - level: DEBUG - -parser: - worker: 6 - -steam: - username: steamusername - api_key: apikey - rate_per_sec: 1 - -httpd: - cors_allow_domains: '*' \ No newline at end of file diff --git a/config_example.yaml b/config_example.yaml new file mode 100644 index 0000000..c00946e --- /dev/null +++ b/config_example.yaml @@ -0,0 +1,17 @@ +logging: + level: DEBUG + +parser: + worker: 6 + +steam: + username: steamuser + api_key: apikey + rate_per_sec: 1 + +httpd: + cors_allow_domains: '*' + listen: + - host: localhost + port: 8000 + - socket: /tmp/csgowtf.sock \ No newline at end of file diff --git a/main.go b/main.go index 12344d1..5b6bb4c 100644 --- a/main.go +++ b/main.go @@ -10,12 +10,14 @@ import ( "csgowtfd/ent/stats" "csgowtfd/utils" "flag" + "fmt" "github.com/gorilla/handlers" "github.com/gorilla/mux" _ "github.com/mattn/go-sqlite3" log "github.com/sirupsen/logrus" "go.uber.org/ratelimit" "gopkg.in/yaml.v3" + "net" "net/http" "os" "strconv" @@ -397,11 +399,29 @@ func main() { go utils.GCInfoParser(sendGC, demoLoader, demoParser, db, conf.Steam.APIKey, rL) go housekeeping() + // Define routes router = mux.NewRouter().StrictSlash(true) router.HandleFunc("/player/{id}", getPlayer).Methods("GET") router.HandleFunc("/player/trackme", postPlayerTrackMe).Methods("POST") router.HandleFunc("/match/parse/{sharecode}", getMatchParse).Methods("GET") router.HandleFunc("/match/{id:[0-9]{19}}", getMatch).Methods("GET") loggedRouter := handlers.LoggingHandler(os.Stdout, router) - utils.Check(http.ListenAndServe(":8000", loggedRouter)) + + for _, l := range conf.Httpd.Listen { + if l.Socket != "" { + sL, err := net.Listen("unix", l.Socket) + if err != nil { + log.Fatalf("Failure listing on socket %s: %v", l.Socket, err) + } + err = http.Serve(sL, loggedRouter) + if err != nil { + log.Fatalf("Failure serving on socket %s: %v", l.Socket, err) + } + } else { + err = http.ListenAndServe(fmt.Sprintf("%s:%d", l.Host, l.Port), loggedRouter) + if err != nil { + log.Fatalf("Failure listing on %s:%d: %v", l.Host, l.Port, err) + } + } + } } diff --git a/utils/utils.go b/utils/utils.go index 27baf91..99083cb 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -36,6 +36,11 @@ type Conf struct { } Httpd struct { CORSAllowDomains string `yaml:"cors_allow_domains"` + Listen []struct { + Socket string + Host string + Port int + } } }