2

I am having issues loading a package in GO.

My main.go file needs ::

import (
        "encoding/csv"
        "flag"
        "net/http"
        "os"
        "runtime"
        "strings"

        log "github.com/Sirupsen/logrus"
        "github.com/oliver006/redis_exporter/exporter"
        "github.com/prometheus/client_golang/prometheus"
)

Now in my SRC folder of go I have,

[root@node src]# pwd
/usr/local/go/src

[root@node src]# ls -tlrh github.com/
total 12K
drwxr-xr-x 3 root root 4.0K Aug 29 17:12 Sirupsen
drwxr-xr-x 3 root root 4.0K Aug 29 17:14 oliver006
drwxr-xr-x 3 root root 4.0K Aug 29 17:14 garyburd

When I am trying to build my project, the ERROR I get is :

[root@node redis_exporter]# go build
can't load package: /usr/local/go/src/redis_exporter/main.go:11:2: non-standard import "github.com/Sirupsen/logrus" in standard package "redis_exporter"

At one point I accidentally ran a command :

go get github.com/prometheus/client_golang/prometheus

Im not sure if this is causing an issue. Is there a way to revert this back ?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    What is your `GOPATH`? Why are you storing the project in `/usr/local/go/src` instead of a subfolder of `/home/$USER/`? – syntagma Aug 29 '17 at 17:33
  • 1
    Possible duplicate? https://stackoverflow.com/questions/36901658/error-non-standard-import-gopkg-in-yaml-v2-in-standard-package – Melvin Aug 29 '17 at 17:35
  • `go env && cd $GOPATH/src/ && tree -L 2` –  Aug 29 '17 at 17:44
  • 4
    You can't have your source in GOROOT. Your "redis_exporter" package (`/usr/local/go/src/redis_exporter/`) needs to go in your GOPATH ([How to Write Go Code](https://golang.org/doc/code.html)) – JimB Aug 29 '17 at 17:56
  • @JimB - thanks for the link – KevinDTimm Aug 29 '17 at 18:32

0 Answers0