github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/lts/v2/logtopics/requests.go (about)

     1  package logtopics
     2  
     3  import "github.com/huaweicloud/golangsdk"
     4  
     5  // CreateOptsBuilder is used for creating log group parameters.
     6  type CreateOptsBuilder interface {
     7  	ToLogTopicsCreateMap() (map[string]interface{}, error)
     8  }
     9  
    10  // CreateOpts is a struct that contains all the parameters.
    11  type CreateOpts struct {
    12  	// Specifies the log group name.
    13  	LogTopicName string `json:"log_topic_name" required:"true"`
    14  }
    15  
    16  // ToLogTopicsCreateMap is used for type convert
    17  func (ops CreateOpts) ToLogTopicsCreateMap() (map[string]interface{}, error) {
    18  	return golangsdk.BuildRequestBody(ops, "")
    19  }
    20  
    21  // Create a log topic with given parameters.
    22  func Create(client *golangsdk.ServiceClient, groupId string, ops CreateOptsBuilder) (r CreateResult) {
    23  	b, err := ops.ToLogTopicsCreateMap()
    24  	if err != nil {
    25  		r.Err = err
    26  		return
    27  	}
    28  
    29  	_, r.Err = client.Post(createURL(client, groupId), b, &r.Body, &golangsdk.RequestOpts{
    30  		OkCodes: []int{201},
    31  	})
    32  
    33  	return
    34  }
    35  
    36  // Delete a log topic by id
    37  func Delete(client *golangsdk.ServiceClient, groupId string, id string) (r DeleteResult) {
    38  	_, r.Err = client.Delete(deleteURL(client, groupId, id), nil)
    39  	return
    40  }
    41  
    42  // Get a log topic with detailed information by id
    43  func Get(client *golangsdk.ServiceClient, groupId string, id string) (r GetResult) {
    44  	_, r.Err = client.Get(getURL(client, groupId, id), &r.Body, nil)
    45  	return
    46  }