Simple dependency import

Thanks for helping me in advance. Fairly new to programming. I have two dependencies and some code first is puppy:

package puppy

func Bark() string{
return "Woof!"
}

func Barks() string {
return "Woof! Woof! Woof!"
}

github.com/dancoe77/008-puppy

Next would be dog:

package dog

import (
	"strings"
)

func WhenGrownUp(s string) string {
	return "When the puppy grows up it says: " + strings.ToUpper(s)
}

github.com/dancoe77/009-dog

Finally there is the code that joins the two:

package main

import(
	"fmt"
	"github.com/dancoe77/008-puppy"
	"github.com/dancoe77/009-dog"
)
func main(){
	s1 := puppy.Bark()
	s2 := puppy.Barks()
	fmt.Println(s1)
	fmt.Println(s2)
	
	s3 := dog.BigBark()
	s4 := dog.BigBarks()
	fmt.Println(s3)
	fmt.Println(s4)
	
	//also like this
	
}

049-Modular_code_dependency_mgmt_part2

I’ve looked this over multiple times and I don’t see any cyclic dependencies but when I run main.go I get import cycle not allowed so I’m guessing there is a cyclic depency somewhere I’m just not seeing it.

Dan S

Hi @dancoe77, welcome to the forum.

There are indeed no cyclic dependencies, and it took me a while to notice, but your repo 049-Modular_code_dependency_mgmt_part2 declares itself to be the 008-puppy module in go.mod:

module github.com/dancoe77/008-puppy

After I changed the module path to

module github.com/dancoe77/049-Modular_code_dependency_mgmt_part2

in GitHub codespaces (followed by go mod tidy), the cyclic dependency error is gone.

2 Likes

Thank you so much:))!! I really appreciate it:))

1 Like