MCPcopy Create free account
hub / github.com/google/go-github / checkGoFieldType

Function checkGoFieldType

tools/structfield/structfield.go:251–269  ·  view source on GitHub ↗
(structName, goFieldName, tagType string, field *ast.Field, tokenPos token.Pos, pass *analysis.Pass, allowedTypes map[string]bool, omitempty, omitzero bool)

Source from the content-addressed store, hash-verified

249}
250
251func checkGoFieldType(structName, goFieldName, tagType string, field *ast.Field, tokenPos token.Pos, pass *analysis.Pass, allowedTypes map[string]bool, omitempty, omitzero bool) {
252 if allowedTypes[structName+"."+goFieldName] {
253 return
254 }
255 switch {
256 case omitzero:
257 skipOmitzero := checkAndReportInvalidTypesForOmitzero(structName, tagType, goFieldName, field.Type, tokenPos, pass)
258 if !skipOmitzero {
259 const msg = `the %q field in struct %q uses "omitzero"; remove "omitzero", as it is only allowed with structs, maps, and slices`
260 pass.Reportf(tokenPos, msg, goFieldName, structName)
261 }
262
263 case omitempty:
264 if newFieldType, ok := checkAndReportInvalidTypes(structName, tagType, goFieldName, field.Type, tokenPos, pass); !ok {
265 const msg = `change the %q field type to %q in the struct %q because its %v tag uses "omitempty"`
266 pass.Reportf(tokenPos, msg, goFieldName, newFieldType, structName, tagType)
267 }
268 }
269}
270
271func checkAndReportInvalidTypes(structName, tagType, goFieldName string, fieldType ast.Expr, tokenPos token.Pos, pass *analysis.Pass) (newFieldType string, ok bool) {
272 switch ft := fieldType.(type) {

Callers 1

processTagFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…