diff options
| author | Fuwn <[email protected]> | 2021-07-14 21:46:15 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-14 21:46:15 +0000 |
| commit | 80c553eb058fab6083d575559267fa4d8472727a (patch) | |
| tree | 569d92a85ea0b608bb6634ac1c31fc1c3c5b85a7 /space.go | |
| download | space-80c553eb058fab6083d575559267fa4d8472727a.tar.xz space-80c553eb058fab6083d575559267fa4d8472727a.zip | |
feat(space): :gemini:
Diffstat (limited to 'space.go')
| -rw-r--r-- | space.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/space.go b/space.go new file mode 100644 index 0000000..976ae7c --- /dev/null +++ b/space.go @@ -0,0 +1,69 @@ +// Copyright (C) 2021-2021 Fuwn +// SPDX-License-Identifier: GPL-3.0-only + +package main + +import ( + "embed" + "io/fs" + "log" + "strings" + "text/template" + + "github.com/fuwn/space/pkg/utilities" + "github.com/pitr/gig" + "github.com/spf13/viper" +) + +//go:embed content +var contentFilesystem embed.FS + +var g = gig.Default() + +var hitsTracker = make(map[string]int) + +// Initialize templates +func init() { + templates, _ := fs.Sub(contentFilesystem, "content/templates") + g.Renderer = &Template{template.Must(template.New("").ParseFS(templates, "*.gmi"))} +} + +// Initialize configuration system +func init() { + viper.SetConfigName("config.yml") + viper.SetConfigType("yaml") + viper.AddConfigPath(".space/") + viper.AddConfigPath(".space-data/") + viper.AddConfigPath("/app/.space/") + + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + log.Panicln("Cannot read configuration file:", err) + } else { + log.Panicln("Read configuration file but an error occurred anyway:", err) + } + } + + viper.WatchConfig() +} + +func main() { + // Route handler + handle() + + // Certificate check + nonExistant := utilities.DoesFilesExist([]string{ + ".space/.certificates/space.crt", + ".space/.certificates/space.key", + }) + if len(nonExistant) != 0 { + panic("The following files crucial to execution DO NOT exist: " + strings.Join(nonExistant, ", ")) + } + + // Start + g.Run( + ":"+viper.GetString("space.port"), + ".space/.certificates/space.crt", + ".space/.certificates/space.key", + ) +} |