Procházet zdrojové kódy

Specify config file

Min před 8 roky
rodič
revize
21029feb2f
2 změnil soubory, kde provedl 18 přidání a 11 odebrání
  1. 12 6
      main.go
  2. 6 5
      readme.md

+ 12 - 6
main.go

@@ -24,15 +24,15 @@ func main() {
 		}
 	}()
 	var err error
+	configFile := "config.json"
 
-	// Processing template
-	tmpl, err = template.New("index").Parse(index)
-	if err != nil {
-		panic(err)
+	// Reading configuration
+	if len(os.Args) >= 2 {
+		configFile = os.Args[1]
 	}
 
-	// Reading configuration
-	logFile, err := ioutil.ReadFile("config.json")
+	log.Println("Reading config", configFile)
+	logFile, err := ioutil.ReadFile(configFile)
 	if err != nil {
 		panic(err)
 	}
@@ -41,6 +41,12 @@ func main() {
 		panic(err)
 	}
 
+	// Processing template
+	tmpl, err = template.New("index").Parse(index)
+	if err != nil {
+		panic(err)
+	}
+
 	// Serving HTTP
 	http.HandleFunc("/", router)
 

+ 6 - 5
readme.md

@@ -4,12 +4,13 @@ Program that serves compressed files over http.
 ***
 ## Configuration
 
-Configuration file (config.json) must be located in the same place as executable.
-
-TODO: allow change conifg location via command line arguments.
-
+Default configuration file is ./config.json.
+Config file can be specified with argument:
+``` bash
+./logserver /path/to/config_file.json
+```
 
-Options:
+Config.json options:
 
 **address** - IP serving address:port.