summaryrefslogtreecommitdiff
path: root/main.go
blob: c64f3741e95114db1b18a202f6343687ae5e7739 (plain)
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
//go:build !clientonly

package main

import (
	"embed"
	"fmt"
	"io/fs"
	"log"

	"code.crute.us/mcrute/ssh-proxy/app"
	"code.crute.us/mcrute/ssh-proxy/cmd/client"
	"code.crute.us/mcrute/ssh-proxy/cmd/register"
	"code.crute.us/mcrute/ssh-proxy/cmd/web"

	"code.crute.us/mcrute/golib/cli"

	"github.com/spf13/cobra"

	// Import backup data. By default zoneinfo is installed in the docker image
	// if something breaks this will still result in us having correct TZ info.
	_ "time/tzdata"
)

//go:embed templates
var embeddedTemplates embed.FS

//go:embed clients
var embeddedClients embed.FS

var appVersion string

func main() {
	rootCmd := &cobra.Command{
		Use:   "web-server",
		Short: fmt.Sprintf("SSH proxy web server (version %s)", appVersion),
	}
	cli.AddFlags(rootCmd, &app.Config{}, app.DefaultConfig, "")

	templates, err := fs.Sub(embeddedTemplates, "templates")
	if err != nil {
		log.Fatalf("Error building sub-fs of embeded fs")
	}

	web.Register(rootCmd, templates, embeddedClients, appVersion)
	client.Register(rootCmd, appVersion)
	register.Register(rootCmd)

	if err := rootCmd.Execute(); err != nil {
		log.Fatalf("Error running root command: %s", err)
	}
}