Package rest provides RESTful serialization of AWS requests and responses.
package rest

import (
	
	
	
	
	
	
	
	
	
	
	

	
	
	
	
)
Whether the byte value can be sent without escaping in AWS URLs
var noEscape [256]bool

var errValueNotSet = fmt.Errorf("value not set")

var byteSliceType = reflect.TypeOf([]byte{})

func () {
AWS expects every character except these to be escaped
		noEscape[] = ( >= 'A' &&  <= 'Z') ||
			( >= 'a' &&  <= 'z') ||
			( >= '0' &&  <= '9') ||
			 == '-' ||
			 == '.' ||
			 == '_' ||
			 == '~'
	}
}
BuildHandler is a named request handler for building rest protocol requests
var BuildHandler = request.NamedHandler{Name: "awssdk.rest.Build", Fn: Build}
Build builds the REST component of a service request.
BuildAsGET builds the REST component of a service request with the ability to hoist data from the body.
Setup the raw path to match the base path pattern. This is needed so that when the path is mutated a custom escaped version can be stored in RawPath that will be used by the Go client.
	.HTTPRequest.URL.RawPath = .HTTPRequest.URL.Path

	for  := 0;  < .NumField(); ++ {
		 := .Field()
		if  := .Type().Field().Name; [0:1] == strings.ToLower([0:1]) {
			continue
		}

		if .IsValid() {
			 := .Type().Field()
			 := .Tag.Get("locationName")
			if  == "" {
				 = .Name
			}
			if  := .Kind();  == reflect.Ptr {
				 = .Elem()
			} else if  == reflect.Interface {
				if !.Elem().IsValid() {
					continue
				}
			}
			if !.IsValid() {
				continue
			}
			if .Tag.Get("ignore") != "" {
				continue
			}
Support the ability to customize values to be marshaled as a blob even though they were modeled as a string. Required for S3 API operations like SSECustomerKey is modeled as stirng but required to be base64 encoded in request.
			if .Tag.Get("marshal-as") == "blob" {
				 = .Convert(byteSliceType)
			}

			var  error
			switch .Tag.Get("location") {
			case "headers": // header maps
				 = buildHeaderMap(&.HTTPRequest.Header, , .Tag)
			case "header":
				 = buildHeader(&.HTTPRequest.Header, , , .Tag)
			case "uri":
				 = buildURI(.HTTPRequest.URL, , , .Tag)
			case "querystring":
				 = buildQueryString(, , , .Tag)
			default:
				if  {
					 = buildQueryString(, , , .Tag)
				}
			}
			.Error = 
		}
		if .Error != nil {
			return
		}
	}

	.HTTPRequest.URL.RawQuery = .Encode()
	if !aws.BoolValue(.Config.DisableRestProtocolURICleaning) {
		cleanPath(.HTTPRequest.URL)
	}
}

func ( *request.Request,  reflect.Value) {
	if ,  := .Type().FieldByName("_");  {
		if  := .Tag.Get("payload");  != "" {
			,  := .Type().FieldByName()
			if  := .Tag.Get("type");  != "" &&  != "structure" {
				 := reflect.Indirect(.FieldByName())
				if .IsValid() && .Interface() != nil {
					switch reader := .Interface().(type) {
					case io.ReadSeeker:
						.SetReaderBody()
					case []byte:
						.SetBufferBody()
					case string:
						.SetStringBody()
					default:
						.Error = awserr.New(request.ErrCodeSerialization,
							"failed to encode REST request",
							fmt.Errorf("unknown payload type %s", .Type()))
					}
				}
			}
		}
	}
}

func ( *http.Header,  reflect.Value,  string,  reflect.StructTag) error {
	,  := convertType(, )
	if  == errValueNotSet {
		return nil
	} else if  != nil {
		return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", )
	}

	 = strings.TrimSpace()
	 = strings.TrimSpace()

	.Add(, )

	return nil
}

func ( *http.Header,  reflect.Value,  reflect.StructTag) error {
	 := .Get("locationName")
	for ,  := range .MapKeys() {
		,  := convertType(.MapIndex(), )
		if  == errValueNotSet {
			continue
		} else if  != nil {
			return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", )

		}
		 := strings.TrimSpace(.String())
		 = strings.TrimSpace()

		.Add(+, )
	}
	return nil
}

func ( *url.URL,  reflect.Value,  string,  reflect.StructTag) error {
	,  := convertType(, )
	if  == errValueNotSet {
		return nil
	} else if  != nil {
		return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", )
	}

	.Path = strings.Replace(.Path, "{"++"}", , -1)
	.Path = strings.Replace(.Path, "{"++"+}", , -1)

	.RawPath = strings.Replace(.RawPath, "{"++"}", EscapePath(, true), -1)
	.RawPath = strings.Replace(.RawPath, "{"++"+}", EscapePath(, false), -1)

	return nil
}

func ( url.Values,  reflect.Value,  string,  reflect.StructTag) error {
	switch value := .Interface().(type) {
	case []*string:
		for ,  := range  {
			.Add(, *)
		}
	case map[string]*string:
		for ,  := range  {
			.Add(, *)
		}
	case map[string][]*string:
		for ,  := range  {
			for ,  := range  {
				.Add(, *)
			}
		}
	default:
		,  := convertType(, )
		if  == errValueNotSet {
			return nil
		} else if  != nil {
			return awserr.New(request.ErrCodeSerialization, "failed to encode REST request", )
		}
		.Set(, )
	}

	return nil
}

func ( *url.URL) {
	 := strings.HasSuffix(.Path, "/")
clean up path, removing duplicate `/`
	.Path = path.Clean(.Path)
	.RawPath = path.Clean(.RawPath)

	if  && !strings.HasSuffix(.Path, "/") {
		.Path += "/"
		.RawPath += "/"
	}
}
EscapePath escapes part of a URL path in Amazon style
func ( string,  bool) string {
	var  bytes.Buffer
	for  := 0;  < len(); ++ {
		 := []
		if noEscape[] || ( == '/' && !) {
			.WriteByte()
		} else {
			fmt.Fprintf(&, "%%%02X", )
		}
	}
	return .String()
}

func ( reflect.Value,  reflect.StructTag) ( string,  error) {
	 = reflect.Indirect()
	if !.IsValid() {
		return "", errValueNotSet
	}

	switch value := .Interface().(type) {
	case string:
		 = 
	case []byte:
		 = base64.StdEncoding.EncodeToString()
	case bool:
		 = strconv.FormatBool()
	case int64:
		 = strconv.FormatInt(, 10)
	case float64:
		 = strconv.FormatFloat(, 'f', -1, 64)
	case time.Time:
		 := .Get("timestampFormat")
		if len() == 0 {
			 = protocol.RFC822TimeFormatName
			if .Get("location") == "querystring" {
				 = protocol.ISO8601TimeFormatName
			}
		}
		 = protocol.FormatTime(, )
	case aws.JSONValue:
		if len() == 0 {
			return "", errValueNotSet
		}
		 := protocol.NoEscape
		if .Get("location") == "header" {
			 = protocol.Base64Escape
		}
		,  = protocol.EncodeJSONValue(, )
		if  != nil {
			return "", fmt.Errorf("unable to encode JSONValue, %v", )
		}
	default:
		 := fmt.Errorf("unsupported value for param %v (%s)", .Interface(), .Type())
		return "", 
	}
	return , nil