Changed generic type constraint
This commit is contained in:
parent
be04815fdb
commit
2a94dc114e
@ -3,7 +3,7 @@ package router
|
||||
import "os"
|
||||
|
||||
// Router is a high-performance router.
|
||||
type Router[T comparable] struct {
|
||||
type Router[T any] struct {
|
||||
get Tree[T]
|
||||
post Tree[T]
|
||||
delete Tree[T]
|
||||
@ -16,7 +16,7 @@ type Router[T comparable] struct {
|
||||
}
|
||||
|
||||
// New creates a new router containing trees for every HTTP method.
|
||||
func New[T comparable]() *Router[T] {
|
||||
func New[T any]() *Router[T] {
|
||||
return &Router[T]{}
|
||||
}
|
||||
|
||||
|
6
Tree.go
6
Tree.go
@ -15,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
// Tree represents a radix tree.
|
||||
type Tree[T comparable] struct {
|
||||
type Tree[T any] struct {
|
||||
root treeNode[T]
|
||||
static map[string]T
|
||||
canBeStatic [2048]bool
|
||||
@ -238,12 +238,8 @@ begin:
|
||||
|
||||
// Bind binds all handlers to a new one provided by the callback.
|
||||
func (tree *Tree[T]) Bind(transform func(T) T) {
|
||||
var empty T
|
||||
|
||||
tree.root.each(func(node *treeNode[T]) {
|
||||
if node.data != empty {
|
||||
node.data = transform(node.data)
|
||||
}
|
||||
})
|
||||
|
||||
for key, value := range tree.static {
|
||||
|
2
go.mod
2
go.mod
@ -2,4 +2,4 @@ module git.akyoto.dev/go/router
|
||||
|
||||
go 1.20
|
||||
|
||||
require git.akyoto.dev/go/assert v0.1.1
|
||||
require git.akyoto.dev/go/assert v0.1.2
|
||||
|
4
go.sum
4
go.sum
@ -1,2 +1,2 @@
|
||||
git.akyoto.dev/go/assert v0.1.1 h1:F0IO7RxXVfV86Y7bwLsd+C5Ar3X0XCJIuywyiCrk8ms=
|
||||
git.akyoto.dev/go/assert v0.1.1/go.mod h1:Zr/UFuiqmqRmFFgpBGwF71jbzb6iYJfXFeePYHGtWsg=
|
||||
git.akyoto.dev/go/assert v0.1.2 h1:3paz/5z/JcGK/2K9J+pVh5Jwt2gYfJQG+P5OE9/jB7Y=
|
||||
git.akyoto.dev/go/assert v0.1.2/go.mod h1:Zr/UFuiqmqRmFFgpBGwF71jbzb6iYJfXFeePYHGtWsg=
|
||||
|
Loading…
x
Reference in New Issue
Block a user