M
M
Maxim Makarov2021-09-03 17:58:53
go
Maxim Makarov, 2021-09-03 17:58:53

Golang compiler doesn't see packages imported from local package?

There is a small written API on GO, pq, mux and pbkdf2 were imported and the project compiled and ran normally, but there was a need for Redis after go mod init X and installing modules, the project throws an error

resources\users.go:10:5: cannot find package when compiling
models\db_con.go:6:2: cannot find package utils
\pass_hash.go:5:2: cannot find package

api/
     models/
         db_con.go
         models.go
     resources/
         users.go
     templates/
          ...
     utils/
          esm.go
          pass_hash.go
     settings.go
     main.go
     go.mod


resources/user.go
package resources

import (
  "encoding/json"
    "fmt"
    "net/http"
    //"context"
    "net"
    "time"
    "github.com/go-redis/redis/v8"
    //"github.com/google/uuid"
    "../../api/utils"
    "../../api/models"
    "../../api"

)
......


models/db_con.go
package models

import (
  "fmt"
    "database/sql"
  _"github.com/lib/pq"
    "../../api"
)

.....


utils/pass_hash.go
package utils

import (
  "fmt"
  "golang.org/x/crypto/pbkdf2"
  "crypto/sha256"
)

....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kenit, 2021-09-04
@chigan0

If I understand correctly, the problem is that they used "go mod init X", since this is an existing project and it was initialized with a new one. It's good to clear the cache of modules and fix everything again "go mod tidy" and / or "go get"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question