A
A
Alexander2021-06-04 19:36:58
go
Alexander, 2021-06-04 19:36:58

Why doesn't the compiler see packages imported from a module's local package?

The imported package (github.com/texttheater/golang-levenshtein/levenshtein) worked fine until the functionality, together with the import of this package, was moved to a separate local package (/pkg/analyzer).

Was:
login_watch/main.go:

package main

import (
  "container/list"
  "fmt"
  "github.com/texttheater/golang-levenshtein/levenshtein"
  "time"

  "encoding/json"
  "log"
  "net/http"

  "sync"

  "github.com/gorilla/mux"
  rotatelogs "github.com/lestrrat-go/file-rotatelogs"
) 
...


Became:
login_watch/main.go:
package main

import (
  "container/list"
  "fmt"
  "github.com/mustikkakeitto/login_watch/pkg/analyzer"
  "time"

  "encoding/json"
  "log"
  "net/http"

  "sync"

  "github.com/gorilla/mux"
  rotatelogs "github.com/lestrrat-go/file-rotatelogs"
) 
...

login_watch/pkg/analyzer/series.go:
// Package analyzer implements functions to detect series
// built from the particular phone numbers
package analyzer

import (
  "container/list"
  "fmt"
  "time"

  "github.com/texttheater/golang-levenshtein/levenshtein"

  "log"
)
...


Run gives error
\login_watch>go run .
pkg\analyzer\series.go:10:2: cannot find package


I tried with other imports - the same thing, in main.go it sees them, in the local package - no.

I've looked all over the forums and found nothing.

Reference info:
login_watch/go.mod:
module github.com/mustikkakeitto/login_watch

go 1.16

require (
  github.com/gorilla/mux v1.8.0
  github.com/jonboulle/clockwork v0.2.2 // indirect
  github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
  github.com/lestrrat-go/strftime v1.0.4 // indirect
  github.com/pkg/errors v0.9.1 // indirect
  github.com/texttheater/golang-levenshtein/levenshtein v0.0.0-20200805054039-cae8b0eaed6c // indirect
)


go version go1.16.4 windows/amd64
GOPATH=C:\Users\Alex\go
Environment variable GOROOT not defined
Environment variable GO111MODULE not defined

Project structure:
C:.
│   build4linux.cmd
│   Dockerfile
│   go.mod
│   go.sum
│   main.go
│
├───bin
├───log
└───pkg
    └───analyzer
            series.go
            series_test.go

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-06-08
@mustikkakeitto

The problem was in the encoding of one of the files (series.go) - there was a UTF-8 BOM header; The compiler doesn't seem to digest them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question