httplib_user_service_gateway.go 1.9 KB
package service_gateway

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
	"strings"
	"time"
)

type HttplibUserServiceGateway struct {
	httplibBaseServiceGateway
}

func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]interface{}, error) {
	url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
	request := serviceGateway.createRequest(url, "post")
	options := make(map[string]interface{})
	options["uid"] = uid
	request.JSONBody(options)
	response := make(map[string]interface{})
	request.ToJSON(&response)
	data, err := serviceGateway.responseHandle(response)

	return data, err
}

func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
	url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
	request := serviceGateway.createRequest(url, "post")
	options := make(map[string]interface{})
	options["companyId"] = companyId
	request.JSONBody(options)
	response := make(map[string]interface{})
	request.ToJSON(&response)
	data, err := serviceGateway.responseHandle(response)
	return data, err
}

func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId int64) (map[string]interface{}, error) {
	url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
	request := serviceGateway.createRequest(url, "post")
	options := make(map[string]interface{})
	options["orgId"] = organizationId
	request.JSONBody(options)
	response := make(map[string]interface{})
	request.ToJSON(&response)
	data, err := serviceGateway.responseHandle(response)
	return data, err
}

func NewHttplibUserServiceGateway() *HttplibUserServiceGateway {
	return &HttplibUserServiceGateway{
		httplibBaseServiceGateway: httplibBaseServiceGateway{
			baseURL:          constant.USER_MODULE_HOST,
			connectTimeout:   100 * time.Second,
			readWriteTimeout: 30 * time.Second,
		},
	}
}