Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 97594b4

Browse files
committed
api, common, db4s, live, webui: Trivial code cleanup
Just improves the code quality of some of our startup code
1 parent 4e12907 commit 97594b4

File tree

8 files changed

+39
-42
lines changed

8 files changed

+39
-42
lines changed

api/main.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func main() {
4343
// Read server configuration
4444
var err error
4545
if err = com.ReadConfig(); err != nil {
46-
log.Fatalf("Configuration file problem\n\n%v", err)
46+
log.Fatalf("Configuration file problem: '%s'", err)
4747
}
4848

4949
// Open the request log for writing
@@ -61,13 +61,13 @@ func main() {
6161
// Connect to Minio server
6262
err = com.ConnectMinio()
6363
if err != nil {
64-
log.Fatalf(err.Error())
64+
log.Fatal(err)
6565
}
6666

6767
// Connect to PostgreSQL server
6868
err = com.ConnectPostgreSQL()
6969
if err != nil {
70-
log.Fatalf(err.Error())
70+
log.Fatal(err)
7171
}
7272

7373
// Connect to MQ server
@@ -80,32 +80,30 @@ func main() {
8080
// Connect to the Memcached server
8181
err = com.ConnectCache()
8282
if err != nil {
83-
log.Fatalf(err.Error())
83+
log.Fatal(err)
8484
}
8585

8686
// Add the default user to the system
8787
err = com.AddDefaultUser()
8888
if err != nil {
89-
log.Fatalf(err.Error())
89+
log.Fatal(err)
9090
}
9191

9292
// Add the default licences to the system
9393
err = com.AddDefaultLicences()
9494
if err != nil {
95-
log.Fatalf(err.Error())
95+
log.Fatal(err)
9696
}
9797

9898
// Load our self signed CA chain
9999
ourCAPool = x509.NewCertPool()
100100
certFile, err := os.ReadFile(com.Conf.DB4S.CAChain)
101101
if err != nil {
102-
log.Printf("Error opening Certificate Authority chain file: %v", err)
103-
return
102+
log.Fatalf("Error opening Certificate Authority chain file: '%s'", err)
104103
}
105104
ok := ourCAPool.AppendCertsFromPEM(certFile)
106105
if !ok {
107-
log.Println("Error appending certificate file")
108-
return
106+
log.Fatal("Error appending certificate file")
109107
}
110108

111109
// Our pages

common/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ func ReadConfig() error {
3131
// world readable. Similar in concept to what ssh does for its config files.
3232
userHome, err := homedir.Dir()
3333
if err != nil {
34-
log.Fatalf("User home directory couldn't be determined: %s", "\n")
34+
log.Printf("User home directory couldn't be determined: '%s'", err)
35+
return err
3536
}
3637
configFile = filepath.Join(userHome, ".dbhub", "config.toml")
3738
}
3839

3940
// Reads the server configuration from disk
4041
if _, err := toml.DecodeFile(configFile, &Conf); err != nil {
41-
return fmt.Errorf("Config file couldn't be parsed: %v\n", err)
42+
return fmt.Errorf("Config file couldn't be parsed: %s", err)
4243
}
4344

4445
// Override config file via environment variables
@@ -58,7 +59,7 @@ func ReadConfig() error {
5859
if tempString != "" {
5960
Conf.Minio.HTTPS, err = strconv.ParseBool(tempString)
6061
if err != nil {
61-
return fmt.Errorf("Failed to parse MINIO_HTTPS: %v\n", err)
62+
return fmt.Errorf("Failed to parse MINIO_HTTPS: %s", err)
6263
}
6364
}
6465
tempString = os.Getenv("PG_SERVER")
@@ -69,7 +70,7 @@ func ReadConfig() error {
6970
if tempString != "" {
7071
tempInt, err := strconv.ParseInt(tempString, 10, 0)
7172
if err != nil {
72-
return fmt.Errorf("Failed to parse PG_PORT: %v\n", err)
73+
return fmt.Errorf("Failed to parse PG_PORT: %s", err)
7374
}
7475
Conf.Pg.Port = int(tempInt)
7576
}

common/postgresql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,13 +3208,13 @@ func ResetDB() error {
32083208
// Add the default user to the system
32093209
err = AddDefaultUser()
32103210
if err != nil {
3211-
log.Fatalf(err.Error())
3211+
log.Fatal(err)
32123212
}
32133213

32143214
// Add the default licences
32153215
err = AddDefaultLicences()
32163216
if err != nil {
3217-
log.Fatalf(err.Error())
3217+
log.Fatal(err)
32183218
}
32193219

32203220
// Commit the transaction

common/sqlite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ var SQLiteFunctions = []function{
332332
func init() {
333333
// Enable the collection of memory allocation statistics
334334
if err := sqlite.ConfigMemStatus(true); err != nil {
335-
log.Fatalf("Cannot enable memory allocation statistics: '%s'\n", err)
335+
log.Fatalf("Cannot enable memory allocation statistics: '%s'", err)
336336
}
337337
}
338338

db4s/main.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,56 +35,54 @@ func main() {
3535
// Read server configuration
3636
var err error
3737
if err = com.ReadConfig(); err != nil {
38-
log.Fatalf("Configuration file problem\n\n%v", err)
38+
log.Fatalf("Configuration file problem: '%s'", err)
3939
}
4040

4141
// Set the temp dir environment variable
4242
err = os.Setenv("TMPDIR", com.Conf.DiskCache.Directory)
4343
if err != nil {
44-
log.Fatalf("Setting temp directory environment variable failed: '%s'\n", err.Error())
44+
log.Fatalf("Setting temp directory environment variable failed: '%s'", err)
4545
}
4646

4747
// Connect to Minio server
4848
err = com.ConnectMinio()
4949
if err != nil {
50-
log.Fatalf(err.Error())
50+
log.Fatal(err)
5151
}
5252

5353
// Connect to PostgreSQL server
5454
err = com.ConnectPostgreSQL()
5555
if err != nil {
56-
log.Fatalf(err.Error())
56+
log.Fatal(err)
5757
}
5858

5959
// Connect to the Memcached server
6060
err = com.ConnectCache()
6161
if err != nil {
62-
log.Fatalf(err.Error())
62+
log.Fatal(err)
6363
}
6464

6565
// Add the default user to the system
6666
err = com.AddDefaultUser()
6767
if err != nil {
68-
log.Fatalf(err.Error())
68+
log.Fatal(err)
6969
}
7070

7171
// Add the default licences to PostgreSQL
7272
err = com.AddDefaultLicences()
7373
if err != nil {
74-
log.Fatalf(err.Error())
74+
log.Fatal(err)
7575
}
7676

7777
// Load our self signed CA chain
7878
ourCAPool = x509.NewCertPool()
7979
certFile, err := os.ReadFile(com.Conf.DB4S.CAChain)
8080
if err != nil {
81-
fmt.Printf("Error opening Certificate Authority chain file: %v\n", err)
82-
return
81+
log.Fatalf("Error opening Certificate Authority chain file: '%s'", err)
8382
}
8483
ok := ourCAPool.AppendCertsFromPEM(certFile)
8584
if !ok {
86-
fmt.Println("Error appending certificate file")
87-
return
85+
log.Fatal("Error appending certificate file")
8886
}
8987

9088
// URL handler

live/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
// Read server configuration
2424
err := com.ReadConfig()
2525
if err != nil {
26-
log.Fatalf("Configuration file problem\n\n%v", err)
26+
log.Fatalf("Configuration file problem: '%s'", err)
2727
}
2828

2929
// If node name and base directory were provided on the command line, then override the config file values

webui/execute.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313

1414
func executePage(w http.ResponseWriter, r *http.Request) {
1515
var pageData struct {
16-
DB com.SQLiteDBinfo
17-
PageMeta PageMetaInfo
18-
SqlHistory []com.SqlHistoryItem
16+
DB com.SQLiteDBinfo
17+
PageMeta PageMetaInfo
18+
SqlHistory []com.SqlHistoryItem
1919
}
2020

2121
// Get all meta information
@@ -116,7 +116,7 @@ func execClearHistory(w http.ResponseWriter, r *http.Request) {
116116
}
117117

118118
// Delete items
119-
err = com.LiveSqlHistoryDeleteOld(loggedInUser, dbOwner, dbName, 0) // 0 means "keep 0 items"
119+
err = com.LiveSqlHistoryDeleteOld(loggedInUser, dbOwner, dbName, 0) // 0 means "keep 0 items"
120120
if err != nil {
121121
w.WriteHeader(http.StatusInternalServerError)
122122
fmt.Fprint(w, err)

webui/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,24 +3104,24 @@ func main() {
31043104
// Read server configuration
31053105
var err error
31063106
if err = com.ReadConfig(); err != nil {
3107-
log.Fatalf("Configuration file problem\n\n%v", err)
3107+
log.Fatalf("Configuration file problem: '%s'", err)
31083108
}
31093109

31103110
// Set the temp dir environment variable
31113111
err = os.Setenv("TMPDIR", com.Conf.DiskCache.Directory)
31123112
if err != nil {
3113-
log.Fatalf("Setting temp directory environment variable failed: '%s'\n", err.Error())
3113+
log.Fatalf("Setting temp directory environment variable failed: '%s'", err)
31143114
}
31153115

31163116
// Ensure the SQLite library is recent enough
31173117
if com.SQLiteVersionNumber() < 3031000 {
3118-
log.Fatalf("Aborting. SQLite version is too old: %v, needs to be at least SQLite 3.31.0.\n ", sqlite.Version())
3118+
log.Fatalf("Aborting. SQLite version is too old: %s, needs to be at least SQLite 3.31.0.", sqlite.Version())
31193119
}
31203120

31213121
// Open the request log for writing
31223122
reqLog, err = os.OpenFile(com.Conf.Web.RequestLog, os.O_CREATE|os.O_APPEND|os.O_WRONLY|os.O_SYNC, 0750)
31233123
if err != nil {
3124-
log.Fatalf("Error when opening request log: %s\n", err)
3124+
log.Fatalf("Error when opening request log: %s", err)
31253125
}
31263126
defer reqLog.Close()
31273127
log.Printf("Request log opened: %s", com.Conf.Web.RequestLog)
@@ -3133,25 +3133,25 @@ func main() {
31333133
// Connect to Minio server
31343134
err = com.ConnectMinio()
31353135
if err != nil {
3136-
log.Fatalf(err.Error())
3136+
log.Fatal(err)
31373137
}
31383138

31393139
// Connect to PostgreSQL server
31403140
err = com.ConnectPostgreSQL()
31413141
if err != nil {
3142-
log.Fatalf(err.Error())
3142+
log.Fatal(err)
31433143
}
31443144

31453145
// Add the default user to the system
31463146
err = com.AddDefaultUser()
31473147
if err != nil {
3148-
log.Fatalf(err.Error())
3148+
log.Fatal(err)
31493149
}
31503150

31513151
// Add the default licences to PostgreSQL
31523152
err = com.AddDefaultLicences()
31533153
if err != nil {
3154-
log.Fatalf(err.Error())
3154+
log.Fatal(err)
31553155
}
31563156

31573157
// Connect to MQ server
@@ -3164,7 +3164,7 @@ func main() {
31643164
// Connect to the Memcached server
31653165
err = com.ConnectCache()
31663166
if err != nil {
3167-
log.Fatalf(err.Error())
3167+
log.Fatal(err)
31683168
}
31693169

31703170
// Setup session storage

0 commit comments

Comments
 (0)