Exemplo n.º 1
0
func (c *CommonParam) Request(action string, params map[string]string, response interface{}) error {
	p := c.ResolveAllParams(action, params)
	result, err := RequestAPI(p)
	if err != nil {
		return err
	}
	log.Debug(result)
	err = json.Unmarshal([]byte(result), response)
	if err != nil {
		log.Error(err)
	}
	return nil
}
Exemplo n.º 2
0
// Http get request
func (request *AliyunRequest) DoGetRequest() (string, error) {
	resp, err := http.Get(request.Url)
	if err != nil {
		// handle error
		log.Error(err)
		return "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		// handle error
		log.Error(err)
		return "", err
	}
	result := string(body)
	var errResp ErrorResponse
	json.Unmarshal([]byte(result), &errResp)
	if errResp.Message != "" {
		err = &SdkError{errResp, request.Url}
	}
	return result, err
}
Exemplo n.º 3
0
func main() {
	// Initialize client
	cli := ecs.NewClient(
		"Your Access Key Id",
		"Your Access Key Secret",
		"ResourceOwnerAccount", // optional, set to empty string if it's no need for you
	)

	// Perform request
	result, err := cli.SecurityGroup.DescribeSecurityGroupAttribute(map[string]string{
		"RegionId":        "cn-beijing",
		"SecurityGroupId": "sg-25rh80j7f",
	})

	if err != nil {
		log.Error(err)
		return
	}
	log.Info(result)
}