org.go 1.0 KB
Newer Older
E
eoLinker API Management 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
package application

import (
	"fmt"
	"github.com/eolinker/goku/utils"
	"net/http"
	"net/url"
	"time"
)

type Org struct {
	server string
}
// 忽略重试
func (app *Org) Send(proto string,method string, path string,querys url.Values, header http.Header, body []byte,timeout time.Duration, retry int) (*http.Response,string,[]string,error) {


	var response *http.Response = nil
	var err error = nil

	FinalTargetServer := ""
	RetryTargetServers :=make([]string,0,retry+1)

	path = utils.TrimPrefixAll(path,"/")

	for doTrice := retry +1;doTrice>0;doTrice--{

		u:= fmt.Sprintf("%s://%s/%s",proto,app.server,path)
		FinalTargetServer = app.server
		RetryTargetServers = append(RetryTargetServers,FinalTargetServer)
		response,err =request(method,u,querys,header,body,timeout)
		if err != nil{
		  continue
		}else{
			return response,FinalTargetServer,RetryTargetServers,err
		}
	}

	return response,FinalTargetServer,RetryTargetServers,err
}

func NewOrg(server string)IHttpApplication  {
	return &Org{
		server:server,
	}
}