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.
# Features
* Multi-site hosting (WIP)
* Multi-site hosting
* CGI (WIP)
* Fully compliant with Jetforce diagnostics
* Probably won't kill your computer

17
main.go
View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"sync"
"github.com/spf13/viper"
)
@ -19,15 +20,29 @@ func main() {
//Load config
active_capsules := viper.GetStringSlice("active_capsules")
capsule_list := make([]Config, len(active_capsules))
for i, c := range active_capsules {
viper.UnmarshalKey(c, &(capsule_list[i]))
log.Printf("Loading capsule %v %v", i, capsule_list[i].Hostname)
}
if len(capsule_list) < 1 {
log.Println("No capsules defined. Shutting down.")
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 {

View File

@ -201,6 +201,8 @@ func generateDirectory(path string) Response {
log.Println(err)
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"
for _, file := range files {
// Skip dotfiles