-
-
Save euskadi31/2e15d21bc718b6f02f3497ad3e0a531d to your computer and use it in GitHub Desktop.
[swift-evolution] custom attribute in userland.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of custom attribute | |
@attribute("route") | |
struct Route { | |
var route: String | |
var name: String? | |
init(route: String) { | |
self.route = route | |
} | |
} | |
@attribute("method") | |
struct Method { | |
var verb: String | |
init(verb: String) { | |
self.verb = verb | |
} | |
} | |
struct CourseController { | |
@route("/courses/", name="toto") | |
@method("GET") | |
func listAction(request: Request) -> Response { | |
return Response(200, "Hello World") | |
} | |
} | |
let app = Application() | |
app.register(CourseController()) | |
app.run(8080) | |
// other example of custom attribute | |
@mappable | |
class ArticleEntity { | |
@field("article_id") | |
var id: Int | |
@field("article_name") | |
var name: String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment