本文整理汇总了Golang中github.com/kingsoft-avteam/aws-sdk-go/aws.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Build
// Build builds the REST component of a service request.
func Build(r *aws.Request) {
if r.ParamsFilled() {
v := reflect.ValueOf(r.Params).Elem()
buildLocationElements(r, v)
buildBody(r, v)
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:8,代码来源:build.go
示例2: UnmarshalError
// UnmarshalError unmarshals a response error for the REST JSON protocol.
func UnmarshalError(r *aws.Request) {
code := r.HTTPResponse.Header.Get("X-Amzn-Errortype")
bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = apierr.New("Unmarshal", "failed reading REST JSON error response", err)
return
}
if len(bodyBytes) == 0 {
r.Error = apierr.NewRequestError(
apierr.New("Unmarshal", r.HTTPResponse.Status, nil),
r.HTTPResponse.StatusCode,
"",
)
return
}
var jsonErr jsonErrorResponse
if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
r.Error = apierr.New("Unmarshal", "failed decoding REST JSON error response", err)
return
}
if code == "" {
code = jsonErr.Code
}
codes := strings.SplitN(code, ":", 2)
r.Error = apierr.NewRequestError(
apierr.New(codes[0], jsonErr.Message, nil),
r.HTTPResponse.StatusCode,
"",
)
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:33,代码来源:restjson.go
示例3: Build
// Build builds a JSON payload for a JSON RPC request.
func Build(req *aws.Request) {
var buf []byte
var err error
if req.ParamsFilled() {
buf, err = jsonutil.BuildJSON(req.Params)
if err != nil {
req.Error = apierr.New("Marshal", "failed encoding JSON RPC request", err)
return
}
} else {
buf = emptyJSON
}
if req.Service.TargetPrefix != "" || string(buf) != "{}" {
req.SetBufferBody(buf)
}
if req.Service.TargetPrefix != "" {
target := req.Service.TargetPrefix + "." + req.Operation.Name
req.HTTPRequest.Header.Add("X-Amz-Target", target)
}
if req.Service.JSONVersion != "" {
jsonVersion := req.Service.JSONVersion
req.HTTPRequest.Header.Add("Content-Type", "application/x-amz-json-"+jsonVersion)
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:27,代码来源:jsonrpc.go
示例4: unmarshalError
func unmarshalError(r *aws.Request) {
defer r.HTTPResponse.Body.Close()
if r.HTTPResponse.ContentLength == int64(0) {
// No body, use status code to generate an awserr.Error
r.Error = apierr.NewRequestError(
apierr.New(strings.Replace(r.HTTPResponse.Status, " ", "", -1), r.HTTPResponse.Status, nil),
r.HTTPResponse.StatusCode,
"",
)
return
}
resp := &xmlErrorResponse{}
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
if err != nil && err != io.EOF {
r.Error = apierr.New("Unmarshal", "failed to decode S3 XML error response", nil)
} else {
r.Error = apierr.NewRequestError(
apierr.New(resp.Code, resp.Message, nil),
r.HTTPResponse.StatusCode,
"",
)
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:25,代码来源:unmarshal_error.go
示例5: UnmarshalError
// UnmarshalError unmarshals an error response for a JSON RPC service.
func UnmarshalError(req *aws.Request) {
defer req.HTTPResponse.Body.Close()
bodyBytes, err := ioutil.ReadAll(req.HTTPResponse.Body)
if err != nil {
req.Error = apierr.New("Unmarshal", "failed reading JSON RPC error response", err)
return
}
if len(bodyBytes) == 0 {
req.Error = apierr.NewRequestError(
apierr.New("Unmarshal", req.HTTPResponse.Status, nil),
req.HTTPResponse.StatusCode,
"",
)
return
}
var jsonErr jsonErrorResponse
if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
req.Error = apierr.New("Unmarshal", "failed decoding JSON RPC error response", err)
return
}
codes := strings.SplitN(jsonErr.Code, "#", 2)
req.Error = apierr.NewRequestError(
apierr.New(codes[len(codes)-1], jsonErr.Message, nil),
req.HTTPResponse.StatusCode,
"",
)
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:29,代码来源:jsonrpc.go
示例6: assertMD5
func assertMD5(t *testing.T, req *aws.Request) {
err := req.Build()
assert.NoError(t, err)
b, _ := ioutil.ReadAll(req.HTTPRequest.Body)
out := md5.Sum(b)
assert.NotEmpty(t, b)
assert.Equal(t, base64.StdEncoding.EncodeToString(out[:]), req.HTTPRequest.Header.Get("Content-MD5"))
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:9,代码来源:customizations_test.go
示例7: Unmarshal
// Unmarshal unmarshals a response for a JSON RPC service.
func Unmarshal(req *aws.Request) {
defer req.HTTPResponse.Body.Close()
if req.DataFilled() {
err := jsonutil.UnmarshalJSON(req.Data, req.HTTPResponse.Body)
if err != nil {
req.Error = apierr.New("Unmarshal", "failed decoding JSON RPC response", err)
}
}
return
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:11,代码来源:jsonrpc.go
示例8: Unmarshal
// Unmarshal unmarshals a response for an AWS Query service.
func Unmarshal(r *aws.Request) {
defer r.HTTPResponse.Body.Close()
if r.DataFilled() {
decoder := xml.NewDecoder(r.HTTPResponse.Body)
err := xmlutil.UnmarshalXML(r.Data, decoder, r.Operation.Name+"Result")
if err != nil {
r.Error = apierr.New("Unmarshal", "failed decoding Query response", err)
return
}
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:12,代码来源:unmarshal.go
示例9: populateLocationConstraint
func populateLocationConstraint(r *aws.Request) {
if r.ParamsFilled() && r.Config.Region != "us-east-1" {
in := r.Params.(*CreateBucketInput)
if in.CreateBucketConfiguration == nil {
r.Params = awsutil.CopyOf(r.Params)
in = r.Params.(*CreateBucketInput)
in.CreateBucketConfiguration = &CreateBucketConfiguration{
LocationConstraint: &r.Config.Region,
}
}
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:12,代码来源:bucket_location.go
示例10: Build
// Build builds a request payload for the REST XML protocol.
func Build(r *aws.Request) {
rest.Build(r)
if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
var buf bytes.Buffer
err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf))
if err != nil {
r.Error = apierr.New("Marshal", "failed to enode rest XML request", err)
return
}
r.SetBufferBody(buf.Bytes())
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:14,代码来源:restxml.go
示例11: UnmarshalError
// UnmarshalError unmarshals a response error for the EC2 protocol.
func UnmarshalError(r *aws.Request) {
defer r.HTTPResponse.Body.Close()
resp := &xmlErrorResponse{}
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
if err != nil && err != io.EOF {
r.Error = apierr.New("Unmarshal", "failed decoding EC2 Query error response", err)
} else {
r.Error = apierr.NewRequestError(
apierr.New(resp.Code, resp.Message, nil),
r.HTTPResponse.StatusCode,
resp.RequestID,
)
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:16,代码来源:unmarshal.go
示例12: Sign
func Sign(req *aws.Request) {
if req.Service.Config.Credentials == credentials.AnonymousCredentials {
return
}
region := req.Service.SigningRegion
if region == "" {
region = req.Service.Config.Region
}
name := req.Service.SigningName
if name == "" {
name = req.Service.ServiceName
}
s := signer{
Service: req.Service,
Request: req.HTTPRequest,
Time: req.Time,
ExpireTime: req.ExpireTime,
Query: req.HTTPRequest.URL.Query(),
Body: req.Body,
ServiceName: name,
Region: region,
Credentials: req.Service.Config.Credentials,
Debug: req.Service.Config.LogLevel,
Logger: req.Service.Config.Logger,
}
req.Error = s.sign()
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:31,代码来源:v2.go
示例13: buildGetBucketLocation
func buildGetBucketLocation(r *aws.Request) {
if r.DataFilled() {
out := r.Data.(*GetBucketLocationOutput)
b, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = apierr.New("Unmarshal", "failed reading response body", err)
return
}
match := reBucketLocation.FindSubmatch(b)
if len(match) > 1 {
loc := string(match[1])
out.LocationConstraint = &loc
}
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:16,代码来源:bucket_location.go
示例14: Sign
// Sign requests with signature version 4.
//
// Will sign the requests with the service config's Credentials object
// Signing is skipped if the credentials is the credentials.AnonymousCredentials
// object.
func Sign(req *aws.Request) {
// If the request does not need to be signed ignore the signing of the
// request if the AnonymousCredentials object is used.
if req.Service.Config.Credentials == credentials.AnonymousCredentials {
return
}
region := req.Service.SigningRegion
if region == "" {
region = req.Service.Config.Region
}
name := req.Service.SigningName
if name == "" {
name = req.Service.ServiceName
}
s := signer{
Request: req.HTTPRequest,
Time: req.Time,
ExpireTime: req.ExpireTime,
Query: req.HTTPRequest.URL.Query(),
Body: req.Body,
ServiceName: name,
Region: region,
Credentials: req.Service.Config.Credentials,
Debug: req.Service.Config.LogLevel,
Logger: req.Service.Config.Logger,
}
req.Error = s.sign()
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:37,代码来源:v4.go
示例15: buildQueryString
func buildQueryString(r *aws.Request, v reflect.Value, name string, query url.Values) {
str, err := convertType(v)
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if str != nil {
query.Set(name, *str)
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:8,代码来源:build.go
示例16: buildHeader
func buildHeader(r *aws.Request, v reflect.Value, name string) {
str, err := convertType(v)
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if str != nil {
r.HTTPRequest.Header.Add(name, *str)
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:8,代码来源:build.go
示例17: validateSSERequiresSSL
func validateSSERequiresSSL(r *aws.Request) {
if /*r.HTTPRequest.URL.Scheme != "https"*/ false {
p := awsutil.ValuesAtPath(r.Params, "SSECustomerKey||CopySourceSSECustomerKey")
if len(p) > 0 {
r.Error = errSSERequiresSSL
}
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:8,代码来源:sse.go
示例18: buildHeaderMap
func buildHeaderMap(r *aws.Request, v reflect.Value, prefix string) {
for _, key := range v.MapKeys() {
str, err := convertType(v.MapIndex(key))
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if str != nil {
r.HTTPRequest.Header.Add(prefix+key.String(), *str)
}
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:10,代码来源:build.go
示例19: buildURI
func buildURI(r *aws.Request, v reflect.Value, name string) {
value, err := convertType(v)
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if value != nil {
uri := r.HTTPRequest.URL.Path
uri = strings.Replace(uri, "{"+name+"}", EscapePath(*value, true), -1)
uri = strings.Replace(uri, "{"+name+"+}", EscapePath(*value, false), -1)
r.HTTPRequest.URL.Path = uri
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:11,代码来源:build.go
示例20: Unmarshal
// Unmarshal unmarshals a payload response for the REST XML protocol.
func Unmarshal(r *aws.Request) {
if t := rest.PayloadType(r.Data); t == "structure" || t == "" {
defer r.HTTPResponse.Body.Close()
decoder := xml.NewDecoder(r.HTTPResponse.Body)
err := xmlutil.UnmarshalXML(r.Data, decoder, "")
if err != nil {
r.Error = apierr.New("Unmarshal", "failed to decode REST XML response", err)
return
}
}
}
开发者ID:kingsoft-avteam,项目名称:aws-sdk-go,代码行数:12,代码来源:restxml.go
注:本文中的github.com/kingsoft-avteam/aws-sdk-go/aws.Request类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论