Add logging

This commit is contained in:
2022-09-10 00:09:09 +02:00
parent 8ceb4452f9
commit af142c4b09
9 changed files with 170 additions and 0 deletions

View 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
}

View 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
View 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)
}
}