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

Method extractHeaders

http/codegen/service_data.go:2578–2639  ·  view source on GitHub ↗
(a *expr.MappedAttributeExpr, svcAtt *expr.AttributeExpr, svcCtx *codegen.AttributeContext, scope *codegen.NameScope)

Source from the content-addressed store, hash-verified

2576}
2577
2578func (sds *ServicesData) extractHeaders(a *expr.MappedAttributeExpr, svcAtt *expr.AttributeExpr, svcCtx *codegen.AttributeContext, scope *codegen.NameScope) []*HeaderData {
2579 var headers []*HeaderData
2580 codegen.WalkMappedAttr(a, func(name, elem string, required bool, _ *expr.AttributeExpr) error { // nolint: errcheck
2581 var attr *expr.AttributeExpr
2582 if attr = svcAtt.Find(name); attr == nil {
2583 attr = svcAtt
2584 }
2585 var hattr *expr.AttributeExpr
2586 var stringSlice bool
2587 // The StringSlice field of ParamData must be false for aliased primitive types
2588 if arr := expr.AsArray(attr.Type); arr != nil {
2589 stringSlice = arr.ElemType.Type.Kind() == expr.StringKind
2590 }
2591
2592 hattr = makeHTTPType(attr)
2593 var (
2594 varn = scope.Name(codegen.Goify(name, false))
2595 arr = expr.AsArray(hattr.Type)
2596 typeRef = scope.GoTypeRef(hattr)
2597 ft = attr.Type
2598
2599 fieldName string
2600 pointer bool
2601 fptr bool
2602 )
2603 pointer = a.IsPrimitivePointer(name, true)
2604 if expr.IsObject(svcAtt.Type) {
2605 fieldName = codegen.GoifyAtt(attr, name, true)
2606 fptr = svcCtx.IsPrimitivePointer(name, svcAtt)
2607 }
2608 if pointer {
2609 typeRef = "*" + typeRef
2610 }
2611 headers = append(headers, &HeaderData{
2612 CanonicalName: http.CanonicalHeaderKey(elem),
2613 Element: &Element{
2614 HTTPName: elem,
2615 Slice: arr != nil,
2616 StringSlice: stringSlice,
2617 AttributeName: name,
2618 AttributeData: &AttributeData{
2619 Name: name,
2620 Description: hattr.Description,
2621 FieldName: fieldName,
2622 FieldPointer: fptr,
2623 FieldType: ft,
2624 VarName: varn,
2625 TypeName: scope.GoTypeName(hattr),
2626 TypeRef: typeRef,
2627 Required: required,
2628 Pointer: pointer,
2629 Type: hattr.Type,
2630 Validate: codegen.AttributeValidationCode(hattr, nil, svcCtx, required, expr.IsAlias(hattr.Type), varn, name),
2631 DefaultValue: hattr.DefaultValue,
2632 Example: hattr.Example(sds.Root.API.ExampleGenerator),
2633 },
2634 },
2635 })

Callers 3

buildPayloadDataMethod · 0.95
buildResponsesMethod · 0.95
buildErrorsDataMethod · 0.95

Calls 15

ExampleMethod · 0.95
WalkMappedAttrFunction · 0.92
AsArrayFunction · 0.92
GoifyFunction · 0.92
IsObjectFunction · 0.92
GoifyAttFunction · 0.92
AttributeValidationCodeFunction · 0.92
IsAliasFunction · 0.92
makeHTTPTypeFunction · 0.85
FindMethod · 0.80
GoTypeRefMethod · 0.80
GoTypeNameMethod · 0.80

Tested by

no test coverage detected