~xenrox/10man-api

c8feb5ff75c78a9818e51c55e3d2dc628cb43477 — Thorben Günther 1 year, 6 months ago e46e516
server: Add setting to enable playground
2 files changed, 19 insertions(+), 0 deletions(-)

M config/config.go
M server.go
M config/config.go => config/config.go +14 -0
@@ 11,6 11,7 @@ type Config struct {
	HTTPAddress        string
	DBConnectionString string
	LogLevel           string
	EnablePlayground   bool
	Admins             []string
	Maps               []string
}


@@ 25,6 26,7 @@ func ReadConfig(path string) (*Config, error) {
	// Set default values
	config.HTTPAddress = "127.0.0.1:8080"
	config.LogLevel = "info"
	config.EnablePlayground = false

	d := cfg.Get("http-address")
	if d != nil {


@@ 48,6 50,18 @@ func ReadConfig(path string) (*Config, error) {
		}
	}

	d = cfg.Get("enable-playground")
	if d != nil {
		var enablePlayground string
		if err := d.ParseParams(&enablePlayground); err != nil {
			return nil, err
		}

		if enablePlayground == "true" {
			config.EnablePlayground = true
		}
	}

	d = cfg.Get("admins")
	if d != nil {
		var admins string

M server.go => server.go +5 -0
@@ 13,6 13,7 @@ import (
	"git.xenrox.net/~xenrox/10man-api/graph/generated"
	"git.xenrox.net/~xenrox/go-log"
	"github.com/99designs/gqlgen/graphql/handler"
	"github.com/99designs/gqlgen/graphql/playground"
)

func main() {


@@ 47,6 48,10 @@ func main() {
		},
	}))

	if cfg.EnablePlayground {
		http.Handle("/", playground.Handler("GraphQL playground", "/query"))
		logger.Infof("connect to http://%s/ for GraphQL playground", cfg.HTTPAddress)
	}
	http.Handle("/query", srv)

	go func() {