-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (54 loc) · 2.19 KB
/
main.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
//"encoding/csv"
"flag"
"fmt"
"strings"
"github.com/fkmiec/tiddlyverse"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
const (
authTokenAnon = "(anon)"
//authTokenAuthenticated = "(authenticated)"
)
func main() {
flag.String("host", "localhost", "the hostname or IP for the server URL (need to specify to support custom paths for multiple wikis)")
flag.String("port", "8080", "the port to serve this page on")
flag.String("debug_level", "info", "specify the debug level. options are: trace, debug, info, warn, error, fatal")
flag.String("credentials_file", "", "the name of the credentials CSV in the root wiki directory")
flag.String("readers", authTokenAnon, "specify the security principals with read access to the wiki")
flag.String("writers", authTokenAnon, "specify the security principals with write access to the wiki")
viper.BindEnv("host")
viper.BindEnv("port")
viper.BindEnv("wiki_location")
viper.BindEnv("debug_level")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
if pflag.NArg() > 0 {
viper.Set("wiki_location", pflag.Arg(0))
}
if !viper.IsSet("wiki_location") {
panic("wiki location must be specified as an environment variable or as the last argument to this call")
}
var err error
// setup the logger
logLevel, err := zerolog.ParseLevel(viper.GetString("debug_level"))
if err != nil {
panic(fmt.Sprintf("debug_level '%s' not recognized: %v", viper.GetString("debug_level"), err))
}
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Logger.Level(logLevel).With().Logger()
if log.Logger.GetLevel() < zerolog.InfoLevel {
log.Logger = log.Logger.With().Caller().Logger()
}
// created a TiddlerStore
locationSplit := strings.Split(viper.GetString("wiki_location"), "://")
storageType := locationSplit[0]
storageLocation := locationSplit[1]
log.Fatal().Err(tiddlybucket.ListenAndServe(fmt.Sprintf("%s:%s", viper.GetString("host"), viper.GetString("port")), viper.GetString("credentials_file"), viper.GetString("readers"), viper.GetString("writers"), storageType, storageLocation)).
Msg("server shutdown with error")
}