本文整理汇总了Golang中github.com/parnurzeal/gorequest.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: runRevokeTokenTest
func runRevokeTokenTest(t *testing.T, strategy oauth2.AccessTokenStrategy) {
f := compose.Compose(new(compose.Config), fositeStore, strategy, compose.OAuth2ClientCredentialsGrantFactory, compose.OAuth2TokenIntrospectionFactory, compose.OAuth2TokenRevocationFactory)
ts := mockServer(t, f, &fosite.DefaultSession{})
defer ts.Close()
oauthClient := newOAuth2AppClient(ts)
token, err := oauthClient.Token(goauth.NoContext)
assert.Nil(t, err)
resp, _, errs := gorequest.New().Post(ts.URL+"/revoke").
SetBasicAuth(oauthClient.ClientID, oauthClient.ClientSecret).
Type("form").
SendStruct(map[string]string{"token": "asdf"}).End()
assert.Len(t, errs, 0)
assert.Equal(t, 200, resp.StatusCode)
resp, _, errs = gorequest.New().Post(ts.URL+"/revoke").
SetBasicAuth(oauthClient.ClientID, oauthClient.ClientSecret).
Type("form").
SendStruct(map[string]string{"token": token.AccessToken}).End()
assert.Len(t, errs, 0)
assert.Equal(t, 200, resp.StatusCode)
hres, _, errs := gorequest.New().Get(ts.URL+"/info").
Set("Authorization", "bearer "+token.AccessToken).
End()
require.Len(t, errs, 0)
assert.Equal(t, http.StatusUnauthorized, hres.StatusCode)
}
开发者ID:cristiangraz,项目名称:fosite,代码行数:29,代码来源:revoke_token_test.go
示例2: init
func init() {
resp, body, err := gorequest.New().
Get("http://" + config.DbConfig.ServerRoot + ":" +
strconv.FormatUint(uint64(config.DbConfig.Port), 10) +
"/listDatabases").End()
if err != nil {
fmt.Println("listDatabase error:", err)
os.Exit(1)
}
if resp.StatusCode != 200 {
fmt.Println("listDatabase status:", resp.Status)
os.Exit(1)
}
type dblist struct {
Databases []string `json: "databases"`
}
var list dblist
json.Unmarshal([]byte(body), &list)
found := false
for _, db := range list.Databases {
if db == config.DATABASE {
found = true
break
}
}
fmt.Println("found database is", found)
if found == false {
resp, body, err = gorequest.New().Post("http://" +
config.DbConf(config.DbConfig).String() +
"/database/" + config.DATABASE + "/plocal/document").End()
if err != nil {
fmt.Println("create database:", err)
} else {
fmt.Println(body)
fmt.Println(resp.Status)
fmt.Println("Database created")
gorequest.New().Post("http://" + config.DbConf(config.DbConfig).String() + "/class/" + config.DATABASE + "/" + config.PASTECLASS).End()
config.Driver.Command("create property " + config.PASTECLASS + "." + config.USER_ID + " string")
config.Driver.Command("create property " + config.PASTECLASS + "." + config.TITLE + " string")
config.Driver.Command("create property " + config.PASTECLASS + "." + config.CONTENT + " string")
config.Driver.Command("create property " + config.PASTECLASS + "." + config.LANGUAGE + " string")
config.Driver.Command("create property " + config.PASTECLASS + "." + config.PUBLIC + " boolean")
}
} else {
fmt.Println("Database already exists")
}
}
开发者ID:RossBabcock3,项目名称:gopastebin5,代码行数:50,代码来源:main.go
示例3: main
func main() {
request := gorequest.New()
_, body, _ := request.Get("http://127.0.0.1:4001/v2/keys/foo").End()
fmt.Println(body)
//IT WORKS!!
save := gorequest.New()
_, body2, _ := save.Put("http://127.0.0.1:4001/v2/keys/foo?value=hi").End()
fmt.Println(body2)
request = gorequest.New()
_, body, _ = request.Get("http://127.0.0.1:4001/v2/keys/foo").End()
fmt.Println(body)
}
开发者ID:hvescovi,项目名称:learnGo,代码行数:14,代码来源:testApi2.go
示例4: getTeam
func getTeam(id int) {
resp, body, errs := gorequest.New().
Get("https://api.steampowered.com/IDOTA2Match_570/GetTeamInfoByTeamID/v0001/").
Query("key=" + conf.Steamapi).
Query("start_at_team_id=" + strconv.Itoa(id)).
End()
if errs != nil {
log.Fatal(errs)
}
if resp.StatusCode != 200 {
log.Println("(riki) ERROR:", resp.StatusCode)
return
}
teamjs, err := simplejson.NewJson([]byte(body))
if err != nil {
log.Fatal("(riki) ERROR:", err)
return
}
name := teamjs.Get("result").Get("teams").GetIndex(0).Get("name").MustString()
tag := teamjs.Get("result").Get("teams").GetIndex(0).Get("tag").MustString()
logo := teamjs.Get("result").Get("teams").GetIndex(0).Get("logo").MustInt()
logo_sponsor := teamjs.Get("result").Get("teams").GetIndex(0).Get("logo_sponsor").MustInt()
country_code := teamjs.Get("result").Get("teams").GetIndex(0).Get("country_code").MustString()
url := teamjs.Get("result").Get("teams").GetIndex(0).Get("url").MustString()
teamToSqlite(id, name, tag, logo, logo_sponsor, country_code, url)
}
开发者ID:shadow-blade-bot,项目名称:riki,代码行数:28,代码来源:teams.go
示例5: httpGet
func (api cvedictClient) httpGet(key, url string, resChan chan<- response, errChan chan<- error) {
var body string
var errs []error
var resp *http.Response
f := func() (err error) {
// resp, body, errs = gorequest.New().SetDebug(config.Conf.Debug).Get(url).End()
resp, body, errs = gorequest.New().Get(url).End()
if 0 < len(errs) || resp == nil || resp.StatusCode != 200 {
return fmt.Errorf("HTTP GET error: %v, url: %s, resp: %v", errs, url, resp)
}
return nil
}
notify := func(err error, t time.Duration) {
log.Warnf("Failed to HTTP GET. retrying in %s seconds. err: %s", t, err)
}
err := backoff.RetryNotify(f, backoff.NewExponentialBackOff(), notify)
if err != nil {
errChan <- fmt.Errorf("HTTP Error %s", err)
}
cveDetail := cve.CveDetail{}
if err := json.Unmarshal([]byte(body), &cveDetail); err != nil {
errChan <- fmt.Errorf("Failed to Unmarshall. body: %s, err: %s", body, err)
}
resChan <- response{
key,
cveDetail,
}
}
开发者ID:ymomoi,项目名称:vuls,代码行数:28,代码来源:cve_client.go
示例6: Charge
// Charge - it charges the customer on mpower and returns a response json object which contains the receipt url with other information
// The `confirmToken` is from the customer
// Returns a `boolean` and `error`
// The boolean signifies whether the customer was chargeed or not
// The response json object can be retrieved on the onsite invoice object
//
// Example.
// if ok, err := onsite.Charge(onsite.Token, "4346"); ok {
// //doSomething
// } else {
//
// }
//
func (on *OnsiteInvoice) Charge(oprToken, confirmToken string) (bool, error) {
var respData oprResponse
data := opr{oprToken, confirmToken}
req := gorequest.New()
for key, val := range on.Setup.GetHeaders() {
req.Set(key, val)
}
if dataByte, err := json.Marshal(data); err != nil {
return false, err
} else {
if _, body, err := req.Send(bytes.NewBuffer(dataByte).String()).End(); err != nil {
return false, fmt.Errorf("%v", err)
} else {
if err := json.Unmarshal(bytes.NewBufferString(body).Bytes(), &respData); err != nil {
return false, err
}
on.ResponseText = respData.ResponseText
on.ResponseCode = respData.ResponseCode
if respData.ResponseCode == "00" {
on.Description = respData.Description
on.Status = respData.InvoiceData.Status
on.ReceiptUrl = respData.InvoiceData.ReceiptUrl
return true, nil
} else {
return false, fmt.Errorf("Failed to charge invoice. Check OPR or confirm token and try again.")
}
}
}
}
开发者ID:MPowerPayments,项目名称:mpowergo,代码行数:46,代码来源:onsite_invoice.go
示例7: sendRequest
func sendRequest(userName string, id int, jsonSchemaWithTag string) {
request := gorequest.New()
if tag, schema := stringify(jsonSchemaWithTag); tag == "" && schema == "" {
fmt.Println("error")
} else {
str := `{"domainName":"` + userName + `","typeName":` + tag + `,"jsonSchema":` + schema + `}`
fmt.Printf("%s", str)
resp, _, err := request.Post(baseURL).
Set("Content-Type", "application/json").
Send(str).End()
if err != nil {
//spew.Dump(err)
callBackUser(id, "JSON syntax error")
} else {
// spew.Dump(body)
// spew.Dump(resp)
target := Onion{}
processResponser(resp, &target)
spew.Dump(target.Ginger_Id)
var s string = strconv.Itoa(int(target.Ginger_Id))
sendRequestByIdForBuild(s, id)
}
}
}
开发者ID:mingderwang,项目名称:twitterd,代码行数:26,代码来源:main.go
示例8: fetchHttp
func fetchHttp(url string, opts options) response {
var resp gorequest.Response
var body string
var errs []error
client := gorequest.New()
switch opts.Method {
case gorequest.HEAD:
resp, body, errs = client.Head(url).End()
case gorequest.GET:
resp, body, errs = client.Get(url).End()
case gorequest.POST:
resp, body, errs = client.Post(url).Query(opts.Body).End()
case gorequest.PUT:
resp, body, errs = client.Put(url).Query(opts.Body).End()
case gorequest.PATCH:
resp, body, errs = client.Patch(url).Query(opts.Body).End()
case gorequest.DELETE:
resp, body, errs = client.Delete(url).End()
}
result := response{
options: opts,
Status: resp.StatusCode,
StatusText: resp.Status,
Errors: errs,
}
result.Body = body
result.Headers = resp.Header
return result
}
开发者ID:deoxxa,项目名称:go-duktape-fetch,代码行数:30,代码来源:fetch.go
示例9: Add
// Add exposes a container on the service
func (expose Expose) Add(name string, port int) error {
var err error
var query struct {
LocalIP string `json:"localip"`
Services []Service `json:"services"`
}
query.LocalIP, err = localIP()
if err != nil {
return err
}
query.Services = make([]Service, 1)
query.Services[0].Service = expose.ContainerHost(name)
query.Services[0].Port = port
request := gorequest.New().Post("http://"+expose.url+"/api/service").
Set("Auth-Username", expose.username).
Set("Auth-Token", expose.token)
res, _, errs := request.Send(query).End()
if len(errs) > 0 {
return errs[0]
}
if res.StatusCode != 200 {
return fmt.Errorf("Invalid return code from server: %d\n%s", res.StatusCode, res.Body)
}
return nil
}
开发者ID:AerisCloud,项目名称:docker-expose,代码行数:32,代码来源:expose.go
示例10: NewAPIPathwar
func NewAPIPathwar(token, debug string) *APIPathwar {
return &APIPathwar{
client: gorequest.New(),
token: token,
debug: debug != "",
}
}
开发者ID:QuentinPerez,项目名称:go-pathwar,代码行数:7,代码来源:api.go
示例11: UpdateRecords
func (z *Zone) UpdateRecords(rs []*Record) []error {
c := RRsetContainer{
RRsets: []*RRset{
&RRset{
Name: rs[0].Name, Type: rs[0].Type, ChangeType: "REPLACE",
Records: rs,
},
},
}
_, bytes, errs := gorequest.
New().
Patch(fmt.Sprintf("%s/zones/%s", os.Getenv("API_URL"), z.Name)).
Set("X-API-Key", os.Getenv("API_KEY")).
Send(c).
EndBytes()
if errs != nil {
return errs
}
err := json.Unmarshal(bytes, z)
if err != nil {
return []error{err}
}
return nil
}
开发者ID:epicagency,项目名称:pdns-manager,代码行数:27,代码来源:zones.go
示例12: isValidAuthorizeRequest
func isValidAuthorizeRequest(c *HTTPClient, ar *AuthorizeRequest, retry bool) (bool, error) {
request := gorequest.New()
resp, body, errs := request.Post(pkg.JoinURL(c.ep, "/guard/allowed")).SetBasicAuth(c.clientConfig.ClientID, c.clientConfig.ClientSecret).Set("Content-Type", "application/json").Send(*ar).End()
if len(errs) > 0 {
return false, errors.Errorf("Got errors: %v", errs)
} else if retry && resp.StatusCode == http.StatusUnauthorized {
var err error
if c.clientToken, err = c.clientConfig.Token(oauth2.NoContext); err != nil {
return false, errors.New(err)
} else if c.clientToken == nil {
return false, errors.New("Access token could not be retrieved")
}
return isValidAuthorizeRequest(c, ar, false)
} else if resp.StatusCode != http.StatusOK {
return false, errors.Errorf("Status code %d is not 200: %s", resp.StatusCode, body)
}
if err := json.Unmarshal([]byte(body), &isAllowed); err != nil {
return false, errors.Errorf("Could not unmarshall body because %s", err.Error())
}
if !isAllowed.Allowed {
return false, errors.New("Authroization denied")
}
return isAllowed.Allowed, nil
}
开发者ID:emmanuel,项目名称:hydra,代码行数:26,代码来源:client.go
示例13: isValidAuthenticationRequest
func isValidAuthenticationRequest(c *HTTPClient, token string, retry bool) (bool, error) {
data := url.Values{}
data.Set("token", token)
request := gorequest.New()
resp, body, errs := request.Post(pkg.JoinURL(c.ep, "/oauth2/introspect")).Type("form").SetBasicAuth(c.clientConfig.ClientID, c.clientConfig.ClientSecret).SendString(data.Encode()).End()
if len(errs) > 0 {
return false, errors.Errorf("Got errors: %v", errs)
} else if resp.StatusCode != http.StatusOK {
return false, errors.Errorf("Status code %d is not 200: %s", resp.StatusCode, body)
}
if retry && resp.StatusCode == http.StatusUnauthorized {
var err error
if c.clientToken, err = c.clientConfig.Token(oauth2.NoContext); err != nil {
return false, errors.New(err)
} else if c.clientToken == nil {
return false, errors.New("Access token could not be retrieved")
}
return isValidAuthenticationRequest(c, token, false)
} else if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("Status code %d is not 200", resp.StatusCode)
}
var introspect struct {
Active bool `json:"active"`
}
if err := json.Unmarshal([]byte(body), &introspect); err != nil {
return false, err
} else if !introspect.Active {
return false, errors.New("Authentication denied")
}
return introspect.Active, nil
}
开发者ID:emmanuel,项目名称:hydra,代码行数:34,代码来源:client.go
示例14: getLeaguePrizePool
func getLeaguePrizePool(leagueid int) {
resp, body, errs := gorequest.New().
Get("https://api.steampowered.com/IEconDOTA2_570/GetTournamentPrizePool/v0001/").
Query("key=" + conf.Steamapi).
Query("leagueid=" + strconv.Itoa(leagueid)).
End()
if errs != nil {
log.Fatal(errs)
}
if resp.StatusCode != 200 {
log.Println("(riki) ERROR:", resp.StatusCode)
return
}
pooljs, err := simplejson.NewJson([]byte(body))
if err != nil {
log.Fatal("(riki) ERROR:", err)
return
}
prize_pool := pooljs.Get("result").Get("prize_pool").MustInt()
_, err = db.Exec("update leagues set prize_pool=? where id = ?;", prize_pool, leagueid)
if err != nil {
log.Fatal("(riki) ERROR:", err)
return
}
}
开发者ID:shadow-blade-bot,项目名称:riki,代码行数:27,代码来源:leagues.go
示例15: getHeroes
//
// GetHeroes to SQLite db
//
func getHeroes() {
resp, body, errs := gorequest.New().
Get("https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/").
Query("key=" + conf.Steamapi).
Query("language=en_us").
End()
if errs != nil {
log.Fatal(errs)
}
herojs, err := simplejson.NewJson([]byte(body))
if err != nil {
log.Fatal("(riki) ERROR:", err)
return
}
if resp.StatusCode != 200 {
log.Println("(riki) ERROR:", resp.StatusCode)
return
}
for i := range herojs.Get("result").Get("heroes").MustArray() {
id := herojs.Get("result").Get("heroes").GetIndex(i).Get("id").MustInt()
name := herojs.Get("result").Get("heroes").GetIndex(i).Get("name").MustString()
localized_name := herojs.Get("result").Get("heroes").GetIndex(i).Get("localized_name").MustString()
heroToSqlite(id, name[14:], localized_name)
}
}
开发者ID:shadow-blade-bot,项目名称:riki,代码行数:30,代码来源:heroes.go
示例16: Delete
// Delete un-exposes (is that a word?) a container from the service
func (expose Expose) Delete(name string) error {
var query struct {
Services []Service `json:"services"`
}
query.Services = make([]Service, 1)
query.Services[0].Service = expose.ContainerHost(name)
request := gorequest.New().Delete("http://"+expose.url+"/api/service").
Set("Auth-Username", expose.username).
Set("Auth-Token", expose.token).
Set("Content-Type", "application/json")
res, _, errs := request.Send(query).End()
if len(errs) > 0 {
return errs[0]
}
if res.StatusCode != 200 {
return fmt.Errorf("Invalid return code from server: %d\n%s", res.StatusCode, res.Body)
}
return nil
}
开发者ID:AerisCloud,项目名称:docker-expose,代码行数:26,代码来源:expose.go
示例17: List
// List lists currently exposed services
func (expose Expose) List(owned bool) (HostList, error) {
request := gorequest.New().SetBasicAuth(expose.username, expose.token)
res, body, errs := request.Get("http://" + expose.url + "/api/vms").End()
if len(errs) > 0 {
return HostList{}, errs[0]
}
if res.StatusCode != 200 {
return HostList{}, fmt.Errorf("Invalid return code from server: %d", res.StatusCode)
}
el := HostList{}
err := json.Unmarshal([]byte(body), &el)
if err != nil {
return HostList{}, err
}
if owned {
res := HostList{}
for _, eh := range el {
components := strings.Split(eh.Hostname, ".")
user := components[len(components)-1]
project := components[len(components)-2]
if user == expose.username && project == "docker" {
res = append(res, eh)
}
}
return res, nil
}
return el, nil
}
开发者ID:AerisCloud,项目名称:docker-expose,代码行数:33,代码来源:expose.go
示例18: getLegueMatches
func getLegueMatches(league_id int) {
resp, body, errs := gorequest.New().
Get("https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/v0001/").
Query("key=" + conf.Steamapi).
Query("league_id=" + strconv.Itoa(league_id)).
Query("min_players=10").
End()
if errs != nil {
log.Println("(invoker) ERROR:", errs)
return
}
if resp.StatusCode != 200 {
log.Println("(invoker) ERROR:", resp.StatusCode)
return
}
leagueGamesjs, err := simplejson.NewJson([]byte(body))
if err != nil {
log.Println("(invoker) ERROR:", err)
return
}
for i := range leagueGamesjs.Get("result").Get("matches").MustArray() {
match_id := leagueGamesjs.Get("result").Get("matches").GetIndex(i).Get("match_id").MustInt()
series_id := leagueGamesjs.Get("result").Get("matches").GetIndex(i).Get("series_id").MustInt()
series_type := leagueGamesjs.Get("result").Get("matches").GetIndex(i).Get("series_type").MustInt()
start_time := leagueGamesjs.Get("result").Get("matches").GetIndex(i).Get("start_time").MustInt64()
if start_time > time.Now().Unix()-86400 {
seriesIDToSqlite(match_id, series_id, series_type)
getMatch(match_id)
}
}
}
开发者ID:shadow-blade-bot,项目名称:invoker,代码行数:32,代码来源:matches.go
示例19: GetWithParameters
// GetWithParameters Makes a GET request to shopify with the given endpoint and given parameters
func (shopify *Shopify) GetWithParameters(endpoint string, parameters map[string]string) ([]byte, []error) {
targetURL := shopify.createTargetURLWithParameters(endpoint, parameters)
request := gorequest.New()
_, body, errs := request.Get(targetURL).End()
return []byte(body), errs
}
开发者ID:alecha,项目名称:go-shopify,代码行数:8,代码来源:shopify.go
示例20: goreq
func goreq() *gorequest.SuperAgent {
request := gorequest.New()
if os.Getenv("https_proxy") != "" {
request.Proxy(os.Getenv("https_proxy"))
}
return request
}
开发者ID:gerchardon,项目名称:cli,代码行数:7,代码来源:main.go
注:本文中的github.com/parnurzeal/gorequest.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论