blob: 70a4d233b521c5a1ff54ad4ce38efef3ad278640 [file] [log] [blame]
iomodoc6abf5b2021-02-19 14:48:03 +04001package commands
2
3import (
4 "github.com/giolekva/pcloud/core/kg/log"
iomodob892d072021-02-22 00:23:16 +04005 "github.com/giolekva/pcloud/core/kg/model"
iomodoc6abf5b2021-02-19 14:48:03 +04006 "github.com/giolekva/pcloud/core/kg/server"
7 "github.com/spf13/cobra"
8)
9
10// Command is an abstraction of the cobra Command
11type Command = cobra.Command
12
13// Run function starts the application
14func Run(args []string) error {
15 rootCmd.SetArgs(args)
16 return rootCmd.Execute()
17}
18
19// rootCmd is a command to run the server.
iomodod32f9ee2021-02-21 21:28:50 +040020var rootCmd = &Command{
iomodoc6abf5b2021-02-19 14:48:03 +040021 Use: "server",
22 Short: "An example of the basic server",
23 RunE: serverCmdF,
24}
25
26func serverCmdF(command *cobra.Command, args []string) error {
iomodob892d072021-02-22 00:23:16 +040027 logger := log.NewLogger(&log.LoggerConfiguration{
iomodoc6abf5b2021-02-19 14:48:03 +040028 EnableConsole: true,
29 ConsoleJSON: true,
30 ConsoleLevel: "debug",
31 EnableFile: true,
32 FileJSON: true,
33 FileLevel: "debug",
34 FileLocation: "server.log",
iomodob892d072021-02-22 00:23:16 +040035 })
36 config := model.NewConfig()
37
38 grpcServer := server.NewGRPCServer(logger, config, nil)
39 httpServer := server.NewHTTPServer(logger, config, nil)
40
iomododb170e12021-02-21 23:06:20 +040041 servers := server.New(logger)
42 servers.AddServers(grpcServer)
iomodob892d072021-02-22 00:23:16 +040043 servers.AddServers(httpServer)
iomododb170e12021-02-21 23:06:20 +040044 servers.Run()
iomodoc6abf5b2021-02-19 14:48:03 +040045
iomodoc6abf5b2021-02-19 14:48:03 +040046 return nil
47}