~nromdotcom/gemif

ref: 4537a2f30ac534f927315780f6176cd14ba1cbe4 gemif/pkg/gemserver/router.go -rw-r--r-- 1014 bytes
4537a2f3Norm MacLennan Update story 1 year, 1 month 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
package gemserver

import (
	"fmt"
	"os"

	"git.sr.ht/~nromdotcom/gemif/pkg/gamemanager"
	"git.sr.ht/~nromdotcom/gemif/pkg/scenerenderer"
	"github.com/markbates/pkger"
	"github.com/pitr/gig"
)

// StartRouter starts the gig server for handling Gemini requests.
func StartRouter(gm *gamemanager.GameManager, gc ServerConfig) {
	//https://github.com/golangci/golangci-lint/issues/741
	//nolint:staticcheck
	pkger.Include("/static")

	tmpl, err := compileTemplates()
	if err != nil {
		fmt.Printf("Couldn't compile templates: %s", err)
		os.Exit(1)
	}

	sceneRenderer := scenerenderer.New()

	g := gig.Default()
	g.HideBanner = true
	g.Renderer = &Template{
		templates: tmpl,
	}

	g.Handle("/", handleHome(gm, gc.Version))
	g.Handle("/game/:statetoken", handleGame(gm, sceneRenderer))
	g.Handle("/story/:storyid", handleStory(gm))
	g.Handle("/docs*", handleStatic)
	g.Handle("/robots.txt", handleRobots)
	g.Handle("/favicon.txt", handleFavicon)

	panic(g.Run(fmt.Sprintf(":%d", gc.Port), gc.CertFile, gc.KeyFile))
}