github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/lts/v2/logtopics/requests.go (about)

     1  package logtopics
     2  
     3  import "github.com/chnsz/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  	opts := golangsdk.RequestOpts{
    39  		MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    40  	}
    41  	_, r.Err = client.Delete(deleteURL(client, groupId, id), &opts)
    42  	return
    43  }
    44  
    45  // Get a log topic with detailed information by id
    46  func Get(client *golangsdk.ServiceClient, groupId string, id string) (r GetResult) {
    47  	_, r.Err = client.Get(getURL(client, groupId, id), &r.Body, nil)
    48  	return
    49  }