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


Golang util.HttpClient類代碼示例

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


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

示例1: PassWordResetTokenTheIssue

func (r *Request) PassWordResetTokenTheIssue() (*Response, string, error) {
	p := &r.Params
	ir := IssueRequest{p.Email}

	mJson, err := json.Marshal(ir)
	if err != nil {
		return nil, "", err
	}

	client := util.HttpClient{}
	client.Path = "/auth/password_reset_token/issue"
	client.Body = mJson

	resp, err := client.Post()
	if err != nil {
		return nil, "", err
	}
	if resp.StatusCode == http.StatusBadRequest {
		err = errors.New("Email is not valid.")
		return nil, "", err
	}

	if resp.StatusCode == http.StatusOK {
		return nil, "OK", nil
	}

	err = errors.New("Undefined error.")
	return nil, "", err
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:29,代碼來源:password.go

示例2: PassWordResetTokenTheVerify

func (r *Request) PassWordResetTokenTheVerify() (*Response, string, error) {
	p := &r.Params
	vr := VerifyRequest{p.NewPassword, p.VerifyToken}

	mJson, err := json.Marshal(vr)
	if err != nil {
		return nil, "", err
	}

	client := util.HttpClient{}
	client.Path = "/auth/password_reset_token/verify"
	client.Body = mJson

	resp, err := client.Post()
	if err != nil {
		return nil, "", err
	}

	switch resp.StatusCode {
	case http.StatusBadRequest:
		err = errors.New("Invalid token.")
		return nil, "", err
	case http.StatusNotFound:
		err = errors.New("Token timeout.")
		return nil, "", err
	case http.StatusOK:
		return nil, "OK", nil
	}

	err = errors.New("Unknown Error.")
	return nil, "", err
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:32,代碼來源:password.go

示例3: OperatorPassword

func (r *Request) OperatorPassword() (*Response, string, error) {
	p := &r.Params
	rp := RequestPassword{p.CurrentPassword, p.NewPassword}

	mJson, err := json.Marshal(rp)
	if err != nil {
		return nil, "", err
	}

	client := util.HttpClient{}
	client.Path = "/operators/" + string(p.OperatorId) + "/password"
	client.Body = mJson
	client.XSoracomApiKey = p.XSoracomApiKey
	client.XSoracomToken = p.XSoracomToken

	resp, err := client.Post()
	if err != nil {
		return nil, "", err
	}

	switch resp.StatusCode {
	case http.StatusBadRequest:
		err = errors.New("Invalid password")
		return nil, "", err
	case http.StatusOK:
		return nil, "OK", err
	}

	err = errors.New("Unknown Error.")
	return nil, "", err
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:31,代碼來源:password.go

示例4: Operators

func (r *Request) Operators() (*Response, string, error) {
	p := &r.Params
	ro := RequestOperators{p.Email, p.Password}

	mJson, err := json.Marshal(ro)
	if err != nil {
		return nil, "", err
	}

	client := util.HttpClient{}
	client.Path = "/operators"
	client.Body = mJson
	client.XSoracomApiKey = p.XSoracomApiKey
	client.XSoracomToken = p.XSoracomToken

	resp, err := client.Post()
	if err != nil {
		return nil, "", err
	}

	switch resp.StatusCode {
	case http.StatusCreated:
		return nil, "OK", nil
	case http.StatusBadRequest:
		err = errors.New("This email is already registered")
		return nil, "", err
	}

	err = errors.New("Unknown error.")
	return nil, "", err
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:31,代碼來源:operators.go

示例5: OperatorInfo

func (r *Request) OperatorInfo() (*Response, string, error) {
	p := &r.Params
	client := util.HttpClient{}
	client.Path = "/operators/" + string(p.OperatorId)
	client.XSoracomApiKey = p.XSoracomApiKey
	client.XSoracomToken = p.XSoracomToken

	resp, err := client.Get()
	if err != nil {
		return nil, "", err
	}

	if resp.StatusCode == http.StatusBadRequest {
		err = errors.New("Invalid Operator Id.")
		return nil, "", err
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()

	or := Response{}

	err = json.Unmarshal(body, &or)
	if err != nil {
		return nil, "", err
	}

	return &or, string(body), nil
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:32,代碼來源:info.go

示例6: Auth

func (r *Request) Auth() (*Response, string, error) {
	p := &r.Params
	ar := AuthRequest{p.Email, p.Password, p.TokenTimeoutSeconds}

	mJson, err := json.Marshal(ar)
	if err != nil {
		return nil, "", err
	}

	client := util.HttpClient{}
	client.Path = "/auth"
	client.Body = mJson

	resp, err := client.Post()
	if err != nil {
		return nil, "", err
	}

	if resp.StatusCode == http.StatusForbidden {
		err = errors.New("Email or password is not valid.")
		return nil, "", err
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()

	aResp := Response{}

	err = json.Unmarshal(body, &aResp)
	if err != nil {
		return nil, "", err
	}

	return &aResp, string(body), nil
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:38,代碼來源:auth.go

示例7: OperatorVerify

func (r *Request) OperatorVerify() (*Response, string, error) {
	p := &r.Params
	rv := RequestVerify{p.VerifyToken}

	mJson, err := json.Marshal(rv)
	if err != nil {
		return nil, "", err
	}

	client := util.HttpClient{}
	client.Path = "/operators/verify"
	client.Body = mJson
	client.XSoracomApiKey = p.XSoracomApiKey
	client.XSoracomToken = p.XSoracomToken

	resp, err := client.Post()
	if err != nil {
		return nil, "", err
	}

	switch resp.StatusCode {
	case http.StatusBadRequest:
		err = errors.New("Invalid token")
		return nil, "", err
	case http.StatusNotFound:
		err = errors.New("Token is expired")
		return nil, "", err
	case http.StatusOK:
		return nil, "OK", nil
	}

	println(resp.StatusCode)

	err = errors.New("Unknown error.")
	return nil, "", err
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:36,代碼來源:verify.go

示例8: OperatorSupportToken

func (r *Request) OperatorSupportToken() (*Response, string, error) {
	p := &r.Params
	client := util.HttpClient{}
	client.Path = "/operators/" + string(p.OperatorId) + "/support/token"
	client.XSoracomApiKey = p.XSoracomApiKey
	client.XSoracomToken = p.XSoracomToken

	resp, err := client.Post()

	if err != nil {
		return nil, "", err
	}

	switch resp.StatusCode {
	case http.StatusBadRequest:
		err = errors.New("Invald OperatorId")
		return nil, "", err
	case http.StatusForbidden:
		err = errors.New("Invalid token for SORACOM")
		return nil, "", err
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()

	ar := Response{}

	err = json.Unmarshal(body, &ar)
	if err != nil {
		return nil, "", err
	}

	return &ar, string(body), nil
}
開發者ID:futoase,項目名稱:soracom-go,代碼行數:37,代碼來源:support.go


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