Warning: Long post!!
I am new to go.
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
Just wonder what happens? go env looks Ok.
I did check with my friend Google, some questions are similar but answers are not working for me :(
Anyone, please.
Thanks in advance.
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
UPDATE1 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
UPDATE 2 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$
maybe I just miss out this step for every folder in the project folder. (very important)
mkdir -p $GOPATH/src/github.com/myusername/project && cd "$_"
I keep asking my friend Google, the answer is: goVendor depend on the $GOPHATH a lot. then I Create the controller folder with above command. so every folder too. no problem :)
Thank you to everyone Helping and Viewing