60 lines
1.2 KiB
Go
Executable File
60 lines
1.2 KiB
Go
Executable File
package config
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"local/args"
|
|
"log"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
Root string
|
|
Port string
|
|
Head string
|
|
Foot string
|
|
OAuthServer string
|
|
VersionInterval time.Duration
|
|
)
|
|
|
|
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", "49909")
|
|
as.Append(args.STRING, "wrap", "file with http header/footer", "./wrapper.html")
|
|
as.Append(args.STRING, "oauth", "oauth URL", "")
|
|
as.Append(args.DURATION, "version", "duration to mark versions", "0s")
|
|
if err := as.Parse(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
wrap := as.Get("wrap").GetString()
|
|
log.Printf("reading %v (%T)", wrap, wrap)
|
|
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").GetString()
|
|
Port = ":" + strings.TrimPrefix(as.Get("port").GetString(), ":")
|
|
Head = string(bs[0])
|
|
Foot = string(bs[1])
|
|
OAuthServer = as.Get("oauth").GetString()
|
|
VersionInterval = as.Get("version").GetDuration()
|
|
}
|