๐พ Archived View for source.community โบ Fuwn โบ space โบ blob โบ main โบ space.go captured on 2023-07-10 at 13:33:11. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2023-01-29)
โก๏ธ Next capture (2024-02-05)
-=-=-=-=-=-=-
. ,-. ,-. . . ,-. ,-. ,-. ,-. ,-. ,-,-. ,-,-. . . ,-. . |- . . `-. | | | | | | |-' | | | | | | | | | | | | | | | | | `-' `-' `-^ ' `-' `-' :: `-' `-' ' ' ' ' ' ' `-^ ' ' ' `' `-| /| `-'
git clone https://source.community/Fuwn/space.git
View raw contents of /space.go (main)
โโโโโฎ 1โ // Copyright (C) 2021-2021 Fuwn 2โ // SPDX-License-Identifier: GPL-3.0-only 3โ 4โ package main 5โ 6โ import ( 7โ "embed" 8โ "io/fs" 9โ "log" 10โ "strings" 11โ "text/template" 12โ 13โ "github.com/fuwn/space/pkg/utilities" 14โ "github.com/pitr/gig" 15โ "github.com/spf13/viper" 16โ ) 17โ 18โ //go:embed content 19โ var contentFilesystem embed.FS 20โ 21โ var g = gig.Default() 22โ 23โ var hitsTracker = make(map[string]int) 24โ 25โ // var startTime = time.Now() 26โ 27โ // Initialize templates 28โ func init() { 29โ templates, _ := fs.Sub(contentFilesystem, "content/templates") 30โ g.Renderer = &Template{template.Must(template.New("").ParseFS(templates, "*.gmi"))} 31โ } 32โ 33โ // Initialize configuration system 34โ func init() { 35โ viper.SetConfigName("config.yml") 36โ viper.SetConfigType("yaml") 37โ viper.AddConfigPath(".space/") 38โ viper.AddConfigPath(".space-data/") 39โ viper.AddConfigPath("/app/.space/") 40โ 41โ if err := viper.ReadInConfig(); err != nil { 42โ if _, ok := err.(viper.ConfigFileNotFoundError); ok { 43โ log.Panicln("Cannot read configuration file:", err) 44โ } else { 45โ log.Panicln("Read configuration file but an error occurred anyway:", err) 46โ } 47โ } 48โ 49โ viper.WatchConfig() 50โ } 51โ 52โ func main() { 53โ // Route handler 54โ handle() 55โ 56โ // Certificate check 57โ nonExistent := utilities.DoesFilesExist([]string{ 58โ ".space/.certificates/space.crt", 59โ ".space/.certificates/space.key", 60โ }) 61โ if len(nonExistent) != 0 { 62โ panic("The following files crucial to execution DO NOT exist: " + strings.Join(nonExistent, ", ")) 63โ } 64โ 65โ // Start 66โ g.Run( 67โ ":"+viper.GetString("space.port"), 68โ ".space/.certificates/space.crt", 69โ ".space/.certificates/space.key", 70โ ) 71โ } โโโโโฏ
ยท ยท ยท
ยฉ 2023 source.community