本文整理汇总了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)
}
}