summaryrefslogtreecommitdiff
path: root/config/config.go
blob: ddf3f0ac059117a80f33e5b024012b95d27ffd94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package config

import (
  "encoding/json"
  "io/ioutil"
  "os"
)

type config struct {
  Hostnames []string  `json:"hosts"`
  Port int            `json:"port"`
  AllowHidden bool    `json:"allow-hidden"`
  Auth bool           `json:"auth"`
  RootPath string     `json:"root-path"`
}

var Config config

func ReadConfig(path string) error {
  if path == "" {
    path = "config.json"
  }
  file, err := os.Open(path)

  if err != nil {
    return err
  } else {
    defer file.Close()
  }

  content, _ := ioutil.ReadAll(file)

  json.Unmarshal(content, &Config)

  return nil
}

func SetDefaultValue() {
  Config.Hostnames = []string{"localhost"}
  Config.Port = 8080
  Config.AllowHidden = false
  Config.Auth = false
  Config.RootPath = "."
}