MCPcopy Create free account
hub / github.com/goadesign/goa / extractMetadata

Function extractMetadata

grpc/codegen/service_data.go:1301–1347  ·  view source on GitHub ↗

extractMetadata collects the request/response metadata from the given metadata attribute and service type (payload/result).

(a *expr.MappedAttributeExpr, service *expr.AttributeExpr, scope *codegen.NameScope, services ServicesData)

Source from the content-addressed store, hash-verified

1299// extractMetadata collects the request/response metadata from the given
1300// metadata attribute and service type (payload/result).
1301func extractMetadata(a *expr.MappedAttributeExpr, service *expr.AttributeExpr, scope *codegen.NameScope, services ServicesData) []*MetadataData {
1302 var metadata []*MetadataData
1303 ctx := serviceTypeContext("", scope)
1304 codegen.WalkMappedAttr(a, func(name, elem string, required bool, c *expr.AttributeExpr) error { // nolint: errcheck
1305 arr := expr.AsArray(c.Type)
1306 mp := expr.AsMap(c.Type)
1307 typeRef := scope.GoTypeRef(unalias(c))
1308 ft := service.Type
1309 varn := scope.Name(codegen.Goify(name, false))
1310 fieldName := codegen.Goify(name, true)
1311 var pointer bool
1312 if !expr.IsObject(service.Type) {
1313 fieldName = ""
1314 } else {
1315 pointer = service.IsPrimitivePointer(name, true)
1316 ft = service.Find(name).Type
1317 }
1318 if pointer {
1319 typeRef = "*" + typeRef
1320 }
1321 metadata = append(metadata, &MetadataData{
1322 Name: elem,
1323 AttributeName: name,
1324 Description: c.Description,
1325 FieldName: fieldName,
1326 FieldType: ft,
1327 VarName: varn,
1328 Required: required,
1329 Type: c.Type,
1330 TypeName: scope.GoTypeName(unalias(c)),
1331 TypeRef: typeRef,
1332 Pointer: pointer,
1333 Slice: arr != nil,
1334 StringSlice: arr != nil && arr.ElemType.Type.Kind() == expr.StringKind,
1335 Map: mp != nil,
1336 MapStringSlice: mp != nil &&
1337 mp.KeyType.Type.Kind() == expr.StringKind &&
1338 mp.ElemType.Type.Kind() == expr.ArrayKind &&
1339 expr.AsArray(mp.ElemType.Type).ElemType.Type.Kind() == expr.StringKind,
1340 Validate: codegen.AttributeValidationCode(c, nil, ctx, required, false, varn, name),
1341 DefaultValue: c.DefaultValue,
1342 Example: c.Example(services.Root.API.ExampleGenerator),
1343 })
1344 return nil
1345 })
1346 return metadata
1347}
1348
1349// usesStreamEnvelope reports whether the transport needs a typed stream
1350// envelope to carry both the one-shot method payload and streaming payload

Callers 1

analyzeMethod · 0.85

Calls 15

WalkMappedAttrFunction · 0.92
AsArrayFunction · 0.92
AsMapFunction · 0.92
GoifyFunction · 0.92
IsObjectFunction · 0.92
AttributeValidationCodeFunction · 0.92
serviceTypeContextFunction · 0.85
GoTypeRefMethod · 0.80
FindMethod · 0.80
GoTypeNameMethod · 0.80
unaliasFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected