mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
@ -64,3 +64,31 @@ fn (mut app App) time_json_pretty() {
|
||||
'time': time.now().format()
|
||||
})
|
||||
}
|
||||
|
||||
struct ApiSuccessResponse<T> {
|
||||
success bool
|
||||
result T
|
||||
}
|
||||
|
||||
fn (mut app App) json_success<T>(result T) vweb.Result {
|
||||
response := ApiSuccessResponse<T>{
|
||||
success: true
|
||||
result: result
|
||||
}
|
||||
|
||||
return app.json(response)
|
||||
}
|
||||
|
||||
// should compile, this is a helper method, not exposed as a route
|
||||
fn (mut app App) some_helper<T>(result T) ApiSuccessResponse<T> {
|
||||
response := ApiSuccessResponse<T>{
|
||||
success: true
|
||||
result: result
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
// should compile, the route method itself is not generic
|
||||
fn (mut app App) ok() vweb.Result {
|
||||
return app.json(app.some_helper(123))
|
||||
}
|
||||
|
Reference in New Issue
Block a user