You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### kong ####### Copyright (c) 2021-2022 losyme ################################################ MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package router |
|
|
|
import "strings" |
|
|
|
const _paramPrefix = ":" |
|
|
|
type segment struct { |
|
param string |
|
handlers map[string]HandlerFunc |
|
middlewares []Middleware |
|
routes map[string]*segment |
|
} |
|
|
|
func newSegment(ps string) *segment { |
|
var param string |
|
|
|
if strings.HasPrefix(ps, _paramPrefix) { |
|
param = strings.TrimPrefix(ps, _paramPrefix) |
|
} |
|
|
|
return &segment{ |
|
param: param, |
|
} |
|
} |
|
|
|
func (s *segment) next(ps string) *segment { |
|
if s.routes == nil { |
|
s.routes = make(map[string]*segment) |
|
next := newSegment(ps) |
|
s.routes[ps] = next |
|
|
|
return next |
|
} |
|
|
|
next, ok := s.routes[ps] |
|
if !ok { |
|
next = newSegment(ps) |
|
s.routes[ps] = next |
|
} |
|
|
|
return next |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|