为什么我的 GitHub 操作脚本找不到我的内部 go 包?



我正在学习 Go,想使用 GitHub Actions。仅使用一个包时一切都很好。但是一旦我定义了多个包(比主包多(,我就会卡住。在我的桌面上,它可以编译,但通过使用操作脚本它不会,最终出现以下错误:

Run go build -v main.go
main.go:4:2: cannot find package "Landsat-Extractor/logger" in any of:
/opt/hostedtoolcache/go/1.14.4/x64/src/Landsat-Extractor/logger (from $GOROOT)
/home/runner/go/src/Landsat-Extractor/logger (from $GOPATH)
##[error]Process completed with exit code 1.

文件结构为:

go
└───src
└───Landsat-Extractor
│   main.go
│
└───logger
|   │   logger.go
|
└───.github
└───workflows
|   go.yml

在我的本地计算机上,GOPATH 设置为以前的文件结构go

我的操作脚本 go.yml 是:

name: Go
on:
push:
branches: [ master, feature_githubaction ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Build
run: go build -v main.go

主要内容是:

package main
import (
"Landsat-Extractor/logger"
)
func main() {
logger.Create()
defer logger.Destroy()
logger.Info("A message")
}

logger.go 是:

package logger
// Create inits the Logger
func Create() {
println("Creating")
}
// Info logs a message
func Info(msg string) {
println(msg)
}
// Destroy closes writers
func Destroy() {
println("Closing")
}

In~/go/src/Landsat-Extractorrungo mod init

这将有助于解决模块导入问题。

最新更新