extractPythonNameFieldTag parses a struct field tag and returns a new python name. If the tag is not defined then the original name is returned. If the tag name is specified but is an invalid python identifier, then an error is returned.
(gname, tag string)
| 272 | // If the tag name is specified but is an invalid python identifier, |
| 273 | // then an error is returned. |
| 274 | func extractPythonNameFieldTag(gname, tag string) (string, error) { |
| 275 | const tagKey = "gopy" |
| 276 | if tag == "" { |
| 277 | return gname, nil |
| 278 | } |
| 279 | tagVal := reflect.StructTag(tag).Get(tagKey) |
| 280 | if tagVal == "" { |
| 281 | return gname, nil |
| 282 | } |
| 283 | if !isValidPythonName(tagVal) { |
| 284 | return "", fmt.Errorf("gopy: invalid identifier for struct field tag: %s", tagVal) |
| 285 | } |
| 286 | return tagVal, nil |
| 287 | } |
| 288 | |
| 289 | // isValidPythonName returns true if the string is a valid |
| 290 | // python identifier name |
no test coverage detected