//路由注册方案2：从动态实例内Mapper类型字段标签中获取路由信息
182619
func (a *Wrapper) RouteTags() {
	if _, valid := a.Controller.(Initer); !valid {
		a.Server.Core.Logger().Infof("%T is no method Init(*Context),skip.", a.Controller)
		return
	}
	t := reflect.TypeOf(a.Controller)
	e := t.Elem()
	v := reflect.ValueOf(a.Controller)
	ctlPath := e.PkgPath() + ".(*" + e.Name() + ")."
	//github.com/webx-top/{Project}/app/{App}/controller.(*Index).
	ctl := strings.ToLower(e.Name())

	for i := 0; i < e.NumField(); i++ {
		f := e.Field(i)
		if f.Type != mapperType {
			continue
		}
		fn := strings.Title(f.Name)
		name := fn
		m := v.MethodByName(fn)
		if !m.IsValid() {
			continue
		}

		//支持的tag:
		// 1. webx - 路由规则
		// 2. memo - 注释说明
		//webx标签内容支持以下格式：
		// 1、只指定http请求方式，如`webx:"POST|GET"`
		// 2、只指定路由规则，如`webx:"index"`
		// 3、只指定扩展名规则，如`webx:".JSON|XML"`
		// 4、指定以上全部规则，如`webx:"GET|POST.JSON|XML index"`
		tag := e.Field(i).Tag
		tagv := tag.Get("webx")
		methods := []string{}
		extends := []string{}
		var p, w string
		if tagv != "" {
			tags := strings.Split(tagv, " ")
			length := len(tags)
			if length >= 2 { //`webx:"GET|POST /index"`
				w = tags[0]
				p = tags[1]
			} else if length == 1 {
				if matched, _ := regexp.MatchString(`^[A-Z.]+(\|[A-Z]+)*$`, tags[0]); !matched {
					//非全大写字母时，判断为网址规则
					p = tags[0]
				} else { //`webx:"GET|POST"`
					w = tags[0]
				}
			}
		}
		if p == "" {
			p = "/" + f.Name
		} else if p[0] != '/' {
			p = "/" + p
		}
		path := "/" + ctl + p
		met := ""
		ext := ""
		if w != "" {
			me := strings.Split(w, ".")
			met = me[0]
			if len(me) > 1 {
				ext = me[1]
			}
		}
		if met != "" {
			methods = strings.Split(met, "|")
		}
		if ext != "" {
			ext = strings.ToLower(ext)
			extends = strings.Split(ext, "|")
		}
		k := ctlPath + name + "-fm"
		u := a.App.Server.URL.SetByKey(path, k, tag.Get("memo"))
		u.SetExts(extends)
		h := echo.HandlerFunc(func(ctx echo.Context) error {
			c := X(ctx)
			if !u.ValidExt(c.Format) {
				return c.HTML(404, `The contents can not be displayed in this format: `+c.Format)
			}
			v := reflect.New(e)
			ac := v.Interface()
			if err := c.Init(a.App, ac, e.Name(), name); err != nil {
				return err
			}
			if err := ac.(Initer).Init(c); err != nil {
				return err
			}
			if a.HasBefore {
				if err := ac.(Before).Before(); err != nil {
					return err
				}
				if c.Exit {
					return nil
				}
			}
			format := strings.ToUpper(c.Format)
			m := v.MethodByName(fn + `_` + c.Method() + format)
			if !m.IsValid() {
				m = v.MethodByName(fn + `_` + c.Method())
				if !m.IsValid() {
					m = v.MethodByName(fn + `_` + format)
					if !m.IsValid() {
						m = v.MethodByName(fn)
					}
				}
			}
			if r, err := a.SafelyCall(m, []reflect.Value{}); err != nil {
				return err
			} else if len(r) > 0 {
				if err, ok := r[0].Interface().(error); ok && err != nil {
					return c.DisplayError(err.Error())
				}
			}
			if a.HasAfter {
				if c.Exit {
					return nil
				}
				return ac.(After).After()
			}
			return nil
		})
		if len(methods) < 1 {
			a.Webx.Any(path, h)
			for strings.HasSuffix(path, `/index`) {
				path = strings.TrimSuffix(path, `/index`)
				a.Webx.Any(path+`/`, h)
			}
			continue
		}
		a.Webx.Match(methods, path, h)
		for strings.HasSuffix(path, `/index`) {
			path = strings.TrimSuffix(path, `/index`)
			a.Webx.Match(methods, path+`/`, h)
		}
	}
}
670038
func MapsGet(xu *xgbutil.XUtil) (*xproto.GetKeyboardMappingReply,
	*xproto.GetModifierMappingReply) {

	min, max := minMaxKeycodeGet(xu)
	newKeymap, keyErr := xproto.GetKeyboardMapping(xu.Conn(), min,
		byte(max-min+1)).Reply()
	newModmap, modErr := xproto.GetModifierMapping(xu.Conn()).Reply()

	// If there are errors, we really need to panic. We just can't do
	// any key binding without a mapping from the server.
	if keyErr != nil {
		panic(fmt.Sprintf("COULD NOT GET KEYBOARD MAPPING: %v\n"+
			"THIS IS AN UNRECOVERABLE ERROR.\n",
			keyErr))
	}
	if modErr != nil {
		panic(fmt.Sprintf("COULD NOT GET MODIFIER MAPPING: %v\n"+
			"THIS IS AN UNRECOVERABLE ERROR.\n",
			keyErr))
	}

	return newKeymap, newModmap
}
389559
func StructMapToStringMap(m map[string]struct{}) map[string]string {
	newMap := make(map[string]string)
	for k := range m {
		newMap[k] = fmt.Sprintf("%s", m[k])
	}
	return newMap
}
470154
func (m *Method) ToRawInfo() interface{} {
	info := yaml.MapSlice{}
	if m.Id != "" {
		info = append(info, yaml.MapItem{Key: "id", Value: m.Id})
	}
	if m.Path != "" {
		info = append(info, yaml.MapItem{Key: "path", Value: m.Path})
	}
	if m.HttpMethod != "" {
		info = append(info, yaml.MapItem{Key: "httpMethod", Value: m.HttpMethod})
	}
	if m.Description != "" {
		info = append(info, yaml.MapItem{Key: "description", Value: m.Description})
	}
	if m.Parameters != nil {
		info = append(info, yaml.MapItem{Key: "parameters", Value: m.Parameters.ToRawInfo()})
	}
	// &{Name:parameters Type:Parameters StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
	if len(m.ParameterOrder) != 0 {
		info = append(info, yaml.MapItem{Key: "parameterOrder", Value: m.ParameterOrder})
	}
	if m.Request != nil {
		info = append(info, yaml.MapItem{Key: "request", Value: m.Request.ToRawInfo()})
	}
	// &{Name:request Type:Request StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
	if m.Response != nil {
		info = append(info, yaml.MapItem{Key: "response", Value: m.Response.ToRawInfo()})
	}
	// &{Name:response Type:Response StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
	if len(m.Scopes) != 0 {
		info = append(info, yaml.MapItem{Key: "scopes", Value: m.Scopes})
	}
	if m.SupportsMediaDownload != false {
		info = append(info, yaml.MapItem{Key: "supportsMediaDownload", Value: m.SupportsMediaDownload})
	}
	if m.SupportsMediaUpload != false {
		info = append(info, yaml.MapItem{Key: "supportsMediaUpload", Value: m.SupportsMediaUpload})
	}
	if m.UseMediaDownloadService != false {
		info = append(info, yaml.MapItem{Key: "useMediaDownloadService", Value: m.UseMediaDownloadService})
	}
	if m.MediaUpload != nil {
		info = append(info, yaml.MapItem{Key: "mediaUpload", Value: m.MediaUpload.ToRawInfo()})
	}
	// &{Name:mediaUpload Type:MediaUpload StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:}
	if m.SupportsSubscription != false {
		info = append(info, yaml.MapItem{Key: "supportsSubscription", Value: m.SupportsSubscription})
	}
	if m.FlatPath != "" {
		info = append(info, yaml.MapItem{Key: "flatPath", Value: m.FlatPath})
	}
	if m.EtagRequired != false {
		info = append(info, yaml.MapItem{Key: "etagRequired", Value: m.EtagRequired})
	}
	return info
}
1164887
func (o *SAMLConnectorV2) MapAttributes(assertionInfo saml2.AssertionInfo) []string {
	var roles []string
	for _, mapping := range o.Spec.AttributesToRoles {
		for _, attr := range assertionInfo.Values {
			if attr.Name != mapping.Name {
				continue
			}
		mappingLoop:
			for _, value := range attr.Values {
				for _, role := range mapping.Roles {
					outRole, err := utils.ReplaceRegexp(mapping.Value, role, value.Value)
					switch {
					case err != nil:
						if !trace.IsNotFound(err) {
							log.Debugf("Failed to match expression %v, replace with: %v input: %v, err: %v", mapping.Value, role, value.Value, err)
						}
						// if value input did not match, no need to apply
						// to all roles
						continue mappingLoop
					case outRole == "":
						// skip empty role matches
					case outRole != "":
						roles = append(roles, outRole)
					}
				}
			}
		}
	}
	return utils.Deduplicate(roles)
}
509238
func (mmap MarshalMap) StringMap(key string) (map[string]string, error) {
	val, exists := mmap.Value(key)
	if !exists {
		return nil, fmt.Errorf(`"%s" is not set`, key)
	}

	switch val.(type) {
	case map[string]string:
		return val.(map[string]string), nil

	default:
		valueMeta := reflect.ValueOf(val)
		if valueMeta.Kind() != reflect.Map {
			return nil, fmt.Errorf(`"%s" is expected to be a map[string]string but is %T`, key, val)
		}

		result := make(map[string]string)
		for _, keyMeta := range valueMeta.MapKeys() {
			strKey, isString := keyMeta.Interface().(string)
			if !isString {
				return nil, fmt.Errorf(`"%s" is expected to be a map[string]string. Key is not a string`, key)
			}

			value := valueMeta.MapIndex(keyMeta)
			strValue, isString := value.Interface().(string)
			if !isString {
				return nil, fmt.Errorf(`"%s" is expected to be a map[string]string. Value is not a string`, key)
			}

			result[strKey] = strValue
		}

		return result, nil
	}
}
258122
func (f *File) GetMapFlat() map[string]string {
	ret := make(map[string]string)

	for _, section := range f.sections {
		name := section.Name()
		if section.name != "" {
			name = fmt.Sprintf("%s%s", name, DefaultNameKeySeparator)
		}

		for _, key := range section.keys {
			ret[fmt.Sprintf("%s%s", name, key)] = f.ValueManipFunc(section.GetRaw(key))
		}
	}

	return ret
}
1299039
func (mapOp *MapOperation) Map(key string) *MapOperation {
	if mapOp.removeMaps != nil {
		delete(mapOp.removeMaps, key)
	}
	if mapOp.maps == nil {
		mapOp.maps = make(map[string]*MapOperation)
	}

	innerMapOp, ok := mapOp.maps[key]
	if ok {
		return innerMapOp
	}

	innerMapOp = &MapOperation{}
	mapOp.maps[key] = innerMapOp
	return innerMapOp
}
245804
func bindMap(params *Params, name string, typ reflect.Type) reflect.Value {
	var (
		keyType   = typ.Key()
		valueType = typ.Elem()
		resultPtr = reflect.New(reflect.MapOf(keyType, valueType))
		result    = resultPtr.Elem()
	)
	result.Set(reflect.MakeMap(typ))
	if params.JSON != nil {
		// Try to inject the response as a json into the created result
		if err := json.Unmarshal(params.JSON, resultPtr.Interface()); err != nil {
			binderLog.Warn("bindMap: Unable to unmarshal request", "name", name, "error", err)
		}
		return result
	}

	for paramName := range params.Values {
		// The paramName string must start with the value in the "name" parameter,
		// otherwise there is no way the parameter is part of the map
		if !strings.HasPrefix(paramName, name) {
			continue
		}

		suffix := paramName[len(name)+1:]
		fieldName := nextKey(suffix)
		if fieldName != "" {
			fieldName = fieldName[:len(fieldName)-1]
		}
		if !strings.HasPrefix(paramName, name+"["+fieldName+"]") {
			continue
		}

		result.SetMapIndex(BindValue(fieldName, keyType), Bind(params, name+"["+fieldName+"]", valueType))
	}
	return result
}
749736
func (s Session) sessionDataFromMap(key string) (result interface{}, err error) {
	var mapValue map[string]interface{}
	uncastMapValue, found := s[SessionMapKeyName]
	if !found {
		mapValue = map[string]interface{}{}
		s[SessionMapKeyName] = mapValue
	} else if mapValue, found = uncastMapValue.(map[string]interface{}); !found {
		// Unusual means that the value in the session was not expected
		sessionLog.Errorf("Unusual means that the value in the session was not expected", "session", uncastMapValue)
		mapValue = map[string]interface{}{}
		s[SessionMapKeyName] = mapValue
	}

	// Try to extract the key from the map
	result, found = mapValue[key]
	if !found {
		result, err = s.convertSessionData(key, nil)
		if err == nil {
			mapValue[key] = result
		}
	}
	return
}
660581
func (c *Context) QueryMap(key string) map[string]string {
	dicts, _ := c.GetQueryMap(key)
	return dicts
}
1152403
func (f *ConfigFlags) ToRESTMapper() (meta.RESTMapper, error) {
	discoveryClient, err := f.ToDiscoveryClient()
	if err != nil {
		return nil, err
	}

	mapper := restmapper.NewDeferredDiscoveryRESTMapper(discoveryClient)
	expander := restmapper.NewShortcutExpander(mapper, discoveryClient)
	return expander, nil
}
601561
func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error {
	cfg.NameMapper = mapper
	return cfg.ReflectFrom(v)
}
42011
func getMap(data *C.pn_data_t, v interface{}) {
	panicUnless(C.pn_data_type(data) == C.PN_MAP, data, v)
	n := int(C.pn_data_get_map(data)) / 2
	mapValue := reflect.ValueOf(v).Elem()
	mapValue.Set(reflect.MakeMap(mapValue.Type())) // Clear the map
	data.enter(v)
	defer data.exit(v)
	// Allocate re-usable key/val values
	keyType := mapValue.Type().Key()
	keyPtr := reflect.New(keyType)
	valPtr := reflect.New(mapValue.Type().Elem())
	for i := 0; i < n; i++ {
		data.next(v)
		unmarshal(keyPtr.Interface(), data)
		if keyType.Kind() == reflect.Interface && !keyPtr.Elem().Elem().Type().Comparable() {
			doPanicMsg(data, v, fmt.Sprintf("key %#v is not comparable", keyPtr.Elem().Interface()))
		}
		data.next(v)
		unmarshal(valPtr.Interface(), data)
		mapValue.SetMapIndex(keyPtr.Elem(), valPtr.Elem())
	}
}
1057273
func MapsFrom(utd *design.UserTypeDefinition, field string) {
	if f, ok := relationalFieldDefinition(true); ok {
		md := gorma.NewMapDefinition()
		md.RemoteField = field
		md.RemoteType = utd
		f.Mappings[utd.TypeName] = md

	}
}
1152499
func (s *Struct) FillMap(out map[string]interface{}) {
	if out == nil {
		return
	}

	fields := s.structFields()

	for _, field := range fields {
		name := field.Name
		val := s.value.FieldByName(name)
		isSubStruct := false
		var finalVal interface{}

		tagName, tagOpts := parseTag(field.Tag.Get(s.TagName))
		if tagName != "" {
			name = tagName
		}

		// if the value is a zero value and the field is marked as omitempty do
		// not include
		if tagOpts.Has("omitempty") {
			zero := reflect.Zero(val.Type()).Interface()
			current := val.Interface()

			if reflect.DeepEqual(current, zero) {
				continue
			}
		}

		if !tagOpts.Has("omitnested") {
			finalVal = s.nested(val)

			v := reflect.ValueOf(val.Interface())
			if v.Kind() == reflect.Ptr {
				v = v.Elem()
			}

			switch v.Kind() {
			case reflect.Map, reflect.Struct:
				isSubStruct = true
			}
		} else {
			finalVal = val.Interface()
		}

		if tagOpts.Has("string") {
			s, ok := val.Interface().(fmt.Stringer)
			if ok {
				out[name] = s.String()
			}
			continue
		}

		if isSubStruct && (tagOpts.Has("flatten")) {
			for k := range finalVal.(map[string]interface{}) {
				out[k] = finalVal.(map[string]interface{})[k]
			}
		} else {
			out[name] = finalVal
		}
	}
}
827647
func (m *NamedMethod) ToRawInfo() interface{} {
	info := yaml.MapSlice{}
	if m.Name != "" {
		info = append(info, yaml.MapItem{Key: "name", Value: m.Name})
	}
	// &{Name:value Type:Method StringEnumValues:[] MapType: Repeated:false Pattern: Implicit:false Description:Mapped value}
	return info
}