summary refs log tree commit diff stats
path: root/init.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-04 22:56:28 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-05 00:12:49 -0400
commit69217dd27196dd59c96bc405afe4bfd83ad17c00 (patch)
tree60183e14dd807bec5865610c1a58d4e432ed8221 /init.go
parentdb1dc5d8c2d1557b085b63cb8c511f5a9864b38e (diff)
downloadgetwtxt-69217dd27196dd59c96bc405afe4bfd83ad17c00.tar.gz
cli flags for db path/type, assets dir. systemd unit file. makefile.
Diffstat (limited to 'init.go')
-rw-r--r--init.go33
1 files changed, 28 insertions, 5 deletions
diff --git a/init.go b/init.go
index 076a7ca..18a3d96 100644
--- a/init.go
+++ b/init.go
@@ -25,6 +25,9 @@ var (
 	flagHelp     *bool   = pflag.BoolP("help", "h", false, "Display the quick-help screen.")
 	flagMan      *bool   = pflag.BoolP("manual", "m", false, "Display the configuration manual.")
 	flagConfFile *string = pflag.StringP("config", "c", "", "The name/path of the configuration file you wish to use.")
+	flagAssets   *string = pflag.StringP("assets", "a", "", "The location of the getwtxt assets directory")
+	flagDBPath   *string = pflag.StringP("db", "d", "", "Path to the getwtxt database")
+	flagDBType   *string = pflag.StringP("dbtype", "t", "", "Type of database being used")
 )
 
 var confObj = &Configuration{}
@@ -54,7 +57,7 @@ var staticCache = &struct {
 	cssMod:   time.Time{},
 }
 
-func initGetwtxt() {
+func init() {
 	checkFlags()
 	titleScreen()
 	initConfig()
@@ -122,6 +125,7 @@ func initConfig() {
 	viper.SetDefault("ListenPort", 9001)
 	viper.SetDefault("LogFile", "getwtxt.log")
 	viper.SetDefault("DatabasePath", "getwtxt.db")
+	viper.SetDefault("DatabaseType", "leveldb")
 	viper.SetDefault("StdoutLogging", false)
 	viper.SetDefault("ReCacheInterval", "1h")
 	viper.SetDefault("DatabasePushInterval", "5m")
@@ -137,9 +141,24 @@ func initConfig() {
 	confObj.Port = viper.GetInt("ListenPort")
 	confObj.LogFile = viper.GetString("LogFile")
 
-	confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
-	confObj.DBPath = viper.GetString("DatabasePath")
-	log.Printf("Using database: %v\n", confObj.DBPath)
+	if *flagDBType == "" {
+		confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
+	} else {
+		confObj.DBType = *flagDBType
+	}
+
+	if *flagDBPath == "" {
+		confObj.DBPath = viper.GetString("DatabasePath")
+	} else {
+		confObj.DBPath = *flagDBPath
+	}
+	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
+
+	if *flagAssets == "" {
+		confObj.AssetsDir = "assets"
+	} else {
+		confObj.AssetsDir = *flagAssets
+	}
 
 	confObj.StdoutLogging = viper.GetBool("StdoutLogging")
 	if confObj.StdoutLogging {
@@ -233,7 +252,11 @@ func rebindConfig() {
 }
 
 func initTemplates() *template.Template {
-	return template.Must(template.ParseFiles("assets/tmpl/index.html"))
+	confObj.Mu.RLock()
+	assetsDir := confObj.AssetsDir
+	confObj.Mu.RUnlock()
+
+	return template.Must(template.ParseFiles(assetsDir + "/tmpl/index.html"))
 }
 
 // Pull DB data into cache, if available.
890411d6fe52c1f442f4433e0d01'>30b5f112 ^
2f82f50a ^
86c1c388 ^
1a3dc91e ^
45a26b11 ^

30b5f112 ^
fbc30231 ^

















cd2458c0 ^

0ae975c2 ^

b21edfaa ^
cd2458c0 ^
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79


                

                       










                          
                    
                    



                      

                         
               
                          








                            





             
               

             


              
              
                      
                           
                      
                           

          
                       

















                                

                           

                            
                          
                
[colours]
bkgnd=default
titlebar=magenta
titlebar.text=white
titlebar.brackets=white
titlebar.unencrypted=black
titlebar.encrypted=cyan
titlebar.untrusted=yellow
titlebar.trusted=cyan
titlebar.online=white
titlebar.offline=black
titlebar.away=white
titlebar.chat=white
titlebar.dnd=black
titlebar.xa=white
statusbar=default
statusbar.text=white
statusbar.time=white
statusbar.brackets=red
statusbar.active=cyan
statusbar.new=white
main.text=blue
main.text.me=white
main.text.them=bold_white
main.splash=red
main.help.header=bold_blue
main.time=green
input.text=yellow
subscribed=bold_magenta
unsubscribed=bold_black
otr.started.trusted=cyan
otr.started.untrusted=yellow
otr.ended=blue
otr.trusted=cyan
otr.untrusted=yellow
online=red
away=cyan
chat=green
dnd=megenta
xa=cyan
offline=green
incoming=yellow
mention=green
trigger=green
typing=magenta
gone=yellow
error=red
roominfo=white
roommention=bold_green
roommention.term=bold_green
roomtrigger=bold_green
roomtrigger.term=bold_green
me=white
them=white
roster.header=bold_cyan
roster.chat=green
roster.online=red
roster.away=cyan
roster.xa=cyan
roster.dnd=magenta
roster.offline=green
roster.chat.active=green
roster.online.active=red
roster.away.active=cyan
roster.xa.active=cyan
roster.dnd.active=magenta
roster.offline.active=green
roster.chat.unread=bold_green
roster.online.unread=bold_red
roster.away.unread=bold_cyan
roster.xa.unread=bold_cyan
roster.dnd.unread=bold_magenta
roster.offline.unread=bold_green
roster.room=red
roster.room.unread=bold_red
roster.room.mention=bold_red
roster.room.trigger=bold_red
occupants.header=bold_cyan
receipt.sent=red