0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 10:51:01 +00:00
hono/deno_dist/router/trie-router/router.ts
2022-07-02 15:09:45 +09:00

19 lines
410 B
TypeScript

import type { Result, Router } from '../../router.ts'
import { Node } from './node.ts'
export class TrieRouter<T> implements Router<T> {
node: Node<T>
constructor() {
this.node = new Node()
}
add(method: string, path: string, handler: T) {
this.node.insert(method, path, handler)
}
match(method: string, path: string): Result<T> | null {
return this.node.search(method, path)
}
}