blob: bb4136a5964d86db0edb335c984ca732c47183b2 [file] [log] [blame]
iomodoc6abf5b2021-02-19 14:48:03 +04001package commands
2
3import (
iomodoa19d4792021-03-26 00:27:25 +04004 "github.com/giolekva/pcloud/core/kg/app"
iomodoc6abf5b2021-02-19 14:48:03 +04005 "github.com/giolekva/pcloud/core/kg/log"
iomodob892d072021-02-22 00:23:16 +04006 "github.com/giolekva/pcloud/core/kg/model"
iomodoc6abf5b2021-02-19 14:48:03 +04007 "github.com/giolekva/pcloud/core/kg/server"
iomodoa19d4792021-03-26 00:27:25 +04008 "github.com/giolekva/pcloud/core/kg/store/memory"
iomodoc6abf5b2021-02-19 14:48:03 +04009 "github.com/spf13/cobra"
10)
11
12// Command is an abstraction of the cobra Command
13type Command = cobra.Command
14
15// Run function starts the application
16func Run(args []string) error {
17 rootCmd.SetArgs(args)
18 return rootCmd.Execute()
19}
20
21// rootCmd is a command to run the server.
iomodod32f9ee2021-02-21 21:28:50 +040022var rootCmd = &Command{
iomodoc6abf5b2021-02-19 14:48:03 +040023 Use: "server",
24 Short: "An example of the basic server",
25 RunE: serverCmdF,
26}
27
28func serverCmdF(command *cobra.Command, args []string) error {
iomodob892d072021-02-22 00:23:16 +040029 logger := log.NewLogger(&log.LoggerConfiguration{
iomodoc6abf5b2021-02-19 14:48:03 +040030 EnableConsole: true,
31 ConsoleJSON: true,
32 ConsoleLevel: "debug",
33 EnableFile: true,
34 FileJSON: true,
35 FileLevel: "debug",
36 FileLocation: "server.log",
iomodob892d072021-02-22 00:23:16 +040037 })
38 config := model.NewConfig()
39
iomodoa19d4792021-03-26 00:27:25 +040040 st := memory.New()
iomodo352127d2021-03-26 20:10:32 +040041 a := app.NewApp(st, config, logger)
iomodoa19d4792021-03-26 00:27:25 +040042
43 grpcServer := server.NewGRPCServer(logger, config, a)
44 httpServer := server.NewHTTPServer(logger, config, a)
iomodob892d072021-02-22 00:23:16 +040045
iomododb170e12021-02-21 23:06:20 +040046 servers := server.New(logger)
47 servers.AddServers(grpcServer)
iomodob892d072021-02-22 00:23:16 +040048 servers.AddServers(httpServer)
iomododb170e12021-02-21 23:06:20 +040049 servers.Run()
iomodoc6abf5b2021-02-19 14:48:03 +040050
iomodoc6abf5b2021-02-19 14:48:03 +040051 return nil
52}