~nromdotcom/gemif

ref: 85dc63b9dbb0221579a7fd26c4a1feae4bd39338 gemif/cmd/gemif/main.go -rw-r--r-- 2.2 KiB
85dc63b9Norm MacLennan chore: upgrade linters and fix linting issues 9 months ago
                                                                                
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main

import (
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"os"

	"git.sr.ht/~nromdotcom/gemif/pkg/gamemanager"
	"git.sr.ht/~nromdotcom/gemif/pkg/gemserver"
	"github.com/pelletier/go-toml"
)

//nolint:gochecknoglobals
var (
	appName    = "GemIF"
	appVersion = "0.0.0"
	appCommit  = "local"
	buildTime  = "just now!"
)

func main() {
	versionFlag := flag.Bool("version", false, "Print version information and exit")
	flag.Parse()

	if *versionFlag {
		fmt.Printf("%s %s (%s) - built %s\n\n", appName, appVersion, appCommit, buildTime)
		os.Exit(0)
	}

	file, err := ioutil.ReadFile("./config.toml")
	if err != nil {
		log.Fatalf("Couldn't load config file: %s", err)
	}

	config, err := toml.Load(string(file))
	if err != nil {
		log.Fatalf("Could not parse config file: %s", err)
	}

	book, err := gamemanager.NewStoryBook(config.Get("engine.stories_dir").(string))
	if err != nil {
		log.Fatalf("Error loading stories! %s", err)
	}

	renderDesc := config.GetDefault("engine.render_descriptions", true).(bool)
	tokenFormat := config.GetDefault("engine.statetoken_format", "proto").(string)

	engineConfig, err := gamemanager.NewEngineConfig(renderDesc, tokenFormat)
	if err != nil {
		log.Fatalf("Error loading config: %s", err)
	}

	gameMgr, err := gamemanager.NewGameManager(book, engineConfig)
	if err != nil {
		log.Fatalf("Error loading game! %s", err)
	}

	gsConfig := config.Get("gemserver").(*toml.Tree)
	serverConfig := gemserver.ServerConfig{
		Domain:   gsConfig.Get("domain").(string),
		Port:     gsConfig.Get("port").(int64),
		CertFile: gsConfig.Get("cert_file").(string),
		KeyFile:  gsConfig.Get("key_file").(string),
		HomePage: gemserver.IndexConfig{
			DisplayProjectInfo: config.GetDefault("homepage.display_project_info", true).(bool),
			ContactEmail:       config.GetDefault("homepage.contact_email", "").(string),
			Title:              config.GetDefault("homepage.title", "").(string),
			DisplayPoweredBy:   config.GetDefault("homepage.display_powered_by", true).(bool),
			PageBody:           config.GetDefault("homepage.page_body", "").(string),
		},
		Version: appVersion,
	}

	fmt.Printf("Starting %s %s (%s) - built %s\n\n", appName, appVersion, appCommit, buildTime)

	gemserver.StartRouter(gameMgr, serverConfig)
}