Cannot find package error when building in Go modules

Asked 2 years ago, Updated 2 years ago, 58 views

./goexample
./goexample/main.go
./goexample/config
./goexample/config/config.go

In the hierarchy shown in , the config package config.go is called from main.go.
config.go imports "gopkg.in/ini.v1".

An error occurred during the following process with reference to Go Modules.

$go mod init goexample
$cd config /
$go mod init config
$go get-u gopkg.in/ini.v1
$cd..
$go build./...

Error Occurring
config/config.go:import line number:cannot find package
There is an error in importing package ini like the above.How do I install the Go package ini using modules?

./goexample/main.go

package main
import(
 "./config"
)
// code

./goexample/config/config.go

package config
import(
    "gopkg.in/ini.v1" < - Where the error occurred
)
// code

It is as follows.
I use Fedora as my operating system.

go

2022-09-30 14:25

1 Answers

In the directory, follow these steps:

$go mod init goexample
$go run main.go 
$go get-u gopkg.in/ini.v1
$go run main.go

Also, the import location in main.go is

import(
 "goexample/config"
)

Change as shown in .


2022-09-30 14:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.