router.go
func (r *Router) handle(method, pattern string, handle Handle) *Route {
	method = strings.ToUpper(method)

	var leaf *Leaf
	// Prevent duplicate routes.
	if leaf = r.getLeaf(method, pattern); leaf != nil {
		return &Route{r, leaf}
	}

	// Validate HTTP methods.
	if !_HTTP_METHODS[method] && method != "*" {
		panic("unknown HTTP method: " + method)
	}

	// Generate methods need register.
	methods := make(map[string]bool)
	if method == "*" {
		for m := range _HTTP_METHODS {
			methods[m] = true
		}
	} else {
		methods[method] = true
	}

	// Add to router tree.
	for m := range methods {
		if t, ok := r.routers[m]; ok {
			leaf = t.Add(pattern, handle)
		} else {
			t := NewTree()
			leaf = t.Add(pattern, handle)
			r.routers[m] = t
		}
		r.add(m, pattern, leaf)
	}
	return &Route{r, leaf}
}
func (r *Router) handle(method, pattern string, handle Handle) *Route {
	method = strings.ToUpper(method)

	var leaf *Leaf
	// Prevent duplicate routes.
	if leaf = r.getLeaf(method, pattern); leaf != nil {
		return &Route{r, leaf}
	}

	// Validate HTTP methods.
	if !_HTTP_METHODS[method] && method != "*" {
		panic("unknown HTTP method: " + method)
	}

	// Generate methods need register.
	methods := make(map[string]bool)
	if method == "*" {
		for m := range _HTTP_METHODS {
			methods[m] = true
		}
	} else {
		methods[method] = true
	}

	// Add to router tree.
	for m := range methods {
		if t, ok := r.routers[m]; ok {
			leaf = t.Add(pattern, handle)
		} else {
			t := NewTree()
			leaf = t.Add(pattern, handle)
			r.routers[m] = t
		}
		r.add(m, pattern, leaf)
	}
	return &Route{r, leaf}
}
func ( r * Router ) handle ( method , pattern string , handle Handle ) * Route { method = strings . ToUpper ( method ) var leaf * Leaf // Prevent duplicate routes. if leaf = r . getLeaf ( method , pattern ) ; leaf != nil { return & Route { r , leaf } } // Validate HTTP methods. if ! _HTTP_METHODS [ method ] && method != " " { panic ( " " + method ) } // Generate methods need register. methods := make ( map [ string ] bool ) if method == " " { for m := range _HTTP_METHODS { methods [ m ] = true } } else { methods [ method ] = true } // Add to router tree. for m := range methods { if t , ok := r . routers [ m ] ; ok { leaf = t . Add ( pattern , handle ) } else { t := NewTree ( ) leaf = t . Add ( pattern , handle ) r . routers [ m ] = t } r . add ( m , pattern , leaf ) } return & Route { r , leaf } }
// handle adds new route to the router tree.
handle adds new route to the router tree .