I'm learning Go and want to make use of GitHub Actions. Everything is fine when working with just one package. But as soon as I define more than one package (more than the main package), I get stucked. On my desktop it does compile, but by using Actions script it does not and ends up in following error:
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.
The file structure is:
go
└───src
└───Landsat-Extractor
│ main.go
│
└───logger
| │ logger.go
|
└───.github
└───workflows
| go.yml
On my local machine GOPATH is set to go
of the previous file structure.
My Actions script go.yml is:
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
The main.go is:
package main
import (
"Landsat-Extractor/logger"
)
func main() {
logger.Create()
defer logger.Destroy()
logger.Info("A message")
}
The logger.go is:
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-Extractor
run go mod init
This would help to resolve your module imports.
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.