# Go module and importing local package

**URL:** <https://forum.golangbridge.org/t/go-module-and-importing-local-package/11649>\
**Category:** Getting Help\
**Created:** [December 4, 2018, 2:45pm UTC](https://forum.golangbridge.org/t/go-module-and-importing-local-package/11649 "2018-12-04T14:45:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adammathieu](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@adammathieu](https://forum.golangbridge.org/u/adammathieu)\
**Post date:** [December 4, 2018, 2:45pm UTC](https://forum.golangbridge.org/t/go-module-and-importing-local-package/11649/1 "2018-12-04T14:45:43Z")

</div>

Hi everyone

I encounter issue regarding the use of go module.

My project example is structure as follow:

> testmod/  
> ------bar/  
> --------- bar.go  
> --------- bar\_test.go  
> ------cmd/  
> --------- testmod/  
> --------------- main.go  
> ------foo/  
> --------- foo.go  
> --------- foo\_test.go  
> ------go.mod  
> ------vendor

My go.mod is defined as follow

```auto
module example.org/maadam/testmod

require (
	github.com/davecgh/go-spew v1.1.1 // indirect
	github.com/pmezard/go-difflib v1.0.0 // indirect
	github.com/stretchr/testify v1.2.2
)

```

foo.go

```auto
package foo

import (
    "strconv"
)

func ConvertInt2String(num int) string {
	return strconv.Itoa(num)
}

```

bar.go

```auto
package bar

import (
    "strconv"
)

func ConvertString2Int(num string) (int, error) {
	return strconv.Atoi(num)
}

```

main.go

```auto
package main

import (
	"fmt"

	"example.org/maadam/testmod/foo"
	"example.org/maadam/testmod/bar"
)

func main() {
	iFoo := 2
	strFoo := ConvertInt2String(iFoo)
	fmt.Printf("foo.ConvertInt2String %d : %s", iFoo, strFoo)

	strBar := "28"
	iBar, _ := ConvertString2Int(strBar)
	fmt.Printf("bar.ConvertString2Int %s : %d", strBar, iBar)
}

```

I thought that as my module name was _[example.org/maadam/testmod](http://example.org/maadam/testmod)_, I could import my packages foo or bar by using [example.org/maadam/testmod/foo](http://example.org/maadam/testmod/foo) or /bar.  
But when I am trying to build cmd/testmod/main.go, I have the following errors:

```auto
> go build cmd/testmod/main.go 
> # command-line-arguments
> cmd/testmod/main.go:6:2: imported and not used: "example.org/maadam/testmod/foo"
> cmd/testmod/main.go:7:2: imported and not used: "example.org/maadam/testmod/bar"
> cmd/testmod/main.go:12:12: undefined: ConvertInt2String
> cmd/testmod/main.go:16:13: undefined: ConvertString2Int

```

Can you help me understand what I am doing wrong with go module for importing my package? Or is it just the project structure that is not compatible with?

Regards

---

<div class="post-metadata">

**Author:** ![adammathieu](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/a/bbe5ce/32.png) [@adammathieu](https://forum.golangbridge.org/u/adammathieu)\
**Post date:** [December 4, 2018, 3:01pm UTC](https://forum.golangbridge.org/t/go-module-and-importing-local-package/11649/2 "2018-12-04T15:01:44Z")

</div>

Ok so I found my mistake… I have to call the function with the name of package I imported: foo.ConvertInt2String() and bar.ConvertString2Int()…

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [March 4, 2019, 3:01pm UTC](https://forum.golangbridge.org/t/go-module-and-importing-local-package/11649/3 "2019-03-04T15:01:47Z")

</div>

Closed on March 4, 2019, 3:01pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
