File tree Expand file tree Collapse file tree 7 files changed +41
-18
lines changed Expand file tree Collapse file tree 7 files changed +41
-18
lines changed Original file line number Diff line number Diff 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 ..." )
Original file line number Diff line number Diff line change @@ -20,23 +20,23 @@ database:
2020
2121# logging configurations
2222logging :
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
3030filesystem_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
3838authentication :
3939 ldap :
4040
4141backend_security :
42- jwt_expiry :
42+ jwt_expiry : 1
Original file line number Diff line number Diff 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 */
1117func 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 */
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import (
1313/* generating jwt token for user identification with specified configs */
1414func 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 }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ type App struct {
1010/* server deployment parameters */
1111type 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 */
3838type FileSystemServers struct {
39- Remote * Remote `yaml:"remote"`
39+ Remote * Remote `yaml:"remote,omitempty "`
4040 Path string `yaml:"path"`
4141 Method string `yaml:"method"`
4242}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments