github.com/aavshr/aws-sdk-go@v1.41.3/private/model/api/endpoint_trait.go (about)

     1  //go:build codegen
     2  // +build codegen
     3  
     4  package api
     5  
     6  import (
     7  	"fmt"
     8  	"text/template"
     9  )
    10  
    11  func setupEndpointHostPrefix(op *Operation) {
    12  	op.API.AddSDKImport("private/protocol")
    13  
    14  	buildHandler := fmt.Sprintf("protocol.NewHostPrefixHandler(%q, ",
    15  		op.Endpoint.HostPrefix)
    16  
    17  	if op.InputRef.Shape.HasHostLabelMembers() {
    18  		buildHandler += "input.hostLabels"
    19  	} else {
    20  		buildHandler += "nil"
    21  	}
    22  
    23  	buildHandler += ")"
    24  
    25  	op.CustomBuildHandlers = append(op.CustomBuildHandlers,
    26  		buildHandler,
    27  		"protocol.ValidateEndpointHostHandler",
    28  	)
    29  }
    30  
    31  // HasHostLabelMembers returns true if the shape contains any members which are
    32  // decorated with the hostLabel trait.
    33  func (s *Shape) HasHostLabelMembers() bool {
    34  	for _, ref := range s.MemberRefs {
    35  		if ref.HostLabel {
    36  			return true
    37  		}
    38  	}
    39  
    40  	return false
    41  }
    42  
    43  var hostLabelsShapeTmpl = template.Must(
    44  	template.New("hostLabelsShapeTmpl").
    45  		Parse(hostLabelsShapeTmplDef),
    46  )
    47  
    48  const hostLabelsShapeTmplDef = `
    49  {{- define "hostLabelsShapeTmpl" }}
    50  func (s *{{ $.ShapeName }}) hostLabels() map[string]string {
    51  	return map[string]string{
    52  	{{- range $name, $ref := $.MemberRefs }}
    53  		{{- if $ref.HostLabel }}
    54  		"{{ $name }}": aws.StringValue(s.{{ $name }}),
    55  		{{- end }}
    56  	{{- end }}
    57  	}
    58  }
    59  {{- end }}
    60  `