From fa55706a41d7ba2490478090dde1eb6dc08f87c7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 13 Nov 2010 13:09:18 -0500 Subject: [PATCH] Add functionality to read the configuration from file. --- src/config.go | 14 ++++++++++++++ src/main.go | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/config.go b/src/config.go index f16823f..8a48d78 100644 --- a/src/config.go +++ b/src/config.go @@ -9,9 +9,23 @@ package config +import ( + "json" + "os" +) + type Configuration struct { JailRoot string Port int ProxyURLs []string Users map [string] string } + +func ReadFromFile(aPath string, config *Configuration) os.Error { + fd, error := os.Open(aPath, os.O_RDONLY, 0) + if error != nil { + return error + } + decoder := json.NewDecoder(fd) + return decoder.Decode(config) +} diff --git a/src/main.go b/src/main.go index be5a1be..27b1da1 100644 --- a/src/main.go +++ b/src/main.go @@ -19,17 +19,22 @@ import ( func main() { var configPath *string = flag.String("config", "~/.armadillo", "Path to the configuration file") - var config = new(config.Configuration) - if len(*configPath) > 0 { - // Read configuration. - } flag.StringVar(&paths.JailRoot, "jail", "/", "Restrict file operations to this directory root") var port *int = flag.Int("port", 8080, "Port to run the server on") flag.Parse() - config.JailRoot = paths.JailRoot - config.Port = *port + var configuration = new(config.Configuration) + fmt.Printf("Reading configuration from %v\n", *configPath) + if len(*configPath) > 0 { + error := config.ReadFromFile(*configPath, configuration) + if error != nil { + fmt.Printf("Error while reading configuration: %v\n", error) + } + } + + configuration.JailRoot = paths.JailRoot + configuration.Port = *port fmt.Printf("Starting Armadillo on port %d with root:\n %v\n", *port, paths.JailRoot) - server.RunFrontEnd(config) + server.RunFrontEnd(configuration) } -- 2.22.5