2024-03-08 15:36:11 -06:00
|
|
|
// package main is the main package for the LapisDeploy program
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"encoding/json"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Configuration stores information retrieved from a configuration file
|
|
|
|
type Configuration struct {
|
2024-03-08 15:55:13 -06:00
|
|
|
port int
|
2024-03-08 15:36:11 -06:00
|
|
|
sites_dir string
|
2024-03-10 17:21:27 -05:00
|
|
|
matrix struct {
|
|
|
|
homeserver string
|
|
|
|
username string
|
|
|
|
password string
|
|
|
|
room_id string
|
|
|
|
}
|
2024-03-08 15:36:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// parseConfig parses the JSON configuration file at 'path' and stores the contents in 'config'
|
|
|
|
func parseConfig(path string, config *Configuration) {
|
|
|
|
file, _ := os.Open(path)
|
|
|
|
var data map[string]interface{}
|
|
|
|
err := json.NewDecoder(file).Decode(&data)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic("Failed to parse config:", err)
|
|
|
|
}
|
|
|
|
file.Close()
|
2024-03-10 17:21:27 -05:00
|
|
|
// Main configuration
|
2024-03-08 15:55:13 -06:00
|
|
|
config.port = int(data["port"].(float64)) // this conversion makes no sense
|
2024-03-08 15:36:11 -06:00
|
|
|
config.sites_dir = data["sites_dir"].(string)
|
2024-03-10 17:21:27 -05:00
|
|
|
|
|
|
|
// Matrix configuration
|
|
|
|
matrix := data["matrix"].(map[string]interface{})
|
|
|
|
config.matrix.homeserver = matrix["homeserver"].(string)
|
|
|
|
config.matrix.username = matrix["username"].(string)
|
|
|
|
config.matrix.password = matrix["password"].(string)
|
|
|
|
config.matrix.room_id = matrix["room_id"].(string)
|
2024-03-08 15:36:11 -06:00
|
|
|
}
|
|
|
|
|