summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/config.go33
-rw-r--r--config/config.json4
-rw-r--r--server.go7
3 files changed, 43 insertions, 1 deletions
diff --git a/config/config.go b/config/config.go
new file mode 100644
index 0000000..b46b0e1
--- /dev/null
+++ b/config/config.go
@@ -0,0 +1,33 @@
+package config
+
+import (
+ "encoding/json"
+ "io/ioutil"
+ "os"
+)
+
+type config struct {
+ Hostnames []string `json:"host"`
+ Port int `json:"port"`
+ AllowLocalPath bool `json:"allow-local-path"`
+ Auth bool `json:"auth"`
+ RootPath string `json:"root-path"`
+}
+
+var Config config
+
+func ReadConfig() error {
+ file, err := os.Open("config.json")
+
+ if err != nil {
+ return err
+ } else {
+ defer file.Close()
+ }
+
+ content, _ := ioutil.ReadAll(file)
+
+ json.Unmarshal(content, &Config)
+
+ return nil
+}
diff --git a/config/config.json b/config/config.json
new file mode 100644
index 0000000..2bd396d
--- /dev/null
+++ b/config/config.json
@@ -0,0 +1,4 @@
+{
+ "host":["localhost"],
+ "port": 8080
+}
diff --git a/server.go b/server.go
index 3b5c732..ad32199 100644
--- a/server.go
+++ b/server.go
@@ -10,6 +10,7 @@ import (
"flag"
"path"
"syscall"
+ "./config"
)
var tmpl *template.Template
@@ -115,7 +116,7 @@ func handleGet( w http.ResponseWriter, r *http.Request, headOnly bool) {
ListCols []Entry
ListFiles []Entry
}
- tmpl.Execute(w, Collection{ "Title" , cols, files})
+ tmpl.Execute(w, Collection{ filename, cols, files})
case stat.Mode().IsRegular():
if !headOnly {
@@ -324,6 +325,8 @@ func main() {
helpString := `This is the help`
versionString := "0.0.0"
+ config.ReadConfig()
+
const (
defaultDir = "."
usageDir = "the directory to serve"
@@ -339,6 +342,8 @@ func main() {
flag.Parse()
+ fmt.Println(config.Config.Port)
+
if dir == "" {
dir = defaultDir
}