*Thanks again!* El sáb, 15 abr 2023 a las 16:50, 'Sean Liao' via golang-nuts (< golang-nuts@googlegroups.com>) escribió:
> the import path specifies the location to find a package, but the actual > identifier used is the one in the package declaration, so > > import "a_module_path" > > var foo = util.Foo > > - sean > > On Sat, Apr 15, 2023, 20:40 Victor Giordano <vitucho3...@gmail.com> wrote: > >> Thanks *Sean!!* >> That makes sense for me! >> >> But i guess I must import with an alias as import without an alias >> doesn't works, right? >> >> <user>@<machine>:<the_project_folder>/cmd$ go build . >> # a_module_path/cmd >> ./main.go:4:2: imported and not used: "a_module_path" as util >> ./main.go:9:14: undefined: a_module_path >> >> main.go >> package main >> >> import ( >> "a_module_path" >> "fmt" >> ) >> >> func main() { >> fmt.Println(a_module_path.Abs(-2)) >> } >> >> I mean... i'm actually importing it without utill.. so the message kind >> of confuse me. >> >> Thanks again. >> El sábado, 15 de abril de 2023 a las 16:34:01 UTC-3, Sean Liao escribió: >> >>> import "a_module_path" >>> >>> optionally rename it to make it clearer >>> >>> import util "a_module_path" >>> >>> - sean >>> >>> On Sat, Apr 15, 2023, 20:31 Victor Giordano <vituc...@gmail.com> wrote: >>> >>>> 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...@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 >>>> <https://groups.google.com/d/msgid/golang-nuts/05b29995-e451-4235-a613-8193d995efcdn%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >> 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/f5bd0bd6-dc15-4160-89a0-34ae4d89d70bn%40googlegroups.com >> <https://groups.google.com/d/msgid/golang-nuts/f5bd0bd6-dc15-4160-89a0-34ae4d89d70bn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/9LtHHkjGsGQ/unsubscribe. > To unsubscribe from this group and all its topics, 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/CAGabyPqs%2BHUse780M-CdYaAYR%3D8qSdWotYxE5QSqJZwfSD65SA%40mail.gmail.com > <https://groups.google.com/d/msgid/golang-nuts/CAGabyPqs%2BHUse780M-CdYaAYR%3D8qSdWotYxE5QSqJZwfSD65SA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- V -- 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/CAPUu9suCZPSJkRsrSyc%3DopmCBUjK8hYe3RimaLsGRHjh%3DUyuFQ%40mail.gmail.com.