Add logging
This commit is contained in:
22
cmd/kraken/commands/root.go
Normal file
22
cmd/kraken/commands/root.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package commands
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
func CreateKrakenCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "krakenserver",
|
||||
Short: "A brief description of your application",
|
||||
Long: `A longer description that spans multiple lines and likely contains
|
||||
examples and usage of using your application. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
|
||||
return cmd
|
||||
}
|
18
cmd/kraken/kraken.go
Normal file
18
cmd/kraken/kraken.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/kraken/cmd/server/commands"
|
||||
)
|
||||
|
||||
func main() {
|
||||
Execute()
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
err := commands.CreateServerCmd().Execute()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
16
cmd/server/commands/root.go
Normal file
16
cmd/server/commands/root.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func CreateServerCmd(logger *zap.Logger) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "krakenserver",
|
||||
}
|
||||
|
||||
cmd.AddCommand(NewStartServerCommand(logger))
|
||||
|
||||
return cmd
|
||||
}
|
21
cmd/server/commands/start.go
Normal file
21
cmd/server/commands/start.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func NewStartServerCommand(logger *zap.Logger) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "Start the kraken server",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
return errors.New("some error")
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
27
cmd/server/server.go
Normal file
27
cmd/server/server.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/kraken/cmd/server/commands"
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/logger"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger, err := logger.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_ = logger.Sync()
|
||||
|
||||
Execute(logger)
|
||||
}
|
||||
|
||||
func Execute(logger *zap.Logger) {
|
||||
err := commands.CreateServerCmd(logger).Execute()
|
||||
if err != nil {
|
||||
logger.Error("execution failed", zap.Error(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user