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

     1  package logstreams
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/common/tags"
     6  )
     7  
     8  // CreateOptsBuilder is used for creating log stream parameters.
     9  type CreateOptsBuilder interface {
    10  	ToLogStreamsCreateMap() (map[string]interface{}, error)
    11  }
    12  
    13  // CreateOpts is a struct that contains all the parameters.
    14  type CreateOpts struct {
    15  	// Specifies the log stream name.
    16  	LogStreamName string `json:"log_stream_name" required:"true"`
    17  
    18  	// Specifies the log expiration time, only support in few regions: cn-north-4, cn-east-3, cn-south-1
    19  	TTL int `json:"ttl_in_days,omitempty"`
    20  
    21  	// Specifies the tags
    22  	Tags []tags.ResourceTag `json:"tags,omitempty"`
    23  }
    24  
    25  // ToLogStreamsCreateMap is used for type convert
    26  func (ops CreateOpts) ToLogStreamsCreateMap() (map[string]interface{}, error) {
    27  	return golangsdk.BuildRequestBody(ops, "")
    28  }
    29  
    30  // Create a log stream with given parameters.
    31  func Create(client *golangsdk.ServiceClient, groupId string, ops CreateOptsBuilder) (r CreateResult) {
    32  	b, err := ops.ToLogStreamsCreateMap()
    33  	if err != nil {
    34  		r.Err = err
    35  		return
    36  	}
    37  
    38  	_, r.Err = client.Post(createURL(client, groupId), b, &r.Body, &golangsdk.RequestOpts{
    39  		OkCodes: []int{201},
    40  	})
    41  
    42  	return
    43  }
    44  
    45  // Delete a log stream by id
    46  func Delete(client *golangsdk.ServiceClient, groupId string, id string) (r DeleteResult) {
    47  	opts := golangsdk.RequestOpts{
    48  		MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    49  	}
    50  	_, r.Err = client.Delete(deleteURL(client, groupId, id), &opts)
    51  	return
    52  }
    53  
    54  // Get log stream list
    55  func List(client *golangsdk.ServiceClient, groupId string) (r ListResults) {
    56  	opts := golangsdk.RequestOpts{
    57  		MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    58  	}
    59  	_, r.Err = client.Get(listURL(client, groupId), &r.Body, &opts)
    60  	return
    61  }