go-iris Re-registering a service in an mvc application

110 Views Asked by At

I am working on a heartbeat failure detector where on the front end I am using Iris and the front end is checking if the backend is alive.

The front end is an Iris mvc application done the following way:

app := iris.New()

app.StaticWeb("/", "./public")

// Configure the websocket server
ws := websocket.New(websocket.Config{})

jobAppsRouter := app.Party("/jobApplications")

jobAppsRouter.Any("/iris-ws.js", websocket.ClientHandler())

// Create the MVC object
jobApplicationsApp := mvc.New(jobAppsRouter)

Then I create my connection and I do the following

/ Create the service that interacts with the repo
jobAppService := services.NewJobApplicationService(conn)

// Dependencies
jobApplicationsApp.Register(
    jobAppService,
    ws.Upgrade,
)
// Controllers registration
jobApplicationsApp.Handle(new(controllers.JobAppController))
// Start the web server at http://localhost:8080
app.Run(iris.Addr(portStr))

This works and starts the app properly. The problem is that later on, I create a new connection to the same back end and I want to register a new service with it. Simply doing this again jobAppService := services.NewJobApplicationService(conn)

// Dependencies
jobApplicationsApp.Register(
    jobAppService,
    ws.Upgrade,
)

doesn't do what I need. What could I do?

0

There are 0 best solutions below