~xenrox/10man-api

7d7099856ce985345d3e1f3226769c8d94948fe8 — Thorben Günther 2 years ago 709ed84 0.1.0
Make port configurable
3 files changed, 11 insertions(+), 3 deletions(-)

M README.md
M config/config.go
M server.go
M README.md => README.md +2 -0
@@ 9,6 9,8 @@ Code for [10man](https://hub.xenrox.net/~xenrox/10man/) API.
Your config file should be placed at `/etc/10man-api/config`.

```
# Port
port 8080
# Connection string for the database (required)
connection-string postgresql://user:pass@localhost/db?sslmode=disable
# Comma separated list of steamID64 for users that should become an admin

M config/config.go => config/config.go +7 -0
@@ 9,6 9,8 @@ import (

var configPath string = "/etc/10man-api/config"

var Port string

// ConnectionString is used to connect to the database
var ConnectionString string



@@ 25,6 27,11 @@ func init() {

	for _, d := range cfg {
		switch d.Name {
		case "port":
			if err := d.ParseParams(&Port); err != nil {
				log.Fatalf("could not parse port: %v", err)
			}

		case "connection-string":
			if err := d.ParseParams(&ConnectionString); err != nil {
				log.Fatalf("could not parse connection-string: %v", err)

M server.go => server.go +2 -3
@@ 7,18 7,17 @@ import (
	"os/signal"
	"syscall"

	"git.xenrox.net/~xenrox/10man-api/config"
	"git.xenrox.net/~xenrox/10man-api/database"
	"git.xenrox.net/~xenrox/10man-api/graph"
	"git.xenrox.net/~xenrox/10man-api/graph/generated"
	"github.com/99designs/gqlgen/graphql/handler"
)

const defaultPort = "8080"

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = defaultPort
		port = config.Port
	}

	sigs := make(chan os.Signal, 1)