gpt4 book ai didi

go - 获取 go 模块问题

转载 作者:行者123 更新时间:2023-12-01 22:23:18 26 4
gpt4 key购买 nike

我是新手去模块,我想https://github.com/microsoft/ApplicationInsights-Go但不能使用 go 模块导入它,所有其他包都会自动导入,只是这个不想要:/

我错过了什么?

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)
}

编译器消息:
could not import github.com/microsoft/ApplicationInsights-Go/appinsights (no package for import github.com/microsoft/ApplicationInsights-Go/appinsights)

编辑1:
GO ENV 输出
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

有趣的是,它对您有用,当我确实 go mod init 时,它找到了所有包,当我手动 go get [github.com/microsoft/ApplicationInsights-Go/appinsights] 时,它被找到了,但我无法使用它。

仅有的

github.com/microsoft/ApplicationInsights-Go



正在导入,所以当我在 logger.go 文件中导入时

github.com/microsoft/ApplicationInsights-Go/appinsights



它没有看到

appinsights



部分,所以我不能使用它。

最佳答案

我刚刚复制了您的代码并创建了一个模块:

 ~/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

你能把你的 go env贴在这里吗?输出?

关于go - 获取 go 模块问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61563442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com