#Error when running application

3 messages · Page 1 of 1 (latest)

viscid juniper
#

Good morning, I created a file to separate the responsibility of starting some dependencies but I get undefined when running the project ```go
package main

import (
"context"
"log"

"github.com/elvesbd/goCrud/src/configuration/database/mongodb"
"github.com/elvesbd/goCrud/src/configuration/logger"
"github.com/elvesbd/goCrud/src/controller/routes"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"

)

func main() {
logger.Info("About to start application")
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}

database, err := mongodb.NewMongoDBConnection(context.Background())
if err != nil {
    log.Fatalf("Error trying to connect database, error=%s \n",
        err.Error())
    return
}

userController := initDependencies(database)

router := gin.Default()
routes.InitRoutes(&router.RouterGroup, userController)
if err := router.Run(":8080"); err != nil {
    log.Fatal(err)
}

}
go
package main

import (
"github.com/elvesbd/goCrud/src/controller"
"github.com/elvesbd/goCrud/src/model/repository"
"github.com/elvesbd/goCrud/src/model/service"
"go.mongodb.org/mongo-driver/mongo"
)

func initDependencies(database *mongo.Database) controller.UserControllerInterface {
repo := repository.NewUserRepository(database)
userService := service.NewUserDomainService(repo)
return controller.NewUserControllerInterface(userService)
}

#
go run main.go                                                              
# command-line-arguments
./main.go:28:20: undefined: initDependencies
rich kraken
#

You're using go run main.go which tells the compiler to only using main.go
Do go run . to use all of the main package