Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何将通配符运算符*集成到数学验证路由_String_Go - Fatal编程技术网

String 如何将通配符运算符*集成到数学验证路由

String 如何将通配符运算符*集成到数学验证路由,string,go,String,Go,我正在go中建立一个认证系统,到目前为止,我对它的工作非常满意。但是现在我想集成一个通配符操作符,如下所示: 如果uri是/user/list,并且在允许的映射中有/user/*它必须是pas Allowed { "*": {"administrator", "regional"}, // logic works "/user/*": {"administrator"}, // how to implement "/login": {"administrator", "regiona

我正在go中建立一个认证系统,到目前为止,我对它的工作非常满意。但是现在我想集成一个通配符操作符,如下所示:

如果uri是/user/list,并且在允许的映射中有/user/*它必须是pas

Allowed {
  "*": {"administrator", "regional"}, // logic works
  "/user/*": {"administrator"}, // how to implement
  "/login": {"administrator", "regional"}, // logic works
}

func (a *Authentication) IsAllowed(req *http.Request, role string) error {
schema := a.Schema // = the Allowed map[string][]string above
url := req.URL.String()

// Check strict match of the url in the schema
roles, ok := schema[url] 
if ok {
  if util.InSlice(role, roles) {
    return nil
  } else {
    return USERNOTALLOWED // error
  }
}

// here must come the logic of the wildcardsuffix
if a.hasWildCardSuffix(url string) {

}

// Fallback to wildCard *
if a.hasWildCard() { // return a bool whenever there is a "*" key
  roles, _ = a.Schema["*"] 
  if util.InSlice(role, roles) {
    return nil
  } else {
    return USERNOTALLOWED // error
  }
 }
 return nil
}
thx alot

文件路径有一个功能,可以为您执行以下操作:

package main

import (
    "log"
    "path/filepath"
)

func main() {   
    ok, err := filepath.Match("/user/*", "/user/list")
    log.Print(err)
    log.Print(ok)
    ok, err = filepath.Match("/user/*/*", "/user/list/detail")
    log.Print(err)
    log.Print(ok)
}

游乐场:

在较长的路线上失败,如/user/list/create@user3396016使用此:/user/*/*