Skip to content

Add support to mulitple routes referring to same handler in goctl #5234

@ez4bk

Description

@ez4bk

Description of Problem
I'm doing a product that should allow users to access some parts of the web page based on their given roles. We are using atomic APIs. APIs are devided by the entity type. Such as GET /user, GET /project. In this case, two components on the website may share one common API, for example, GET /project. But one of them are not available for a give user role. So I want to have APIs to be /componentA/project and /componentB/project but they both refer to the same handler. And in my middleware, I will determine if the user role has the right to access the project in componentA or componentB.

This kind of design is indeed a little bit strange, whic I have to admit. And my description does not express the entire picture of the application. But this method is the most suitable way of doing it that we could do it.

Description of Solution
So, in the API file, I would like to define multiple API routes using the same handler, which by far is not supported and would give a duplicate handler expression error.

@doc (
	summary:   "Access entity in component A"
)
@handler AccessEntity
get /component-a/entity returns (EntityInfo)

@doc (
	summary:   "Access entity in component B"
)
@handler AccessEntity
get /component-b/entity returns (EntityInfo)

Alternatives I Can Imagine
Another way of implementing this, is to support a mapping layer that is able to map multiple routes to one route. So I would still define get /entity to handler AccessEntity, but I can have an another dedicated method to map other routes to it.

@doc (
	summary:   "Access entity in component A"
)
@handler AccessEntity
get /entity returns (EntityInfo)

e.g.

handler.MapRoutes(map[string]string)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions