當前位置: 首頁>>代碼示例>>Golang>>正文


Golang autorest.PreparerFunc函數代碼示例

本文整理匯總了Golang中github.com/Azure/go-autorest/autorest.PreparerFunc函數的典型用法代碼示例。如果您正苦於以下問題:Golang PreparerFunc函數的具體用法?Golang PreparerFunc怎麽用?Golang PreparerFunc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了PreparerFunc函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: WithAuthorization

func (mfa mockFailingAuthorizer) WithAuthorization() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			return r, fmt.Errorf("ERROR: mockFailingAuthorizer returned expected error")
		})
	}
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:7,代碼來源:azure_test.go

示例2: WithAuthorization

// WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose
// value is "Bearer " followed by the AccessToken of the Token.
func (t *Token) WithAuthorization() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			return (autorest.WithBearerAuthorization(t.AccessToken)(p)).Prepare(r)
		})
	}
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:9,代碼來源:token.go

示例3: RequestRecorder

// RequestRecorder returns an autorest.PrepareDecorator that records requests
// to ghe given slice.
func RequestRecorder(requests *[]*http.Request) autorest.PrepareDecorator {
	if requests == nil {
		return nil
	}
	var mu sync.Mutex
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(req *http.Request) (*http.Request, error) {
			// Save the request body, since it will be consumed.
			reqCopy := *req
			if req.Body != nil {
				var buf bytes.Buffer
				if _, err := buf.ReadFrom(req.Body); err != nil {
					return nil, err
				}
				if err := req.Body.Close(); err != nil {
					return nil, err
				}
				reqCopy.Body = ioutil.NopCloser(&buf)
				req.Body = ioutil.NopCloser(bytes.NewReader(buf.Bytes()))
			}
			mu.Lock()
			*requests = append(*requests, &reqCopy)
			mu.Unlock()
			return req, nil
		})
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:29,代碼來源:recorder.go

示例4: withInspection

func withInspection() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			fmt.Printf("Inspecting Request: %s %s\n", r.Method, r.URL)
			return p.Prepare(r)
		})
	}
}
開發者ID:daemonfire300,項目名稱:azure-sdk-for-go,代碼行數:8,代碼來源:check.go

示例5: WithInspection

func (mi *mockInspector) WithInspection() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			mi.wasInvoked = true
			return p.Prepare(r)
		})
	}
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:8,代碼來源:azure_test.go

示例6: withErrorPrepareDecorator

func withErrorPrepareDecorator(e *error) autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			*e = fmt.Errorf("azure: Faux Prepare Error")
			return r, *e
		})
	}
}
開發者ID:Azure,項目名稱:go-autorest,代碼行數:8,代碼來源:azure_test.go

示例7: withInspection

func withInspection() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			log.Debug("Azure request", logutil.Fields{
				"method":  r.Method,
				"request": r.URL.String(),
			})
			return p.Prepare(r)
		})
	}
}
開發者ID:RaulKite,項目名稱:machine,代碼行數:11,代碼來源:inspector.go

示例8: WithAuthorization

// WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose
// value is "Bearer " followed by the AccessToken of the ServicePrincipalToken.
//
// By default, the token will automatically refresh if nearly expired (as determined by the
// RefreshWithin interval). Use the AutoRefresh method to enable or disable automatically refreshing
// tokens.
func (spt *ServicePrincipalToken) WithAuthorization() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			if spt.autoRefresh {
				err := spt.EnsureFresh()
				if err != nil {
					return r, fmt.Errorf("azure: Failed to refresh Service Principal Token for request to %s (%v)", r.URL, err)
				}
			}
			return (autorest.WithBearerAuthorization(spt.AccessToken)(p)).Prepare(r)
		})
	}
}
開發者ID:oaastest,項目名稱:go-autorest,代碼行數:19,代碼來源:token.go

示例9: WithAuthorization

// WithAuthorization is part of the autorest.Authorizer interface.
func (c *cloudSpecAuth) WithAuthorization() autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			r, err := p.Prepare(r)
			if err != nil {
				return nil, err
			}
			token, err := c.getToken()
			if err != nil {
				return nil, err
			}
			return autorest.CreatePreparer(token.WithAuthorization()).Prepare(r)
		})
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:16,代碼來源:auth.go

示例10: withInspection

func withInspection(maxlen int64) autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			body, bodyString := handleBody(r.Body, maxlen)
			r.Body = body

			log.Print("Azure request", logutil.Fields{
				"method":  r.Method,
				"request": r.URL.String(),
				"body":    bodyString,
			})
			return p.Prepare(r)
		})
	}
}
開發者ID:boumenot,項目名稱:packer,代碼行數:15,代碼來源:inspector.go

示例11: WithReturningClientID

// WithReturningClientID returns a PrepareDecorator that adds an HTTP extension header of
// x-ms-client-request-id whose value is the passed, undecorated UUID (e.g.,
// "0F39878C-5F76-4DB8-A25D-61D2C193C3CA"). It also sets the x-ms-return-client-request-id
// header to true such that UUID accompanies the http.Response.
func WithReturningClientID(uuid string) autorest.PrepareDecorator {
	preparer := autorest.CreatePreparer(
		WithClientID(uuid),
		WithReturnClientID(true))

	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			r, err := p.Prepare(r)
			if err != nil {
				return r, err
			}
			return preparer.Prepare(r)
		})
	}
}
開發者ID:RaulKite,項目名稱:machine,代碼行數:19,代碼來源:azure.go

示例12: PrepareDecorator

// PrepareDecorator returns an autorest.PrepareDecorator that
// logs requests at trace level.
func PrepareDecorator(logger loggo.Logger) autorest.PrepareDecorator {
	return func(p autorest.Preparer) autorest.Preparer {
		return autorest.PreparerFunc(func(r *http.Request) (*http.Request, error) {
			if logger.IsTraceEnabled() {
				dump, err := httputil.DumpRequest(r, true)
				if err != nil {
					logger.Tracef("failed to dump request: %v", err)
					logger.Tracef("%+v", r)
				} else {
					logger.Tracef("%s", dump)
				}
			}
			return p.Prepare(r)
		})
	}
}
開發者ID:bac,項目名稱:juju,代碼行數:18,代碼來源:tracing.go


注:本文中的github.com/Azure/go-autorest/autorest.PreparerFunc函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。