From ff9e4b3e3a455052a576ce2016a1a4c4d7b087b2 Mon Sep 17 00:00:00 2001 From: netbenix Date: Sat, 6 Nov 2021 20:55:55 +0100 Subject: [PATCH] Updated logging --- Commands/ListCommand.go | 12 ++++++---- Commands/PullCommand.go | 12 ++++++---- Commands/PushCommand.go | 12 ++++++---- Commands/SearchCommand.go | 49 +++++++++++++++++++++++++++++++++------ Lotus/LotusProto.go | 23 ++++++++++++++++++ go.mod | 1 + go.sum | 8 +++++++ main.go | 19 ++++++++------- 8 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 Lotus/LotusProto.go diff --git a/Commands/ListCommand.go b/Commands/ListCommand.go index 512651f..c36bd6a 100644 --- a/Commands/ListCommand.go +++ b/Commands/ListCommand.go @@ -1,12 +1,15 @@ package Commands import ( - "fmt" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "lpm-cli/Tools" + "lpm-cli/Lotus" ) -func ListCommand() *cli.Command{ +func NewListCommand() *cli.Command{ + + logger := Lotus.CreateLogger("listCommand", logrus.WarnLevel) + return &cli.Command{ Name: "list", Usage: "Lists all packages", @@ -18,8 +21,7 @@ func ListCommand() *cli.Command{ }, OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error { if err != nil { - fmt.Printf("[ERROR] %s", err.Error()) - Tools.ErrorLogger.Fatal(err) + logger.Fatal(err) } return err }, diff --git a/Commands/PullCommand.go b/Commands/PullCommand.go index a208103..1f028b4 100644 --- a/Commands/PullCommand.go +++ b/Commands/PullCommand.go @@ -1,12 +1,15 @@ package Commands import ( - "fmt" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "lpm-cli/Tools" + "lpm-cli/Lotus" ) -func PullCommand() *cli.Command{ +func NewPullCommand() *cli.Command{ + + logger := Lotus.CreateLogger("pullCommand", logrus.WarnLevel) + return &cli.Command { Name: "pull", Usage: "Pull a package", @@ -18,8 +21,7 @@ func PullCommand() *cli.Command{ }, OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error { if err != nil { - fmt.Printf("[ERROR] %s", err.Error()) - Tools.ErrorLogger.Fatal(err) + logger.Fatal(err) } return err }, diff --git a/Commands/PushCommand.go b/Commands/PushCommand.go index eea2589..3a778b0 100644 --- a/Commands/PushCommand.go +++ b/Commands/PushCommand.go @@ -1,12 +1,15 @@ package Commands import ( - "fmt" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" - "lpm-cli/Tools" + "lpm-cli/Lotus" ) -func PushCommand() *cli.Command { +func NewPushCommand() *cli.Command { + + logger := Lotus.CreateLogger("pushCommand", logrus.WarnLevel) + return &cli.Command { Name: "push", Usage: "Push a package", @@ -18,8 +21,7 @@ func PushCommand() *cli.Command { }, OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error { if err != nil{ - fmt.Printf("[ERROR] %s", err.Error()) - Tools.ErrorLogger.Fatal(err) + logger.Fatal(err) } return err }, diff --git a/Commands/SearchCommand.go b/Commands/SearchCommand.go index 1711b55..78a4763 100644 --- a/Commands/SearchCommand.go +++ b/Commands/SearchCommand.go @@ -1,25 +1,60 @@ package Commands import ( + "context" "fmt" "github.com/urfave/cli/v2" - "lpm-cli/Tools" + "google.golang.org/grpc" + "github.com/sirupsen/logrus" + "lpm-cli/Lotus" + proto "lpm-cli/Proto/lpm/go" + "time" ) -func SearchCommand() *cli.Command{ +func NewSearchCommand() *cli.Command { + + logger := Lotus.CreateLogger("searchCommand", logrus.WarnLevel) + return &cli.Command { Name: "search", Usage: "Seaches a packages", Description: "Sends a search request to the default registry server, or to a user-defined registry server", HelpName: "search", - Action: func(c *cli.Context) error{ - //Do Stuff + Action: func(c *cli.Context) error { + + //TODO Remove Hardcoded addr + conn, err := grpc.Dial("faf-notebook2:9090", grpc.WithInsecure()) + if err != nil{ + logger.Error(err) + } + + defer conn.Close() + + lrc := proto.NewLpmRegistryClient(conn) + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + start := time.Now() + r, connErr := lrc.Search(ctx, &proto.SearchRequest {Platform: "noot", Architecture: nil, Query: "Schnitzel"}) + fmt.Printf("%d", time.Since(start).Milliseconds()) + if connErr != nil { + logger.Fatal(connErr) + } + + packages := r.GetPackages() + + fmt.Printf("Packages: ") + + for _, pkg := range packages { + fmt.Printf("%s\t\t\t\t\t%s\t\t\t\t\t%s\n", pkg.GetArchitecture(), pkg.GetPublisher(), pkg.GetVersion()) + } + return nil }, OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error { - if err != nil { - fmt.Printf("[ERROR]%s", err.Error()) - Tools.ErrorLogger.Fatal(err) + if err != nil{ + logger.Fatal(err) } return err }, diff --git a/Lotus/LotusProto.go b/Lotus/LotusProto.go new file mode 100644 index 0000000..4ce8dbf --- /dev/null +++ b/Lotus/LotusProto.go @@ -0,0 +1,23 @@ +package Lotus + +import ( + proto "lpm-cli/Proto/lpm/go" +) + +type LotusProtoHandler struct {} + +var ( + LotusProto *LotusProtoHandler +) + + +func (lph* LotusProtoHandler) GetPackageMetasFromRegistry(registry string) []proto.PackageMetadata{ + + //var addr = flag.String("addr", "localhost:50051", "connection addr") + + + + return nil +} + + diff --git a/go.mod b/go.mod index 18e0ec7..dc14503 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.17 require ( github.com/golang/protobuf v1.5.2 + github.com/sirupsen/logrus v1.8.1 github.com/urfave/cli/v2 v2.3.0 google.golang.org/grpc v1.42.0 google.golang.org/protobuf v1.27.1 diff --git a/go.sum b/go.sum index 7e9d40a..c3eebef 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -54,8 +56,12 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= @@ -83,6 +89,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= @@ -125,6 +132,7 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/main.go b/main.go index 5a8ca2d..762faef 100644 --- a/main.go +++ b/main.go @@ -4,29 +4,32 @@ import ( "github.com/urfave/cli/v2" "lpm-cli/Commands" "lpm-cli/Informations" - . "lpm-cli/Logging" + "github.com/sirupsen/logrus" + "lpm-cli/Lotus" "os" ) func main() { - Logger.Init() - Logger.Info("Lotus-PM was executed") + logger := Lotus.CreateLogger("mainThread", logrus.InfoLevel) + app := &cli.App { Name: "lotus-pm", Usage: "Lotus Package Manager", Authors: Informations.GetAuthors(), Copyright: "(c) 2021 LPM-Group", Commands: []*cli.Command { - Commands.PushCommand(), - Commands.PullCommand(), - Commands.SearchCommand(), - Commands.ListCommand(), + Commands.NewPushCommand(), + Commands.NewPullCommand(), + Commands.NewSearchCommand(), + Commands.NewListCommand(), }, } err := app.Run(os.Args) - ErrorHandler.HandleFatal(err) + if err != nil{ + logger.Fatal(err) + } } \ No newline at end of file