(ptype string, field string)
| 407 | } |
| 408 | |
| 409 | func (model Model) GetFieldIndex(ptype string, field string) (int, error) { |
| 410 | assertion := model["p"][ptype] |
| 411 | |
| 412 | assertion.FieldIndexMutex.RLock() |
| 413 | if index, ok := assertion.FieldIndexMap[field]; ok { |
| 414 | assertion.FieldIndexMutex.RUnlock() |
| 415 | return index, nil |
| 416 | } |
| 417 | assertion.FieldIndexMutex.RUnlock() |
| 418 | |
| 419 | pattern := fmt.Sprintf("%s_"+field, ptype) |
| 420 | index := -1 |
| 421 | for i, token := range assertion.Tokens { |
| 422 | if token == pattern { |
| 423 | index = i |
| 424 | break |
| 425 | } |
| 426 | } |
| 427 | if index == -1 { |
| 428 | return index, fmt.Errorf(field + " index is not set, please use enforcer.SetFieldIndex() to set index") |
| 429 | } |
| 430 | |
| 431 | assertion.FieldIndexMutex.Lock() |
| 432 | assertion.FieldIndexMap[field] = index |
| 433 | assertion.FieldIndexMutex.Unlock() |
| 434 | |
| 435 | return index, nil |
| 436 | } |
no outgoing calls
no test coverage detected