Cobra CMD does not executes completly

235 views Asked by At

I have the following code, is really simple. The point is that the code after the first fmt.Println is never executed. Any idea why?

The code creates a random string, and then creates a Gin Router. The code that executes the router is never being runned.

func send(cmd *cobra.Command, args []string) {

    randomString = createRandomString()
    fmt.Println("Code for share: " + randomString)
    var files filesToSend = args

    //Create http to listen to port
    g := gin.Default()
    g.GET("/", files.sendHttpHandler)
    g.Run()
}
1

There are 1 answers

1
TehSphinX On BEST ANSWER

Problem is the import path in main.go vs the module name in go.mod. The capitalization is different:

package main

import "github.com/mariogmarq/goshare/cmd"

go.mod:

module github.com/mariogmarq/GoShare

It is best practice to use all lowercase for package (and module) names. From the Go Blog:

Good package names are short and clear. They are lower case, with no under_scores or mixedCaps.