I get the following error message:
controllers/user.go:4:2: cannot find package "(underscore)/home/ubuntu/goapi/src/github.com/roes/api/vendor/github.com/gin-gonic/gin"
in any of: /usr/local/go/src/(underscore)/home/ubuntu/goapi/src/github.com/roes/api/vendor/github.com/gin-gonic/gin (from $GOROOT)
/home/ubuntu/goapi/src/_(underscore)/home/ubuntu/goapi/src/github.com/roes/api/vendor/github.com/gin-gonic/gin (from $GOPATH)
go env
GOPATH="/home/ubuntu/goapi"
GOROOT="/usr/local/go"
folder structure
github.com/rose
api
main.go // the loading gin is ok here
controller
|-user.go //with import ( "github.com/gin-gonic/gin" ) : error
go env looks Ok.
Some more code:
package controller
import (
"github.com/gin-gonic/gin"
"net/http"
// "github.com/astaxie/beego/orm"
"../database"
"../models"
)
func init() {
database.ConnectToDb()
ORM = database.GetOrmObject()
}
//UserController ...
type UserController struct{}
func createUser(c *gin.Context) {
example resource: https://github.com/thearavind/go-gin-pg, nothing wrong with this example. I just make it like MVC structure
I did remove go. and install it again flow Linux version https://golang.org/doc/install then
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
then https://github.com/gin-gonic/gin#use-a-vendor-tool-like-govendor the example code run ok. when I add controller folder with user.go with
import( "github.com/gin-gonic/gin")
full code
package controller
import( "github.com/gin-gonic/gin")
func somestring(){
return "hello world"
}
in the main.go i use above
curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go
add to import
"./controller"
"fmt"
add to the main function
user := new(controller.somestring)
fmt.Printf(user)
I understand this is not a good code for me, but will produce this error again, like so:
controller/user.go:4:2: cannot find package "github.com/gin-gonic/gin" in any of:
/usr/local/go/src/github.com/gin-gonic/gin (from $GOROOT)
/home/ubuntu/go/src/github.com/gin-gonic/gin (from $GOPATH)
(no underscore this time)
No luck, reinstall go
I am able to find the path, but not the underscore thing
08:56:35 ~/go/src/github.com/jerry/core$ cd /home/ubuntu/go/src/github.com/jerry/core/vendor/github.com/gin-gonic/
08:56:45 ~/go/src/github.com/jerry/core/vendor/github.com/gin-gonic$
github.com/rose
. In your error messages you havegithub.com/roes
. Why? – peterSOimport "_/home/ubuntu/goapi/src/github.com/roes/api/vendor/github.com/gin-gonic/gin"
, which is wrong. Go wouldn't look in$GOPATH/src/_home/ubuntu/...
otherwise. – Peter