feat: add hono.route method for easy group requests
This commit is contained in:
@@ -70,6 +70,12 @@ fn main() {
|
||||
status_code: 200
|
||||
}
|
||||
})
|
||||
mut book_app := &hono.Hono{}
|
||||
book_app.get('/api/book', fn (req hono.Request) http.Response {
|
||||
println('Received get request: ${req}')
|
||||
return hono.Response.text('books')
|
||||
})
|
||||
hono_app.route('/api', mut book_app)
|
||||
port := '0.0.0.0:8585'
|
||||
hono_app.listen(port)
|
||||
println('Listening on ${port}')
|
||||
|
||||
+21
-13
@@ -1,14 +1,22 @@
|
||||
import regex
|
||||
// import regex
|
||||
import pcre
|
||||
|
||||
fn main(){
|
||||
path := "/order/**"
|
||||
mut replaced_path := path.replace('**','[\\w+//?]+')
|
||||
println("replaced_path: ${replaced_path}")
|
||||
replaced_path = replaced_path.replace('*','\\w+')
|
||||
println("replaced_path: ${replaced_path}")
|
||||
replaced_path = replaced_path + '$'
|
||||
println("replaced_path: ${replaced_path}")
|
||||
mut reg := regex.regex_opt(replaced_path) or { panic(err) }
|
||||
result := reg.matches_string("/order/33")
|
||||
println("reg match result ${result}")
|
||||
}
|
||||
fn main() {
|
||||
// path := '/order/**'
|
||||
// mut replaced_path := path.replace('**','[\\w+//?]+')
|
||||
// println("replaced_path: ${replaced_path}")
|
||||
// replaced_path = replaced_path.replace('*','\\w+')
|
||||
// println("replaced_path: ${replaced_path}")
|
||||
// replaced_path = replaced_path + '$'
|
||||
// println("replaced_path: ${replaced_path}")
|
||||
// mut reg := regex.regex_opt(replaced_path) or { panic(err) }
|
||||
// result := reg.matches_string("/order/33")
|
||||
mut reg := pcre.new_regex(r'/(?:order)/[\w+/]+', 0) or { panic(err) }
|
||||
result := reg.match_str('555/order/33//?88/', 0, 0) or { panic(err) }
|
||||
mut count := 0
|
||||
for count < result.group_size {
|
||||
println('group ${count} ${result.get(count) or { 'not found' }}')
|
||||
count++
|
||||
}
|
||||
println('reg match result ${result}')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user