blob: 812cdf14f51ad4f7e16f8dee3a5c9146e715e169 [file] [log] [blame]
iomodoc6abf5b2021-02-19 14:48:03 +04001package commands
2
3import (
4 "github.com/giolekva/pcloud/core/kg/log"
5 "github.com/giolekva/pcloud/core/kg/server"
6 "github.com/spf13/cobra"
7)
8
9// Command is an abstraction of the cobra Command
10type Command = cobra.Command
11
12// Run function starts the application
13func Run(args []string) error {
14 rootCmd.SetArgs(args)
15 return rootCmd.Execute()
16}
17
18// rootCmd is a command to run the server.
iomodod32f9ee2021-02-21 21:28:50 +040019var rootCmd = &Command{
iomodoc6abf5b2021-02-19 14:48:03 +040020 Use: "server",
21 Short: "An example of the basic server",
22 RunE: serverCmdF,
23}
24
25func serverCmdF(command *cobra.Command, args []string) error {
26 config := &log.LoggerConfiguration{
27 EnableConsole: true,
28 ConsoleJSON: true,
29 ConsoleLevel: "debug",
30 EnableFile: true,
31 FileJSON: true,
32 FileLevel: "debug",
33 FileLocation: "server.log",
34 }
35 logger := log.NewLogger(config)
36 srv, err := server.NewServer(logger)
37 if err != nil {
38 logger.Error(err.Error())
39 return err
40 }
41 defer srv.Shutdown()
42
43 serverErr := srv.Start()
44 if serverErr != nil {
45 logger.Error(err.Error())
46 return serverErr
47 }
48 return nil
49}