This commit is contained in:
scratch
2019-10-19 03:52:26 +00:00
commit 019992c4c2
18 changed files with 442 additions and 0 deletions

50
config/config.go Normal file
View File

@@ -0,0 +1,50 @@
package config
import (
"bytes"
"fmt"
"io/ioutil"
"local/args"
"os"
"strings"
)
var (
Root string
Port string
Head string
Foot string
)
func init() {
Refresh()
}
func Refresh() {
if strings.Contains(fmt.Sprint(os.Args), "-test") {
return
}
as := args.NewArgSet()
as.Append(args.STRING, "root", "root dir path", "./public")
as.Append(args.STRING, "port", "port to listen on", "39909")
as.Append(args.STRING, "wrap", "file with http header/footer", "./wrapper.html")
if err := as.Parse(); err != nil {
panic(err)
}
wrap := as.Get("wrap").String()
b, err := ioutil.ReadFile(wrap)
if err != nil {
panic(err)
}
bs := bytes.Split(b, []byte("{{{}}}"))
if len(bs) != 2 {
panic(len(bs))
}
Root = as.Get("root").String()
Port = ":" + strings.TrimPrefix(as.Get("port").String(), ":")
Head = string(bs[0])
Foot = string(bs[1])
}