Skip to content

Commit 78cd820

Browse files
Some minor changes + added normalization for Config
1 parent ea2584f commit 78cd820

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

cmd/laclm/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func exec() error {
2929
/* exec() wraps run() protecting it with user interrupts */
3030

3131
utils.InitLogger(true)
32+
3233
/* zap.L() can be used all over the code for global level logging */
3334

3435
zap.L().Info("Logger Initiated ...")

config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ database:
2020

2121
# logging configurations
2222
logging:
23-
file:
24-
max_size:
25-
max_backups:
26-
max_age:
27-
compress:
23+
file: "logs/app.log"
24+
max_size: 100
25+
max_backups: 5
26+
max_age: 30
27+
compress: true
2828

2929
# filesystem server that needs management
3030
filesystem_servers:
31-
- path:
32-
method:
31+
- path: /mnt/beegfs-1
32+
method: "remote"
3333
remote:
34-
host:
35-
port:
34+
host: "127.0.0.1"
35+
port: 4444
3636

3737
# authentication information
3838
authentication:
3939
ldap:
4040

4141
backend_security:
42-
jwt_expiry:
42+
jwt_expiry: 1

config/loader.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import (
77
"gopkg.in/yaml.v3"
88
)
99

10+
/*
11+
we need config normalization as well
12+
config normalization fixes all the fields that are not present in config file
13+
and sets it to default value
14+
*/
15+
1016
/* loads yaml config file from given file path */
1117
func LoadConfig(path string) {
1218

@@ -25,6 +31,8 @@ func LoadConfig(path string) {
2531
zap.Error(err),
2632
)
2733
}
34+
35+
BackendConfig.Normalize()
2836
}
2937

3038
/* loads environment variables */

internal/authentication/authentication.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
/* generating jwt token for user identification with specified configs */
1414
func GenerateJWT(username string) (string, error) {
1515
expiryHours := config.BackendConfig.BackendSecurity.JWTExpiry
16+
17+
/* GET THIS INTO CONFIG SANITISATION */
1618
if expiryHours == 0 {
1719
expiryHours = 24
1820
}

internal/models/models.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type App struct {
1010
/* server deployment parameters */
1111
type Server struct {
1212
Host string `yaml:"host"`
13-
Port string `yaml:"port"`
13+
Port int `yaml:"port"`
1414
}
1515

1616
/* database parameters */
@@ -31,12 +31,12 @@ type Logging struct {
3131
MaxSize int `yaml:"max_size"`
3232
MaxBackups int `yaml:"max_backups"`
3333
MaxAge int `yaml:"max_age"`
34-
Compress int `yaml:"compress"`
34+
Compress bool `yaml:"compress"`
3535
}
3636

3737
/* file system server parameters */
3838
type FileSystemServers struct {
39-
Remote *Remote `yaml:"remote"`
39+
Remote *Remote `yaml:"remote,omitempty"`
4040
Path string `yaml:"path"`
4141
Method string `yaml:"method"`
4242
}

internal/models/normalize.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package models
2+
3+
func (m *Config) Normalize() {
4+
if m.Server.Host == "" {
5+
m.Server.Host = "localhost"
6+
}
7+
8+
if m.Server.Port == 0 {
9+
m.Server.Port = 8080
10+
}
11+
}

internal/utils/utils.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"log"
55
"os"
66

7+
"github.com/PythonHacker24/linux-acl-management-backend/config"
78
"github.com/google/uuid"
89
"go.uber.org/zap"
910
"go.uber.org/zap/zapcore"
@@ -25,11 +26,11 @@ func InitLogger(isProduction bool) {
2526
encoder = zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
2627
logLevel = zapcore.InfoLevel
2728
writeSyncer = zapcore.AddSync(&lumberjack.Logger{
28-
Filename: "logs/app.log",
29-
MaxSize: 100, // MB
30-
MaxBackups: 5,
31-
MaxAge: 30, // days
32-
Compress: true,
29+
Filename: config.BackendConfig.Logging.File,
30+
MaxSize: config.BackendConfig.Logging.MaxSize, // MB
31+
MaxBackups: config.BackendConfig.Logging.MaxBackups,
32+
MaxAge: config.BackendConfig.Logging.MaxBackups, // days
33+
Compress: config.BackendConfig.Logging.Compress,
3334
})
3435
} else {
3536

0 commit comments

Comments
 (0)