From 020fc720379255832aad369dfc2dece9a1cf4699 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 3 Sep 2023 18:34:56 +0530 Subject: added pretty startup messages --- README.md | 10 ++++++++++ conf/conf.go | 4 +++- db/db.go | 2 ++ item/item.go | 4 +++- main.go | 10 ++++++++-- openbills.toml | 1 + 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c12b239 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# OpenBills + +OpenBills is a web based libre billing software. + +## Licence +Licenced under GNU General Public Licence + +GNU GPL License: [LICENSE](https://dev.vidhukant.xyz/openbills/tree/LICENSE) + +Copyright (c) 2023 Vidhu Kant Sharma diff --git a/conf/conf.go b/conf/conf.go index 9c3d328..26a5d90 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -25,7 +25,6 @@ import ( // TODO: validate config func init() { viper.SetConfigName("openbills") - viper.SetConfigType("toml") viper.AddConfigPath("/etc/openbills") viper.AddConfigPath(".") @@ -38,6 +37,7 @@ func init() { } viper.SetDefault("port", "8765") + viper.SetDefault("production_mode", false) viper.SetDefault("security.min_password_length", 12) viper.SetDefault("security.max_password_length", 72) @@ -52,4 +52,6 @@ func init() { viper.SetDefault("username.max_username_length", 20) viper.SetDefault("cryptography.password_hashing_cost", 14) + + log.Printf("\x1b[46m\x1b[30m[info]\x1b[0m Loaded Config File \"%s\"\n", viper.ConfigFileUsed()) } diff --git a/db/db.go b/db/db.go index 14b0f11..1d64bf7 100644 --- a/db/db.go +++ b/db/db.go @@ -45,4 +45,6 @@ func init() { if err != nil { log.Fatalf("\x1b[41m\x1b[30m[err]\x1b[0m cannot to connect to database, exiting.\n%v\n", err) } + + log.Printf("\x1b[46m\x1b[30m[info]\x1b[0m Successfully Connected To Database \"%v\"\n", conf["db_name"]) } diff --git a/item/item.go b/item/item.go index 839cbe0..02e568e 100644 --- a/item/item.go +++ b/item/item.go @@ -32,7 +32,9 @@ func init() { type Brand struct { gorm.Model - Name string + UserID uint `json:"-"` + User user.User `json:"-"` + Name string } type Item struct { diff --git a/main.go b/main.go index 6b9704c..cf54d25 100644 --- a/main.go +++ b/main.go @@ -39,10 +39,15 @@ import ( const OPENBILLS_VERSION = "v0.0.1" -func main() { - log.Printf("\x1b[46m\x1b[30m[info]\x1b[0m Starting OpenBills Server %s\n", OPENBILLS_VERSION) +func init() { + if viper.GetBool("production_mode") { + gin.SetMode(gin.ReleaseMode) + } +} +func main() { r := gin.New() + r.SetTrustedProxies([]string{"127.0.0.1"}) r.GET("/info", serverInfo) @@ -60,5 +65,6 @@ func main() { item.Routes(protected) } + log.Printf("\x1b[46m\x1b[30m[info]\x1b[0m Running OpenBills Server %s\n", OPENBILLS_VERSION) r.Run(":" + viper.GetString("port")) } diff --git a/openbills.toml b/openbills.toml index 6733c5a..dd37e22 100644 --- a/openbills.toml +++ b/openbills.toml @@ -1,4 +1,5 @@ port = 8765 +production_mode = false [database] username = "openbills" -- cgit v1.2.3