github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/iec/v1/security/rules/requests.go (about) 1 package rules 2 3 import ( 4 "net/http" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/openstack/iec/v1/common" 8 ) 9 10 type CreateOpts struct { 11 SecurityGroupRule *common.ReqSecurityGroupRuleEntity `json:"security_group_rule"` 12 } 13 14 type CreateOptsBuilder interface { 15 ToSecurityGroupRuleCreateMap() (map[string]interface{}, error) 16 } 17 18 func (opts CreateOpts) ToSecurityGroupRuleCreateMap() (map[string]interface{}, error) { 19 b, err := golangsdk.BuildRequestBody(&opts, "") 20 if err != nil { 21 return nil, err 22 } 23 return b, nil 24 } 25 26 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 27 b, err := opts.ToSecurityGroupRuleCreateMap() 28 if err != nil { 29 r.Err = err 30 return 31 } 32 33 _, r.Err = client.Post(CreateURL(client), b, &r.Body, &golangsdk.RequestOpts{ 34 OkCodes: []int{http.StatusOK}, 35 }) 36 return 37 } 38 39 func Delete(client *golangsdk.ServiceClient, securityGroupRuleID string) (r DeleteResult) { 40 url := DeleteURL(client, securityGroupRuleID) 41 _, r.Err = client.Delete(url, nil) 42 return 43 } 44 45 func Get(client *golangsdk.ServiceClient, securityGroupRuleID string) (r GetResult) { 46 url := GetURL(client, securityGroupRuleID) 47 _, r.Err = client.Get(url, &r.Body, &golangsdk.RequestOpts{ 48 OkCodes: []int{http.StatusOK}, 49 }) 50 return 51 }