當前位置: 首頁>>代碼示例>>Golang>>正文


Golang sling.Sling類代碼示例

本文整理匯總了Golang中github.com/dghubble/sling.Sling的典型用法代碼示例。如果您正苦於以下問題:Golang Sling類的具體用法?Golang Sling怎麽用?Golang Sling使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Sling類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: DoRequest

func DoRequest(r *sling.Sling) *http.Response {
	req, err := r.Request()
	Expect(err).To(BeNil())
	response, err := http.DefaultClient.Do(req)

	Expect(err).To(BeNil())
	return response
}
開發者ID:SpectoLabs,項目名稱:hoverfly,代碼行數:8,代碼來源:ft_suite_test.go

示例2: newStreamService

// newStreamService returns a new StreamService.
func newStreamService(client *http.Client, sling *sling.Sling) *StreamService {
	sling.Set("User-Agent", userAgent)
	return &StreamService{
		client: client,
		public: sling.New().Base(publicStream).Path("statuses/"),
		user:   sling.New().Base(userStream),
		site:   sling.New().Base(siteStream),
	}
}
開發者ID:dougnukem,項目名稱:go-twitter,代碼行數:10,代碼來源:streams.go

示例3: DoRequestThroughProxy

func DoRequestThroughProxy(r *sling.Sling) *http.Response {
	req, err := r.Request()
	Expect(err).To(BeNil())

	proxy, err := url.Parse(hoverflyProxyUrl)
	proxyHttpClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }}
	response, err := proxyHttpClient.Do(req)

	Expect(err).To(BeNil())

	return response
}
開發者ID:SpectoLabs,項目名稱:hoverfly,代碼行數:12,代碼來源:ft_suite_test.go

示例4: DoRequestThroughProxy

func DoRequestThroughProxy(r *sling.Sling) *http.Response {
	req, err := r.Request()
	Expect(err).To(BeNil())

	proxy, err := url.Parse(hoverflyProxyUrl)
	proxyHttpClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}}
	response, err := proxyHttpClient.Do(req)

	Expect(err).To(BeNil())

	return response
}
開發者ID:SpectoLabs,項目名稱:hoverfly,代碼行數:12,代碼來源:ft_suite_test.go

示例5: request

func request(_sling *sling.Sling, acceptHeader string, authInfo ...usrInfo) (int, []byte, error) {
	_sling = _sling.Set("Accept", acceptHeader)
	req, err := _sling.Request()
	if err != nil {
		return 400, nil, err
	}
	if len(authInfo) > 0 {
		req.SetBasicAuth(authInfo[0].Name, authInfo[0].Passwd)
	}
	w := httptest.NewRecorder()
	beego.BeeApp.Handlers.ServeHTTP(w, req)
	body, err := ioutil.ReadAll(w.Body)
	return w.Code, body, err
}
開發者ID:vmware,項目名稱:harbor,代碼行數:14,代碼來源:harborapi_test.go

示例6: doRequest

func (h *Hoverfly) doRequest(request *sling.Sling) (*http.Response, error) {
	httpRequest, err := request.Request()
	if err != nil {
		log.Debug(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}

	response, err := h.httpClient.Do(httpRequest)
	if err != nil {
		log.Debug(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}

	if response.StatusCode == 401 {
		return nil, errors.New("Hoverfly requires authentication")
	}

	return response, nil
}
開發者ID:SpectoLabs,項目名稱:hoverfly,代碼行數:19,代碼來源:hoverfly.go

示例7: performAPIRequest

func (h *Hoverfly) performAPIRequest(slingRequest *sling.Sling) (*http.Response, error) {
	slingRequest, err := h.addAuthIfNeeded(slingRequest)
	if err != nil {
		log.Warn(err.Error())
		return nil, errors.New("Could not authenticate  with Hoverfly")
	}

	request, err := slingRequest.Request()

	if err != nil {
		log.Warn(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}

	response, err := h.httpClient.Do(request)
	if err != nil {
		log.Warn(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}
	return response, nil

}
開發者ID:SpectoLabs,項目名稱:hoverfly,代碼行數:22,代碼來源:template.go

示例8: addAuthIfNeeded

func (h *Hoverfly) addAuthIfNeeded(sling *sling.Sling) (*sling.Sling, error) {
	if len(h.Username) > 0 || len(h.Password) > 0 && len(h.authToken) == 0 {
		var err error

		h.authToken, err = h.generateAuthToken()
		if err != nil {
			return nil, err
		}
	}

	if len(h.authToken) > 0 {
		sling.Add("Authorization", h.buildAuthorizationHeaderValue())
	}

	return sling, nil
}
開發者ID:SpectoLabs,項目名稱:hoverfly,代碼行數:16,代碼來源:hoverfly.go

示例9: newSchemaService

func newSchemaService(sling *sling.Sling) *SchemaService {
	return &SchemaService{
		sling: sling.Path("schemas"),
	}
}
開發者ID:osiloke,項目名稱:dostow-contrib,代碼行數:5,代碼來源:schema.go

示例10: newUserService

// newUserService returns a new UserService.
func newUserService(sling *sling.Sling) *UserService {
	return &UserService{
		sling: sling.Path("users/"),
	}
}
開發者ID:silalahi,項目名稱:go-twitter,代碼行數:6,代碼來源:users.go

示例11: newGroupService

func newGroupService(sling *sling.Sling) *GroupService {
	return &GroupService{
		sling: sling.Path("group/"),
	}
}
開發者ID:osiloke,項目名稱:dostow-contrib,代碼行數:5,代碼來源:group.go

示例12: newStoreService

func newStoreService(sling *sling.Sling) *StoreService {
	return &StoreService{
		sling: sling.Path("store"),
	}
}
開發者ID:osiloke,項目名稱:dostow-contrib,代碼行數:5,代碼來源:store.go

示例13:

	"net/http"
	"os/exec"

	"github.com/dghubble/sling"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/rosenhouse/cnsim/models"
	"github.com/sclevine/agouti"
	. "github.com/sclevine/agouti/matchers"
)

var _ = Describe("CNSim Server", func() {
	var (
		session *gexec.Session
		address string

		apiClient *sling.Sling
	)

	var serverIsAvailable = func() error {
		return VerifyTCPConnection(address)
	}

	BeforeEach(func() {
		port := 10000 + rand.Intn(10000)
		serverCmd := exec.Command(pathToServer)
		serverCmd.Env = []string{fmt.Sprintf("PORT=%d", port)}
		var err error
		session, err = gexec.Start(serverCmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
開發者ID:rosenhouse,項目名稱:cnsim,代碼行數:31,代碼來源:acceptance_test.go

示例14: newAccountService

// newAccountService returns a new AccountService.
func newAccountService(sling *sling.Sling) *AccountService {
	return &AccountService{
		sling: sling.Path("account/"),
	}
}
開發者ID:silalahi,項目名稱:go-twitter,代碼行數:6,代碼來源:accounts.go

示例15: newStatusService

// newStatusService returns a new StatusService.
func newStatusService(sling *sling.Sling) *StatusService {
	return &StatusService{
		sling: sling.Path("statuses/"),
	}
}
開發者ID:silalahi,項目名稱:go-twitter,代碼行數:6,代碼來源:statuses.go


注:本文中的github.com/dghubble/sling.Sling類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。