aboutsummaryrefslogtreecommitdiff
path: root/space.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-14 21:46:15 +0000
committerFuwn <[email protected]>2021-07-14 21:46:15 +0000
commit80c553eb058fab6083d575559267fa4d8472727a (patch)
tree569d92a85ea0b608bb6634ac1c31fc1c3c5b85a7 /space.go
downloadspace-80c553eb058fab6083d575559267fa4d8472727a.tar.xz
space-80c553eb058fab6083d575559267fa4d8472727a.zip
feat(space): :gemini:
Diffstat (limited to 'space.go')
-rw-r--r--space.go69
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",
+ )
+}