Skip to content

Commit

Permalink
refactor: use Init to init config router and logger
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayheaven committed Jan 23, 2024
1 parent 5ea0cae commit 80641ed
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
12 changes: 6 additions & 6 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ import (
)

var (
// host string
// port uint
host string

Check failure on line 22 in cmd/server.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

var `host` is unused (unused)
port int

Check failure on line 23 in cmd/server.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

var `port` is unused (unused)
ServerStartCmd = &cobra.Command{
Use: "server",
Short: `Start the server`,
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
// log.Println("Hello World!")
start()
},
}
Expand All @@ -35,19 +33,21 @@ var (
func init() {

// ServerStartCmd.Flags().StringVarP(&host, "host", "H", "127.0.0.1", "HTTP server host") // server host
// ServerStartCmd.Flags().UintVarP(&port, "port", "p", 8080, "HTTP server port") // server port
rootCmd.AddCommand(ServerStartCmd) // add server start command
// ServerStartCmd.Flags().IntVarP(&port, "port", "p", 8080, "Http server port") // server port
}

func start() {

// init router
router.Init()
r := router.Router

// init logger
logger.Init()
logger := logger.LogrusLogger

// load env config
configs.Init()
EnvConfig := configs.EnvConfig

// connect database
Expand Down
4 changes: 0 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ var VersionCmd = &cobra.Command{
fmt.Printf(`Go-Gin-Boilerplate version: %v`, "v0.0.1")
},
}

func init() {
rootCmd.AddCommand(VersionCmd) // add version command
}
3 changes: 1 addition & 2 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func LoadConfig() *Config {
return config
}

func init() {
func Init() {
EnvConfig = LoadConfig()
fmt.Printf("👻 EnvConfig: %+v\n", EnvConfig)
}
3 changes: 2 additions & 1 deletion configs/server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package configs

type Server struct {
Port string
GinMode string
Port string
}
2 changes: 1 addition & 1 deletion internal/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var (
LogrusLogger *logrus.Logger
)

func init() {
func Init() {
LogrusLogger = InitLogrusLogger()

// ZapLogger = InitZapLogger()
Expand Down
2 changes: 1 addition & 1 deletion internal/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

var Router *gin.Engine

func init() {
func Init() {
Router = gin.Default()

// Global middlewares
Expand Down

0 comments on commit 80641ed

Please sign in to comment.