add multi site

This commit is contained in:
Steve 2020-02-19 15:26:46 -05:00
parent 4c0c488325
commit 84ad9d8f4a
3 changed files with 19 additions and 2 deletions

2
README
View File

@ -1,7 +1,7 @@
SecretShop: a small Gemini server. SecretShop: a small Gemini server.
# Features # Features
* Multi-site hosting (WIP) * Multi-site hosting
* CGI (WIP) * CGI (WIP)
* Fully compliant with Jetforce diagnostics * Fully compliant with Jetforce diagnostics
* Probably won't kill your computer * Probably won't kill your computer

17
main.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"sync"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -19,15 +20,29 @@ func main() {
//Load config //Load config
active_capsules := viper.GetStringSlice("active_capsules") active_capsules := viper.GetStringSlice("active_capsules")
capsule_list := make([]Config, len(active_capsules)) capsule_list := make([]Config, len(active_capsules))
for i, c := range active_capsules { for i, c := range active_capsules {
viper.UnmarshalKey(c, &(capsule_list[i])) viper.UnmarshalKey(c, &(capsule_list[i]))
log.Printf("Loading capsule %v %v", i, capsule_list[i].Hostname)
} }
if len(capsule_list) < 1 { if len(capsule_list) < 1 {
log.Println("No capsules defined. Shutting down.") log.Println("No capsules defined. Shutting down.")
return return
} }
log.Fatal(ListenAndServeTLS(capsule_list[0])) log.Printf("%v capsules loaded", len(capsule_list))
// Intialize servers
wg := new(sync.WaitGroup)
wg.Add(len(capsule_list))
for i, c := range capsule_list {
log.Printf("Starting capsule %v %v", i, c.Hostname)
go func(c interface{}) {
log.Fatal(ListenAndServeTLS(c.(Config)))
wg.Done()
}(c)
}
wg.Wait()
//log.Fatal(ListenAndServeTLS(capsule_list[0]))
} }
type Config struct { type Config struct {

View File

@ -201,6 +201,8 @@ func generateDirectory(path string) Response {
log.Println(err) log.Println(err)
return Response{STATUS_TEMPORARY_FAILURE, "Unable to show directory listing", ""} return Response{STATUS_TEMPORARY_FAILURE, "Unable to show directory listing", ""}
} }
// Unashamedly based off solderpunks directory generation code
// https://tildegit.org/solderpunk/molly-brown/src/branch/master/handler.go
listing = "# Directory listing\r\n" listing = "# Directory listing\r\n"
for _, file := range files { for _, file := range files {
// Skip dotfiles // Skip dotfiles