Passing dependency container structure by value or reference – Getting help


I am just wondering which exercise below is correct. Well the received functions will not modify the container.

Thank you

type Container struct {
	Version  string
	Shutdown time.Duration

	SomeStructA StructA
	SomeStructB *StructB

	DB     *sql.DB
	SRV    *http.Server
	AWSS3  *s3.S3
	AWSSES *session.Session

func main() {
	con := Container{}

	a(con) // Pass by value
	// OR
	b(&con) // Pass by reference

func a(Container)  {}
func b(*Container) {}

Leave a Comment