1

I'm using golang and GoLand(Jetbrains)IDE for development on UBUNTU. My Go path is /usr/local/go and my Project Directory is at /Home/GoLandProjects with bin, src, pkg directories and my project directory.

go version go1.16.7 linux/amd64

My GOPATH is set like this in .bashrc:

export GOPATH="$HOME/GolandProjects"
export PATH="$PATH:$GOPATH/bin:/usr/local/go/bin"

Everything is good, If I run my code its totally works fine but my import is making issues, not showing Intellisence-suggestions. Imports from within the project are not working.

import (
    "context" //woking
    "errors" //woking
    "go.mongodb.org/mongo-driver/bson" //woking
    "go.mongodb.org/mongo-driver/bson/primitive" //woking
    "go.mongodb.org/mongo-driver/mongo" //woking

    "my-server/helpers" //not woking - not showing intelliSense and in Red Color 
    "my-server/models"  //not woking - not showing intelliSense and in Red Color 

    "time" //woking
)

Code is running but no intelliSense of internal imports.

My go.mod file:

module my-server

// +heroku goVersion go1.16
go 1.16

require (
    cloud.google.com/go v0.91.1 // indirect
    cloud.google.com/go/firestore v1.5.0 // indirect
    cloud.google.com/go/storage v1.16.0 // indirect
    firebase.google.com/go v3.13.0+incompatible
    github.com/aead/chacha20poly1305 v0.0.0-20170617001512-233f39982aeb // indirect
    github.com/gin-contrib/cors v1.3.1
    github.com/gin-gonic/gin v1.7.3
    github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
    github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
    github.com/gorilla/websocket v1.4.2 // indirect
    github.com/mikunalpha/goas v1.6.0 // indirect
    github.com/o1egl/paseto v1.0.0
    go.mongodb.org/mongo-driver v1.7.1
    golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
    golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5
    golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
    golang.org/x/text v0.3.7 // indirect
    google.golang.org/api v0.54.0
    google.golang.org/genproto v0.0.0-20210813162853-db860fec028c // indirect
    google.golang.org/grpc v1.40.0 // indirect
)

ls -alR

drwxrwxr-x 9 zainkhan zainkhan  4096 Sep  4 12:40 .
drwxrwxr-x 8 zainkhan zainkhan  4096 Sep  2 16:45 ..
-rw-rw-r-- 1 zainkhan zainkhan  2373 Sep  2 16:42 admin-pk.json
drwxrwxr-x 2 zainkhan zainkhan  4096 Sep  4 17:08 controllers
-rw-rw-r-- 1 zainkhan zainkhan  2383 Sep  2 16:42 credentials.json
-rw-rw-r-- 1 zainkhan zainkhan   123 Sep  2 16:42 Dockerfile
drwxrwxr-x 8 zainkhan zainkhan  4096 Sep  4 17:08 .git
drwxrwxr-x 3 zainkhan zainkhan  4096 Sep  2 16:42 .github
-rw-rw-r-- 1 zainkhan zainkhan     6 Sep  2 16:42 .gitignore
-rw-rw-r-- 1 zainkhan zainkhan  1078 Sep  4 12:40 go.mod
-rw-rw-r-- 1 zainkhan zainkhan 70236 Sep  2 16:45 go.sum
drwxrwxr-x 2 zainkhan zainkhan  4096 Sep  3 12:45 helpers
drwxrwxr-x 3 zainkhan zainkhan  4096 Sep  4 17:14 .idea
-rw-rw-r-- 1 zainkhan zainkhan  1403 Sep  4 12:40 main.go
drwxrwxr-x 3 zainkhan zainkhan  4096 Sep  4 16:28 models
drwxrwxr-x 2 zainkhan zainkhan  4096 Sep  4 17:08 services

in helpers dir

./helpers:
total 20
drwxrwxr-x 2 zainkhan zainkhan 4096 Sep  3 12:45 .
drwxrwxr-x 9 zainkhan zainkhan 4096 Sep  4 12:40 ..
-rw-rw-r-- 1 zainkhan zainkhan   16 Sep  2 16:42 firebase.go
-rw-rw-r-- 1 zainkhan zainkhan  854 Sep  2 16:42 mongo.go
-rw-rw-r-- 1 zainkhan zainkhan 3138 Sep  3 12:45 mongo_utils.go

enter image description here enter image description here enter image description here

Zain Ur Rehman
  • 287
  • 3
  • 14

1 Answers1

1

GOPATH is not same as go mod. Modify your go.mod file to locate your local package using replace.

enter image description here

replace package => path/to/package

p1gd0g
  • 631
  • 5
  • 16