I see following code (I simplified it a bit).
func getEndpoints(db *sqlx.DB) s.Endpoints {
var endpoints s.Endpoints
{
repository := acl.NewRepository(db)
service := stat.NewService(repository)
endpoints = s.Endpoints{
GetEndpoint: s.MakeEndpoint(service),
}
}
return endpoints
}
If I understand this code correctly, code inside var endpoints s.Endpoints{...} is executed line by line and endpoints = s.Endpoints ... line initialises var endpoints variable declared above.
I suppose that it's correct to rewrite it like this (correct me if I'm wrong):
func getEndpoints(db *sqlx.DB) s.Endpoints {
repository := acl.NewRepository(db)
service := stat.NewService(repository)
endpoints := s.Endpoints{
GetEndpoint: s.MakeEndpoint(service),
}
return endpoints
}
So can somebody explain me why initialisation is written inside var endpoints s.Endpoints{...}. Is there any idea to do it like this? Am I missing something?