Browse Source

change env parameter

Andreas Peters 1 year ago
parent
commit
fb662cdf2d
2 changed files with 15 additions and 32 deletions
  1. 14
    31
      app.go
  2. 1
    1
      init.go

+ 14
- 31
app.go View File

@@ -156,22 +156,22 @@ func loadDatabase(databaseType, databaseURL, configYAML string) (*database.Servi
156 156
 	return db, err
157 157
 }
158 158
 
159
-func setup(e envVars, mux *http.ServeMux, matrixClient *http.Client) {
160
-	err := types.BaseURL(e.BaseURL)
159
+func setup(mux *http.ServeMux, matrixClient *http.Client) {
160
+	err := types.BaseURL(BaseURL)
161 161
 	if err != nil {
162 162
 		log.WithError(err).Panic("Failed to get base url")
163 163
 	}
164 164
 
165
-	db, err := loadDatabase(e.DatabaseType, e.DatabaseURL, e.ConfigFile)
165
+	db, err := loadDatabase(DatabaseType, DatabaseURL, ConfigFile)
166 166
 	if err != nil {
167 167
 		log.WithError(err).Panic("Failed to open database")
168 168
 	}
169 169
 
170 170
 	// Populate the database from the config file if one was supplied.
171 171
 	var cfg *api.ConfigFile
172
-	if e.ConfigFile != "" {
173
-		if cfg, err = loadFromConfig(db, e.ConfigFile); err != nil {
174
-			log.WithError(err).WithField("config_file", e.ConfigFile).Panic("Failed to load config file")
172
+	if ConfigFile != "" {
173
+		if cfg, err = loadFromConfig(db, ConfigFile); err != nil {
174
+			log.WithError(err).WithField("config_file", ConfigFile).Panic("Failed to load config file")
175 175
 		}
176 176
 		if err := db.InsertFromConfig(cfg); err != nil {
177 177
 			log.WithError(err).Panic("Failed to persist config data into in-memory DB")
@@ -196,7 +196,7 @@ func setup(e envVars, mux *http.ServeMux, matrixClient *http.Client) {
196 196
 
197 197
 	// Read exclusively from the config file if one was supplied.
198 198
 	// Otherwise, add HTTP listeners for new Services/Sessions/Clients/etc.
199
-	if e.ConfigFile != "" {
199
+	if ConfigFile != "" {
200 200
 		if err := insertServicesFromConfig(clients, cfg.Services); err != nil {
201 201
 			log.WithError(err).Panic("Failed to insert services")
202 202
 		}
@@ -217,30 +217,13 @@ func setup(e envVars, mux *http.ServeMux, matrixClient *http.Client) {
217 217
 	}
218 218
 }
219 219
 
220
-type envVars struct {
221
-	BindAddress  string
222
-	DatabaseType string
223
-	DatabaseURL  string
224
-	BaseURL      string
225
-	LogDir       string
226
-	ConfigFile   string
227
-}
228
-
229 220
 func main() {
230
-	e := envVars{
231
-		BindAddress:  BindAddress,
232
-		DatabaseType: DatabaseType,
233
-		DatabaseURL:  DatabaseURL,
234
-		BaseURL:      BaseURL,
235
-		LogDir:       LogDir,
236
-		ConfigFile:   ConfigFile,
237
-	}
238 221
 
239
-	if e.LogDir != "" {
222
+	if LogDir != "" {
240 223
 		log.AddHook(dugong.NewFSHook(
241
-			filepath.Join(e.LogDir, "info.log"),
242
-			filepath.Join(e.LogDir, "warn.log"),
243
-			filepath.Join(e.LogDir, "error.log"),
224
+			filepath.Join(LogDir, "info.log"),
225
+			filepath.Join(LogDir, "warn.log"),
226
+			filepath.Join(LogDir, "error.log"),
244 227
 			&log.TextFormatter{
245 228
 				TimestampFormat:  "2006-01-02 15:04:05.000000",
246 229
 				DisableColors:    true,
@@ -250,8 +233,8 @@ func main() {
250 233
 		))
251 234
 	}
252 235
 
253
-	log.Infof("GO-AVBOT (%+v)", e)
236
+	log.Infof("GO-AVBOT (%s %s %s %s %s %s)", BindAddress, BaseURL, DatabaseType, DatabaseURL, LogDir, ConfigFile)
254 237
 
255
-	setup(e, http.DefaultServeMux, http.DefaultClient)
256
-	log.Fatal(http.ListenAndServe(e.BindAddress, nil))
238
+	setup(http.DefaultServeMux, http.DefaultClient)
239
+	log.Fatal(http.ListenAndServe(BindAddress, nil))
257 240
 }

+ 1
- 1
init.go View File

@@ -5,7 +5,7 @@ import (
5 5
 )
6 6
 
7 7
 func init() {
8
-	flag.StringVar(&BindAddress, "server", "127.0.0.1:4050", "bot server port")
8
+	flag.StringVar(&BindAddress, "server", "0.0.0.0:4050", "bot server port")
9 9
 	flag.StringVar(&DatabaseType, "datastore", "sqlite3", "database type")
10 10
 	flag.StringVar(&DatabaseURL, "datastoreurl", "go-neb.db?_busy_timeout=5000", "database url")
11 11
 	flag.StringVar(&BaseURL, "baseurl", "http://localhost:4050", "base url")

Loading…
Cancel
Save