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

     1  package logstreams
     2  
     3  import "github.com/huaweicloud/golangsdk"
     4  
     5  // CreateOptsBuilder is used for creating log stream parameters.
     6  type CreateOptsBuilder interface {
     7  	ToLogStreamsCreateMap() (map[string]interface{}, error)
     8  }
     9  
    10  // CreateOpts is a struct that contains all the parameters.
    11  type CreateOpts struct {
    12  	// Specifies the log stream name.
    13  	LogStreamName string `json:"log_stream_name" required:"true"`
    14  }
    15  
    16  // ToLogStreamsCreateMap is used for type convert
    17  func (ops CreateOpts) ToLogStreamsCreateMap() (map[string]interface{}, error) {
    18  	return golangsdk.BuildRequestBody(ops, "")
    19  }
    20  
    21  // Create a log stream with given parameters.
    22  func Create(client *golangsdk.ServiceClient, groupId string, ops CreateOptsBuilder) (r CreateResult) {
    23  	b, err := ops.ToLogStreamsCreateMap()
    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 stream 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 log stream list
    46  func List(client *golangsdk.ServiceClient, groupId string) (r ListResults) {
    47  	opts := golangsdk.RequestOpts{
    48  		MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    49  	}
    50  	_, r.Err = client.Get(listURL(client, groupId), &r.Body, &opts)
    51  	return
    52  }