Hi there! 

I was playing a little bit with modules and packages, regarding making 
projects.
And I'm struggling to use a package (non-main) declared in the root 
directory.. allow me to show an example:

This scenario,  I have project somewhere on my file system
.
├── cmd
│   └── main.go
├── go.mod
└── util.go

*go.mod*
module a_module_path

go 1.19


*util.go*
package util

func Abs(x int) int {
if x < 0 {
return -x
} else {
return x
}
}

And the problem appears when I try to use the package util (in the root 
directory of the module) within another package of the module...

*cmd/main.go*
package main

import (
"fmt"
"a_module_path/util" // this doesn't works
"a_module_path/../util" // this attemp neither (and as relative import 
paths are not supported in module mode i guess is a no-go)
)

func main() {
fmt.Println(util.Abs(-2))
}

The question, as you may predict, is *¿If there any way to make this work?*
*I do not want to create a folder named util (or whatever) and place there 
the util package.*

Thanks for the reading and the patience!
Keep rocking code! 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/05b29995-e451-4235-a613-8193d995efcdn%40googlegroups.com.

Reply via email to