本文整理匯總了Golang中github.com/eaciit/toolkit.HttpCall函數的典型用法代碼示例。如果您正苦於以下問題:Golang HttpCall函數的具體用法?Golang HttpCall怎麽用?Golang HttpCall使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了HttpCall函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Grab
func (g *Grabber) Grab(parm toolkit.M) error {
errorTxt := ""
sendConf, e := g.GetConfig()
if e != nil {
return fmt.Errorf("Unable to grab %s, GetConfig Error found %s", g.URL, e.Error())
}
r, e := toolkit.HttpCall(g.URL, g.CallType, g.DataByte(), sendConf)
if e != nil {
errorTxt = e.Error()
} else if r.StatusCode != 200 {
errorTxt = r.Status
}
if errorTxt != "" {
return fmt.Errorf("Unable to grab %s. %s", g.URL, errorTxt)
}
g.Response = r
g.bodyByte = toolkit.HttpContent(r)
//Logout ====
if sendConf.Has("cookie") {
tjar := sendConf.Get("cookie", nil).(*cookiejar.Jar)
if tjar != nil && g.LogoutUrl != "" {
_, e := toolkit.HttpCall(g.LogoutUrl, g.CallType, g.DataByte(), toolkit.M{}.Set("cookie", tjar))
if e != nil {
return fmt.Errorf("Unable to logout %s, grab logout Error found %s", g.LogoutUrl, e.Error())
}
}
}
return nil
}
示例2: Exec
/*
Execute command depend on type that has been declared before
*/
func (c *Command) Exec() (string, error) {
var (
res string
e error
httpRes *http.Response
)
res = "initial"
e = fmt.Errorf("Command %s %s can't be executed. No valid implementation can be found")
if c.Type == CommandType_Local {
ps := []string{}
if c.CommandParms != nil {
ps = c.CommandParms
}
res, e = toolkit.RunCommand(c.CommandText, ps...)
} else if c.Type == CommandType_SSH {
ps := []string{c.CommandText}
res, e = c.SshClient.RunCommandSsh(ps...)
} else if c.Type == CommandType_REST {
if c.RESTAuthType == RESTAuthType_None {
httpRes, e = toolkit.HttpCall(c.RESTUrl, c.RESTMethod, nil, nil)
} else if c.RESTAuthType == RESTAuthType_Basic {
var config = map[string]interface{}{"auth": "basic", "user": c.RESTUser, "password": c.RESTPassword}
httpRes, e = toolkit.HttpCall(c.RESTUrl, c.RESTMethod, nil, config)
// httpRes, e = toolkit.HttpCall(c.RESTUrl, c.RESTMethod, nil, true, c.RESTUser, c.RESTPassword)
}
res = toolkit.HttpContentString(httpRes)
}
return res, e
}
示例3: getMsgAsResult
func (s *Subscriber) getMsgAsResult(key string) *toolkit.Result {
result := toolkit.NewResult()
if key == "" {
if len(s.messageKeys) > 0 {
key = s.messageKeys[0]
}
}
// if no key is provided, check from the latest
if key == "" {
result.Status = toolkit.Status_NOK
result.Message = "No key has been provided to receive the message"
} else {
msgQue, exist := s.MessageQues[key]
if !exist {
result.Status = toolkit.Status_NOK
result.Message = "Key " + key + " is not exist on message que or it has been collected. Available keys are: " + strings.Join(s.messageKeys, ",")
} else {
url := fmt.Sprintf("%s/getmsg", s.BroadcasterAddress)
r, e := toolkit.HttpCall(url, "POST",
toolkit.Jsonify(msgQue), nil)
if e != nil {
result.SetErrorTxt("Subscriber ReceiveMsg Call Error: " + e.Error())
} else if r.StatusCode != 200 {
result.SetErrorTxt("Subsciber ReceiveMsg Call Error: " + r.Status)
} else {
//var resultMsg toolkit.Result
e := toolkit.Unjson(toolkit.HttpContent(r),
&result)
if e != nil {
result.SetErrorTxt(fmt.Sprintf("Subsciber ReceiveMsg Decode Error: ", e.Error()))
}
/*else {
if resultMsg.Status == toolkit.Status_OK {
result.Data = resultMsg.Data
} else {
result.SetErrorTxt(resultMsg.Message)
}
}
*/
}
}
}
if result.Status == "OK" {
url := fmt.Sprintf("%s/msgreceived")
toolkit.HttpCall(url, "POST", toolkit.Jsonify(struct {
Key string
Subscriber string
}{key, s.Address}), nil)
}
return result
}
示例4: main
func main() {
UrlStr := "http://www.dce.com.cn/PublicWeb/MainServlet"
dataurl := toolkit.M{}
dataurl["Pu00231_Input.trade_date"] = "20151214"
dataurl["Pu00231_Input.variety"] = "i"
dataurl["Pu00231_Input.trade_type"] = "0"
dataurl["Submit"] = "Go"
dataurl["action"] = "Pu00231_result"
postdata := toolkit.M{}.Set("formvalues", dataurl)
// dataurl := url.Values{}
// dataurl.Add("Pu00231_Input.trade_date", "20151214")
// dataurl.Add("Pu00231_Input.variety", "i")
// dataurl.Add("Pu00231_Input.trade_type", "0")
// dataurl.Add("Submit", "Go")
// dataurl.Add("action", "Pu00231_result")
// tdata := toolkit.Jsonify(dataurl.Encode())
r, _ := toolkit.HttpCall(UrlStr, "POST", nil, postdata)
fmt.Println(string(toolkit.HttpContent(r)))
// rX, _ := http.NewRequest("POST", UrlStr, bytes.NewBuffer(tdata))
// fmt.Println(rX)
// client := &http.Client{}
// resp, _ := client.Do(rX)
// fmt.Println(string(toolkit.HttpContent(resp)))
}
示例5: TestPut
func TestPut(t *testing.T) {
if e := getToken(); e != nil {
//he(t, e)
//return
}
surl := restPrefix + "/put"
for i := 1; i <= 1000; i++ {
randomTxt := createRandomString(toolkit.RandInt(22) + 10)
data := struct {
Token string
Data string
}{
token,
randomTxt,
}
fmt.Printf("Saving %d value %s", i, data.Data)
r, e := toolkit.HttpCall(surl, "XPUT", toolkit.GetEncodeByte(data), nil)
//e = nil
if e != nil {
fmt.Printf("... Fail: %s \n", e.Error())
} else {
if r.StatusCode != 200 {
fmt.Printf("... Fail: %d %s \n", r.StatusCode, r.Status)
} else {
fmt.Println("...Done")
}
fmt.Println("...Done")
}
}
}
示例6: webcall
func webcall(url, method string, data []byte) ([]byte, error) {
r, e := toolkit.HttpCall(url, method, data, nil)
if e != nil {
return nil, e
}
if r.StatusCode != 200 {
return nil, fmt.Errorf("Invalid Code: " + r.Status)
}
return toolkit.HttpContent(r), nil
}
示例7: checkHttpStatus
func (p *Ping) checkHttpStatus() error {
r, e := toolkit.HttpCall(p.Host, "GET", nil, false, "", "")
if e != nil {
return fmt.Errorf("Unable to access %s, %s", p.Host, e.Error())
}
if r.StatusCode != 200 {
return fmt.Errorf("Unable to access %s, code: %d status: %s", p.Host, r.StatusCode, r.Status)
}
return nil
}
示例8: checkHttpStatus
/*
Ping service over http status
*/
func (p *Ping) checkHttpStatus() error {
r, e := toolkit.HttpCall(p.Host, "GET", nil, nil)
p.LastStatus = "Fail"
if e != nil {
return fmt.Errorf("Unable to access %s, %s", p.Host, e.Error())
}
if r.StatusCode != 200 {
return fmt.Errorf("Unable to access %s, code: %d status: %s", p.Host, r.StatusCode, r.Status)
}
p.LastStatus = "OK"
return nil
}
示例9: distributeBroadcast
func (m *MessageMonitor) distributeBroadcast() {
for len(m.Targets) != m.Success && time.Now().After(m.Expiry) == false {
wg := new(sync.WaitGroup)
for k, t := range m.Targets {
wg.Add(1)
go func(wg *sync.WaitGroup, k int, t string) {
defer wg.Done()
if m.Status[k] != "OK" && m.retry[k] < RetryWhenFail() {
var command, url string
/*
if m.Command != "" {
command = m.Command
} else {
command = "msg"
}
*/
sub := m.broadcaster.Subscibers[t]
if sub != nil {
command = "pushmessage"
url = fmt.Sprintf("http://%s/subscriber/%s", t, command)
r, ecall := toolkit.HttpCall(url, "POST",
toolkit.M{}.Set("secret", sub.Secret).Set("Data", m.Data).Set("Key", m.Key).ToBytes("json", nil),
nil)
if ecall != nil {
m.setSuccessFail(k, "CALL ERROR: "+url+" ERR:"+ecall.Error())
} else if r.StatusCode != 200 {
m.setSuccessFail(k, fmt.Sprintf("CALL STATUS ERROR: %s ERR: %s", url, r.Status))
} else {
var result toolkit.Result
bs := toolkit.HttpContent(r)
edecode := toolkit.Unjson(bs, &result)
if edecode != nil {
m.setSuccessFail(k, "DECODE ERROR: "+string(bs)+" ERR:"+edecode.Error())
} else {
m.setSuccessFail(k, toolkit.IfEq(result.Status, toolkit.Status_OK, "OK", result.Message).(string))
}
}
}
}
}(wg, k, t)
}
wg.Wait()
//time.Sleep(1 * time.Second)
//fmt.Printf("%d = %d \n", len(m.Targets), m.Success+m.Fail)
}
}
示例10: call
func (s *Server) call(op string, calltype string, qs toolkit.M, payload []byte) (*http.Response, error) {
url := s.Id
url += op
q := ""
for k, v := range qs {
if q == "" {
q = "?" + k + "=" + v.(string)
} else {
q += "&" + k + "=" + v.(string)
}
}
url += q
//rdr := bytes.NewReader(payload)
r, e := toolkit.HttpCall(url, calltype, payload, nil)
return r, e
}
示例11: FetchContent
func (w *WebGrabberController) FetchContent(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := new(colonycore.WebGrabber)
err := r.GetPayload(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
param := toolkit.M{} //.Set("formvalues", payload.Parameter)
res, err := toolkit.HttpCall(payload.URL, payload.CallType, nil, param)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := toolkit.HttpContentString(res)
return helper.CreateResult(true, data, "")
}
示例12: checkHttpBody
func (p *Ping) checkHttpBody() error {
r, e := toolkit.HttpCall(p.Host, "GET", nil, false, "", "")
if e != nil {
return e
}
body := toolkit.HttpContentString(r)
if p.HttpBodyType == HttpBody_Contains {
if !strings.Contains(body, p.HttpBodySearch) {
return fmt.Errorf("Phrase %s could not be found on response body", p.HttpBodySearch)
}
} else if p.HttpBodyType == HttpBody_Equals {
if body != p.HttpBodySearch {
return fmt.Errorf("Response is not valid. Expecting for %s", p.HttpBodySearch)
}
} else {
return fmt.Errorf("Invalid parameter")
}
return nil
}
示例13: AddChannel
func (s *Subscriber) AddChannel(c string) error {
url := fmt.Sprintf("%s/channelregister", s.BroadcasterAddress)
r, e := toolkit.HttpCall(url, "POST", toolkit.Jsonify(ChannelRegister{c, s.Address}), nil)
if e != nil {
return fmt.Errorf("Channel Register Call Error: %s", e.Error())
}
if r.StatusCode != 200 {
return fmt.Errorf("Channel Register Call Error: %s", r.Status)
}
result := new(toolkit.Result)
e = toolkit.Unjson(toolkit.HttpContent(r), &result)
if e != nil {
return fmt.Errorf("Channel Register Decode error: %s", e.Error())
}
if result.Status != toolkit.Status_OK {
return fmt.Errorf("Channel Register error: %s", result.Message)
}
return nil
}
示例14: main
func main() {
url := "http://www.dce.com.cn/PublicWeb/MainServlet"
formvalues := toolkit.M{}.Set("Pu00231_Input.trade_date", "20151214").
Set("Pu00231_Input.variety", "i").
Set("Pu00231_Input.trade_type", "0").
Set("Submit", "Go").
Set("action", "Pu00231_result")
config := toolkit.M{}.Set("formvalues", formvalues)
r, e := toolkit.HttpCall(url, "POST", nil, config)
if e != nil {
fmt.Printf("ERROR:\n%s\n", e.Error())
return
}
fmt.Printf("Result:\n%s\n", toolkit.HttpContentString(r))
}
示例15: call
func call(url, call string, data []byte, expectedStatus int) (*toolkit.Result, error) {
cfg := toolkit.M{}
if expectedStatus != 0 {
cfg.Set("expectedstatus", expectedStatus)
}
r, e := toolkit.HttpCall(url, call, data, cfg)
if e != nil {
return nil, fmt.Errorf(url + " Call Error: " + e.Error())
}
result := toolkit.NewResult()
bs := toolkit.HttpContent(r)
edecode := toolkit.Unjson(bs, result)
if edecode != nil {
return nil, fmt.Errorf(url + " Http Result Decode Error: " + edecode.Error() + "\nFollowing got: " + string(bs))
}
if result.Status == toolkit.Status_NOK {
return nil, fmt.Errorf(url + " Http Result Error: " + result.Message)
}
return result, nil
}