folder structure:
- myproject
- resolver
- resolver.go
- main.go
go mod init github.com/kaleabbyh/foodrecipie
resolver.go:
package resolvers
import "fmt"
func resolverfunc(){
fmt.Println("resolvers are running")
}
main.go:
package main
import (
"fmt"
"github.com/kaleabbyh/foodrecipie/resolvers"
)
func main(){
resolvers.resolverfunc()
fmt.Println("main is running")
}
I try to do just like the above details but it returns me
no required module provides package "github.com/kaleabbyh/foodrecipie/resolvers"
Although you used package resolvers
, the name of that package's directory is resolver
, therefore the import path for that package (regardless of its name) is not "github.com/kaleabbyh/foodrecipie/resolvers"
but instead "github.com/kaleabbyh/foodrecipie/resolver"
.
Note also that, to be able to call functions in imported packages those functions need to be exported (i.e. they MUST start with an upper case letter). In other words; resolvers.resolverfunc()
is not gonna work (even if you manage to fix the import issue) because resolverfunc
is unexported (i.e. it starts with a lower case letter). See: https://go.dev/ref/spec#Exported_identifiers