diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7899f4d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.ignoreWords": [ + "msgf" + ] +} \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index abcb701..d8be989 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -68,7 +68,7 @@ tasks: run-backend: env: SERVER_PORT: 3500 - TZ: "America/New_York" + # TZ: "America/New_York" sources: - ./*.go cmds: diff --git a/app/config/config.yaml b/app/config/config.yaml new file mode 100644 index 0000000..de6323a --- /dev/null +++ b/app/config/config.yaml @@ -0,0 +1,10 @@ +# All values in this config file WILL BE overwritten by ENV variables if they exist. +Server: + port: 3000 + +Logger: + loglevel: "debug" # debug/info/warn/error + loggingFile: "./app/log/goInventorize.log" + +TZ: "Africa/Casablanca" # For goinventorize TZ, TZ in UNDERLYING docker image (scratch) is not set + diff --git a/config.go b/config.go index 1e6028d..d90bcfd 100644 --- a/config.go +++ b/config.go @@ -1,9 +1,11 @@ package main import ( - "fmt" + "os" + "time" "github.com/kkyr/fig" + "github.com/rs/zerolog" ) type Config struct { @@ -12,19 +14,45 @@ type Config struct { Port string `fig:"port" default:"3000"` } Logger struct { - Level string `fig:"level" default:"error"` + Level string `fig:"loglevel" default:"info"` + LoggingFile string `fig:"loggingFile" default:"./app/log/goInventorize.log"` } } -func LoadConfig(server *Server) error { +func LoadConfig(s *Server) error { var cfg Config - err := fig.Load(&cfg, fig.File("config.yaml"), fig.Dirs("./config"), fig.UseEnv("")) + err := fig.Load(&cfg, fig.File("config.yaml"), fig.Dirs("./app/config"), fig.UseEnv("")) // Load in config.yaml, then overwrite with ENV variables if err != nil { return err } - fmt.Println("Configuration loaded successfully...") - fmt.Println("PORT: ", cfg.Server.Port) - fmt.Println("TZ: ", cfg.Timezone) - server.Config = &cfg + logFile, err := os.OpenFile(cfg.Logger.LoggingFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) // Open/Create log file for writting to log + if err != nil { + return err + } + switch cfg.Logger.Level { // Setting our logging level + case "error": + zerolog.SetGlobalLevel(zerolog.ErrorLevel) + case "warn": + zerolog.SetGlobalLevel(zerolog.WarnLevel) + case "debug": + zerolog.SetGlobalLevel(zerolog.DebugLevel) + default: + zerolog.SetGlobalLevel(zerolog.InfoLevel) + + } + loc, err := time.LoadLocation(cfg.Timezone) // Getting our timezone info from config + if err != nil { + return err + } + s.LogFile = logFile + zerolog.TimestampFunc = func() time.Time { // Making sure our logger writes in the correct tz + return time.Now().In(loc) + } + s.Log = zerolog.New(logFile).With().Timestamp().Logger() + + defer logFile.Close() + s.Log.Info().Msg("Configuration loaded successfully...") + s.Log.Debug().Msgf("Values: Server Port: %s Logging File: %s Logging Level: %s Timezone: %s", cfg.Server.Port, cfg.Logger.LoggingFile, cfg.Logger.Level, cfg.Timezone) + s.Config = &cfg return nil } diff --git a/config/config.yaml b/config/config.yaml deleted file mode 100644 index e20feab..0000000 --- a/config/config.yaml +++ /dev/null @@ -1,2 +0,0 @@ -serverConfig: - port: 3000 \ No newline at end of file diff --git a/database.go b/database.go new file mode 100644 index 0000000..473a35d --- /dev/null +++ b/database.go @@ -0,0 +1,116 @@ +package main + +import ( + "path/filepath" + + "github.com/asdine/storm/v3" +) + +// Location is a top level component that starts the containerization process +type Location struct { + ID int `storm:"id,increment,index"` + Name string `storm:"unique"` + Description string + CoverPhoto string // A "cover photo" for the location + Photos []string // A list of additional photos for the location + Rooms []Room + Notes string +} + +// Room is a containerized area at a location +type Room struct { + ID int `storm:"id,increment,index"` + CoverPhoto string // A "cover photo" for the room + Photos []string // A list of additional photos for the room + Name string `storm:"unique"` + Description string + LocationID int //Which location room is assigned to + Notes string +} + +// Item is contained inside a room +type Item struct { + ID int `storm:"id, increment"` + RoomID int // Room ID that item is assigned to + CoverPhoto string // A "cover photo" for the item + Photos []string // A list of additional photos for the room + Name string + Product string + Serial string + Warranty string + Notes string +} + +//SetupDatabase initializes the storm/bbolt database +func SetupDatabase(s *Server) (db *storm.DB) { + db, err := storm.Open(filepath.Clean("./app/database/goInventorize.db")) + if err != nil { + s.Log.Fatal().Msgf("Unable to create/open database! %s", err) + } + return db +} + +// AddLocation adds a location to the database +func (s *Server) AddLocation(loc Location) error { + s.Log.Info().Msgf("Adding new location to database: ", loc) + err := s.Database.Save(&loc) + if err != nil { + s.Log.Error().Msgf("Unable to add new location to database: %s error: %s ", loc, err) + return err + } + return nil +} + +// AddRoom adds a room to a location +func (s *Server) AddRoom(room Room) error { + s.Log.Info().Msgf("Adding new room to location: %s", room) + err := s.Database.Save(&room) + if err != nil { + s.Log.Error().Msgf("Unable to add new room to database: %s error: %s", room, err) + return err + } + return nil +} + +// AddItem adds an item to a room +func (s *Server) AddItem(item Item) error { + s.Log.Info().Msgf("Adding new item to room: ", item) + err := s.Database.Save(&item) + if err != nil { + s.Log.Error().Msgf("Unable to add new item to room: %s error: %s", item, err) + return err + } + return nil +} + +// GetLocations fetches all of the locations from the database +func (s *Server) GetLocations() (locations []Location, err error) { + err = s.Database.All(&locations) + if err != nil { + s.Log.Error().Msgf("Unable to fetch all locations: %s", err) + return nil, err + } + return locations, nil +} + +// GetRoomsAtLocation fetches all the rooms assigned to a location by location ID +func (s *Server) GetRoomsAtLocation(locID int) error { + var rooms []Room + err := s.Database.Find("Location", locID, &rooms) + if err != nil { + s.Log.Error().Msgf("Unable to fetch all rooms at location: %s", err) + return err + } + return nil +} + +// GetItemsInRoom fetches all of the items assigned to a room +func (s *Server) GetItemsInRoom(roomID int) error { + var items []Item + err := s.Database.Find("Room", roomID, &items) + if err != nil { + s.Log.Error().Msgf("Unable to fetch all rooms at location: %s", err) + return err + } + return nil +} diff --git a/defaults/config/config.yaml b/defaults/config/config.yaml new file mode 100644 index 0000000..a68397b --- /dev/null +++ b/defaults/config/config.yaml @@ -0,0 +1,8 @@ +Server: + port: 3000 + +Logger: + loggingFile: "./app/log/goInventorize.log" + +TimeZone: "EST" # For goinventorize TZ, TZ in docker is not set + diff --git a/go.mod b/go.mod index 1f4cc2b..eab9f70 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,15 @@ go 1.16 require ( github.com/BurntSushi/toml v0.4.1 // indirect github.com/andybalholm/brotli v1.0.3 // indirect + github.com/asdine/storm/v3 v3.2.1 // indirect github.com/gofiber/fiber/v2 v2.15.0 github.com/ilyakaznacheev/cleanenv v1.2.5 // indirect github.com/kkyr/fig v0.3.0 // indirect github.com/klauspost/compress v1.13.1 // indirect + github.com/rs/zerolog v1.23.0 // indirect github.com/valyala/fasthttp v1.28.0 // indirect - golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + go.etcd.io/bbolt v1.3.6 // indirect + golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect gopkg.in/yaml.v2 v2.4.0 // indirect olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect ) diff --git a/go.sum b/go.sum index 92803c6..254ffb1 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,21 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= +github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM= github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.3 h1:fpcw+r1N1h0Poc1F/pHbW40cUm/lMEQslZtCkBQ0UnM= github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= +github.com/asdine/storm/v3 v3.2.1 h1:I5AqhkPK6nBZ/qJXySdI7ot5BlXSZ7qvDY1zAn5ZJac= +github.com/asdine/storm/v3 v3.2.1/go.mod h1:LEpXwGt4pIqrE/XcTvCnZHT5MgZCV6Ub9q7yQzOFWr0= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofiber/fiber/v2 v2.15.0 h1:yd+o1t6/hjkmjZxz4FJlgHAKBIu1w1PnRL3VB67KMHM= github.com/gofiber/fiber/v2 v2.15.0/go.mod h1:iftruuHGkRYGEXVISmdD7HTYWyfS2Bh+Dkfq4n/1Owg= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/ilyakaznacheev/cleanenv v1.2.5 h1:/SlcF9GaIvefWqFJzsccGG/NJdoaAwb7Mm7ImzhO3DM= github.com/ilyakaznacheev/cleanenv v1.2.5/go.mod h1:/i3yhzwZ3s7hacNERGFwvlhwXMDcaqwIzmayEhbRplk= @@ -16,10 +26,19 @@ github.com/kkyr/fig v0.3.0/go.mod h1:fEnrLjwg/iwSr8ksJF4DxrDmCUir5CaVMLORGYMcz30 github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.13.1 h1:wXr2uRxZTJXHLly6qhJabee5JqIhTRoLBhDOA74hDEQ= github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.23.0 h1:UskrK+saS9P9Y789yNNulYKdARjPZuS35B8gJF2x60g= +github.com/rs/zerolog v1.23.0/go.mod h1:6c7hFfxPOy7TacJc4Fcdi24/J0NKYGzjG8FWRI916Qo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.26.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA= @@ -27,19 +46,52 @@ github.com/valyala/fasthttp v1.28.0 h1:ruVmTmZaBR5i67NqnjvvH5gEv0zwHfWtbjoyW98ih github.com/valyala/fasthttp v1.28.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= +go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/main.go b/main.go index 327fbdc..3705246 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,20 @@ package main import ( "fmt" "log" + "os" + "github.com/asdine/storm/v3" "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/logger" + "github.com/rs/zerolog" ) type Server struct { - Config *Config + Config *Config + Database *storm.DB + WebServer *fiber.App + LogFile *os.File + Log zerolog.Logger } func main() { @@ -19,11 +27,19 @@ func main() { } fmt.Println("Server: ", server.Config) app := fiber.New() + app.Use(logger.New(logger.Config{ + Output: server.LogFile, + TimeZone: server.Config.Timezone, + })) - app.Get("/", func(c *fiber.Ctx) error { + server.WebServer = app + server.WebServer.Server().Logger.Printf("Webserver Started") + app.Server().Logger.Printf("HERE!") + + server.WebServer.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello, World 👋 RELOADED!") }) // fmt.Println("Port listen on: ", os.Getenv("PORT")) // fmt.Println("Timezone is: ", os.Getenv("TZ")) - app.Listen(fmt.Sprintf(":%s", server.Config.Server.Port)) + server.WebServer.Listen(fmt.Sprintf(":%s", server.Config.Server.Port)) }