github.com/astaxie/beego@v1.12.3/filter.go (about) 1 // Copyright 2014 beego Author. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package beego 16 17 import "github.com/astaxie/beego/context" 18 19 // FilterFunc defines a filter function which is invoked before the controller handler is executed. 20 type FilterFunc func(*context.Context) 21 22 // FilterRouter defines a filter operation which is invoked before the controller handler is executed. 23 // It can match the URL against a pattern, and execute a filter function 24 // when a request with a matching URL arrives. 25 type FilterRouter struct { 26 filterFunc FilterFunc 27 tree *Tree 28 pattern string 29 returnOnOutput bool 30 resetParams bool 31 } 32 33 // ValidRouter checks if the current request is matched by this filter. 34 // If the request is matched, the values of the URL parameters defined 35 // by the filter pattern are also returned. 36 func (f *FilterRouter) ValidRouter(url string, ctx *context.Context) bool { 37 isOk := f.tree.Match(url, ctx) 38 if isOk != nil { 39 if b, ok := isOk.(bool); ok { 40 return b 41 } 42 } 43 return false 44 }