httplib_allied_creation_basic.go 1.2 KB
package service_gateway

import (
	"time"

	"github.com/astaxie/beego/httplib"
)

type HttplibAlliedCreationBasic struct {
	connectTimeout   time.Duration
	readWriteTimeout time.Duration
	BaseUrL          string
}

func (gateway HttplibAlliedCreationBasic) createRequest(url string, method string) *httplib.BeegoHTTPRequest {
	var request *httplib.BeegoHTTPRequest
	switch method {
	case "get":
		request = httplib.Get(url)
	case "post":
		request = httplib.Post(url)
	case "put":
		request = httplib.Put(url)
	case "delete":
		request = httplib.Delete(url)
	case "head":
		request = httplib.Head(url)

	default:
		request = httplib.Get(url)
	}
	return request.SetTimeout(gateway.connectTimeout, gateway.readWriteTimeout)
}

func (gateway HttplibAlliedCreationBasic) getResponseData(result GatewayResponse) {

}

//GetDictionarysByCode 根据code获取字典数据
func (gateway HttplibAlliedCreationBasic) GetDictionarysByCode(param map[string]interface{}) error {
	url := gateway.BaseUrL + "/dictionarys/dictionary-code"
	req := gateway.createRequest(url, "post")
	req, err := req.JSONBody(param)
	if err != nil {
		return err
	}
	var result GatewayResponse
	err = req.ToJSON(&result)
	if err != nil {
		return err
	}
	return nil
}