简体   繁体   中英

Getting go module issue

I'm new to go modules, I'd like to https://github.com/microsoft/ApplicationInsights-Go but can't import it using go modules, all the other packages are automatically imported, just this one doesn't want:/

What am I missing?

package logger

import (
    "fmt"
    "github.com/microsoft/ApplicationInsights-Go/appinsights" //<-- This won't import
)

var tc appinsights.TelemetryClient

func init() {
    tc = appinsights.NewTelemetryClient("")
}


func LogError(err error) {
    if err != nil {
        fmt.Println(err)
        tc.TrackException(err)
    }
}

func LogEvent(message string) {
    ex := appinsights.NewEventTelemetry(message)
    tc.Track(ex)
}

Compiler message:

could not import github.com/microsoft/ApplicationInsights-Go/appinsights (no package for import github.com/microsoft/ApplicationInsights-Go/appinsights)

EDIT 1: GO ENV output

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\JakubMichalewski\AppData\Local\go-build
set GOENV=C:\Users\JakubMichalewski\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Projects\GO;C:\Users\JakubMichalewski\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Projects\NCV\src\NCV.Services\NCV.WebScraper\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\JAKUBM~1\AppData\Local\Temp\go-build949124214=/tmp/go-build -gno-record-gcc-switches

Interesting that it worked for you, when I did go mod init it found all packages, when I do manually go get [github.com/microsoft/ApplicationInsights-Go/appinsights] it's being found but I thill can't use it.

Only

github.com/microsoft/ApplicationInsights-Go

is being imported so when in the logger.go file I'm importing

github.com/microsoft/ApplicationInsights-Go/appinsights

it doesn't see

appinsights

part so I can't use it.

I just copied your code and created a module:

 ~/awesomeProject  go mod init example.com
go: creating new go.mod: module example.com

 ~/awesomeProject  go mod tidy
go: finding module for package github.com/microsoft/ApplicationInsights-Go/appinsights
go: downloading github.com/microsoft/ApplicationInsights-Go v0.4.3
go: found github.com/microsoft/ApplicationInsights-Go/appinsights in github.com/microsoft/ApplicationInsights-Go v0.4.3
go: downloading code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c
go: downloading github.com/tedsuo/ifrit v0.0.0-20180802180643-bea94bb476cc
go: downloading golang.org/x/net v0.0.0-20180906233101-161cd47e91fd

 ~/awesomeProject  go mod vendor

Could you please paste here your go env output?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM