Initial
This commit is contained in:
50
config/config.go
Normal file
50
config/config.go
Normal 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])
|
||||
}
|
||||
Reference in New Issue
Block a user