github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/smn/v2/logtank/requests.go (about) 1 package logtank 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 var RequestOpts = golangsdk.RequestOpts{ 8 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=UTF-8"}, 9 } 10 11 // Opts is a struct that contains all the parameters. 12 type Opts struct { 13 LogGroupID string `json:"log_group_id" required:"true"` 14 15 LogStreamID string `json:"log_stream_id" required:"true"` 16 } 17 18 // Create a logtank with given parameters. 19 func Create(client *golangsdk.ServiceClient, topicUrn string, opts Opts) (r CreateResult) { 20 b, err := golangsdk.BuildRequestBody(opts, "") 21 if err != nil { 22 r.Err = err 23 return 24 } 25 26 _, r.Err = client.Post(baseURL(client, topicUrn), b, &r.Body, &golangsdk.RequestOpts{ 27 MoreHeaders: RequestOpts.MoreHeaders, 28 }) 29 30 return 31 } 32 33 // List all the logtanks under the topicUrn 34 func List(client *golangsdk.ServiceClient, topicUrn string) (r ListResult) { 35 _, r.Err = client.Get(baseURL(client, topicUrn), &r.Body, &golangsdk.RequestOpts{ 36 MoreHeaders: RequestOpts.MoreHeaders, 37 }) 38 return 39 } 40 41 // Update a logtank with given parameters. 42 func Update(client *golangsdk.ServiceClient, topicUrn string, logTankID string, opts Opts) (r UpdateResult) { 43 b, err := golangsdk.BuildRequestBody(opts, "") 44 if err != nil { 45 r.Err = err 46 return 47 } 48 49 _, r.Err = client.Put(resourceURL(client, topicUrn, logTankID), b, &r.Body, &golangsdk.RequestOpts{ 50 MoreHeaders: RequestOpts.MoreHeaders, 51 }) 52 return 53 } 54 55 // Delete a logtank by topicUrn and LogTankID. 56 func Delete(client *golangsdk.ServiceClient, topicUrn string, LogTankID string) (r DeleteResult) { 57 _, r.Err = client.Delete(resourceURL(client, topicUrn, LogTankID), &golangsdk.RequestOpts{ 58 MoreHeaders: RequestOpts.MoreHeaders, 59 }) 60 return 61 }