Skip to content

Commit e9612d9

Browse files
Implemented omitempty to config parser for completely dynamic config loading
1 parent fc597c0 commit e9612d9

File tree

10 files changed

+34
-34
lines changed

10 files changed

+34
-34
lines changed

cmd/laclm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func exec() error {
3131

3232
err := godotenv.Load()
3333
if err != nil {
34-
fmt.Println("No .env file found, continuing with system environment variables")
34+
fmt.Println("No .env file found, continuing with system environment variables\n")
3535
}
3636

3737
/* setting up cobra for cli interactions */

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# backend environment configs
44
app:
5-
name: laclm-dev
5+
# name: laclm-dev
66
version: v1.1
77
debug_mode: true
88

config/app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package config
22

33
/* app parameters */
44
type App struct {
5-
Name string `yaml:"name"`
6-
Version string `yaml:"version"`
7-
DebugMode bool `yaml:"debug_mode"`
5+
Name string `yaml:"name,omitempty"`
6+
Version string `yaml:"version,omitempty"`
7+
DebugMode bool `yaml:"debug_mode,omitempty"`
88
}
99

1010
/* normalization function */

config/authentication.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88

99
/* authentication parameters */
1010
type Authentication struct {
11-
LDAPConfig LDAPConfig `yaml:"ldap"`
11+
LDAPConfig LDAPConfig `yaml:"ldap,omitempty"`
1212
}
1313

1414
/* ldap authentication parameters */
1515
type LDAPConfig struct {
16-
TLS bool `yaml:"tls"`
17-
Address string `yaml:"address"`
18-
AdminDN string `yaml:"admin_dn"`
19-
AdminPassword string `yaml:"admin_password"`
16+
TLS bool `yaml:"tls,omitempty"`
17+
Address string `yaml:"address,omitempty"`
18+
AdminDN string `yaml:"admin_dn,omitempty"`
19+
AdminPassword string `yaml:"admin_password,omitempty"`
2020
}
2121

2222
/* normalization function */

config/backend_security.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88

99
/* backend security configs */
1010
type BackendSecurity struct {
11-
JWTTokenSecret string `yaml:"jwt_secret_token"`
12-
JWTExpiry int `yaml:"jwt_expiry"`
11+
JWTTokenSecret string `yaml:"jwt_secret_token,omitempty"`
12+
JWTExpiry int `yaml:"jwt_expiry,omitempty"`
1313
}
1414

1515
/* normalization function */

config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ var BackendConfig Config
77

88
/* complete yaml config for global usage */
99
type Config struct {
10-
AppInfo App `yaml:"app"`
11-
Server Server `yaml:"server"`
12-
Database Database `yaml:"database"`
13-
Logging Logging `yaml:"logging"`
14-
FileSystemServers []FileSystemServers `yaml:"filesystem_servers"`
15-
BackendSecurity BackendSecurity `yaml:"backend_security"`
16-
Authentication Authentication `yaml:"authentication"`
10+
AppInfo App `yaml:"app,omitempty"`
11+
Server Server `yaml:"server,omitempty"`
12+
Database Database `yaml:"database,omitempty"`
13+
Logging Logging `yaml:"logging,omitempty"`
14+
FileSystemServers []FileSystemServers `yaml:"filesystem_servers,omitempty"`
15+
BackendSecurity BackendSecurity `yaml:"backend_security,omitempty"`
16+
Authentication Authentication `yaml:"authentication,omitempty"`
1717
}
1818

1919
/* complete config normalizer function */

config/database.go

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

1010
/* database parameters */
1111
type Database struct {
12-
TransactionLogRedis TransactionLogRedis `yaml:"transaction_log_redis"`
12+
TransactionLogRedis TransactionLogRedis `yaml:"transaction_log_redis,omitempty"`
1313
}
1414

1515
/* transaction log redis parameters */
1616
type TransactionLogRedis struct {
17-
Address string `yaml:"address"`
18-
Password string `yaml:"password"`
19-
DB int `yaml:"db"`
17+
Address string `yaml:"address,omitempty"`
18+
Password string `yaml:"password,omitempty"`
19+
DB int `yaml:"db,omitempty"`
2020
}
2121

2222
/* normalization function */

config/filesystem.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88

99
/* file system server parameters */
1010
type FileSystemServers struct {
11-
Path string `yaml:"path"`
12-
Method string `yaml:"method"`
11+
Path string `yaml:"path,omitempty"`
12+
Method string `yaml:"method,omitempty"`
1313
Remote *Remote `yaml:"remote,omitempty"`
1414
}
1515

1616
/* remote parameters for file system server with laclm daemons installed */
1717
type Remote struct {
18-
Host string `yaml:"host"`
19-
Port int `yaml:"port"`
18+
Host string `yaml:"host,omitempty"`
19+
Port int `yaml:"port,omitempty"`
2020
}
2121

2222
/* normalization function */

config/logging.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package config
22

33
/* logging parameters */
44
type Logging struct {
5-
File string `yaml:"file"`
6-
MaxSize int `yaml:"max_size"`
7-
MaxBackups int `yaml:"max_backups"`
8-
MaxAge int `yaml:"max_age"`
9-
Compress bool `yaml:"compress"`
5+
File string `yaml:"file,omitempty"`
6+
MaxSize int `yaml:"max_size,omitempty"`
7+
MaxBackups int `yaml:"max_backups,omitempty"`
8+
MaxAge int `yaml:"max_age,omitempty"`
9+
Compress bool `yaml:"compress,omitempty"`
1010
}
1111

1212
/* normalization function */

config/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package config
22

33
/* server deployment parameters */
44
type Server struct {
5-
Host string `yaml:"host"`
6-
Port int `yaml:"port"`
5+
Host string `yaml:"host,omitempty"`
6+
Port int `yaml:"port,omitempty"`
77
}
88

99
/* normalization function */

0 commit comments

Comments
 (0)