本文整理匯總了Golang中github.com/pomack/oauth2_client/go/oauth2_client.OAuth2Client.Initialize方法的典型用法代碼示例。如果您正苦於以下問題:Golang OAuth2Client.Initialize方法的具體用法?Golang OAuth2Client.Initialize怎麽用?Golang OAuth2Client.Initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pomack/oauth2_client/go/oauth2_client.OAuth2Client
的用法示例。
在下文中一共展示了OAuth2Client.Initialize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleGenericOauthTestRequest
func HandleGenericOauthTestRequest(w http.ResponseWriter, req *http.Request, c oauth2_client.OAuth2Client, method, test_url_property, body string, useTemplate *template.Template) {
props := getProperties()
if req.Method == oauth2_client.POST {
if err := req.ParseForm(); err != nil {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(500)
io.WriteString(w, "Unable to parse form:\n\n")
io.WriteString(w, err.Error())
return
}
for k, arr := range req.Form {
for _, v := range arr {
props.Set(k, v)
}
}
}
for k, arr := range req.URL.Query() {
for _, v := range arr {
props.Set(k, v)
}
}
c.Initialize(props)
uri := props.GetAsString(test_url_property)
log.Printf("Client is: %T -> %#v", c, c)
var reader io.Reader = nil
if len(body) > 0 {
reader = bytes.NewBufferString(body)
}
resp, _, err := oauth2_client.AuthorizedRequest(c, method, nil, uri, nil, reader)
m := make(map[string]interface{})
isError := false
m["c"] = c
m["url"] = uri
if err != nil {
m["output"] = err.Error()
isError = true
} else {
b, err := httputil.DumpResponse(resp, true)
if err != nil {
m["output"] = err.Error()
isError = true
} else {
m["output"] = string(b)
}
}
if isError {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(500)
} else {
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(200)
}
err = useTemplate.Execute(w, m)
if err != nil {
oauth2_client.LogErrorf("Error: %T %v", err, err)
}
}