summaryrefslogtreecommitdiff
path: root/config/config.go
blob: 5abdaf6e3dfac6cf24cff45efc592da59dd9e3db (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
45
46
47
48
49
50
package config

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

type config struct {
  Hostnames []string  `json:"hosts"`
  Port int            `json:"port"`
  AllowHidden bool    `json:"allow-hidden"`
  HideHidden bool     `json:"hide-hidden"`
  Auth bool           `json:"auth"`
  RootPath string     `json:"root-path"`
  Cache bool          `json:"cache"`
  OnlyIPv4 bool       `json:"ipv4"`
  OnlyIPv6 bool       `json:"ipv6"`
}

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 = 0
  Config.AllowHidden = false
  Config.HideHidden = true
  Config.Auth = false
  Config.RootPath = "."
  Config.OnlyIPv6 = true
}