blob: b3fb921e58063522c7d6f558e6c4ffe73e3153a9 [file] [log] [blame]
Jon Perritt816d2a02014-03-11 20:49:46 -05001package containers
2
3import (
4 "encoding/json"
5 "strings"
6)
7
8type Container struct {
9 Bytes int
10 Count int
11 Name string
12}
13
14type ListOpts struct {
15 Full bool
16 Params map[string]string
17}
18
19type CreateOpts struct {
20 Name string
21 Metadata map[string]string
22 Headers map[string]string
23}
24
25type DeleteOpts struct {
26 Name string
27 Params map[string]string
28}
29
30type UpdateOpts struct {
31 Name string
32 Metadata map[string]string
33 Headers map[string]string
34}
35
36type GetOpts struct {
37 Name string
38 Metadata map[string]string
39}
40
41// GetInfo is a function that takes a ListResult (of type *perigee.Response)
42// and returns the containers' information.
43func GetInfo(lr ListResult) ([]Container, error) {
44 var ci []Container
45 err := json.Unmarshal(lr.JsonResult, &ci)
46 return ci, err
47}
48
49// GetNames is a function that takes a ListResult (of type *perigee.Response)
50// and returns the containers' names.
51func GetNames(lr ListResult) ([]string, error) {
52 jr := string(lr.JsonResult)
53 cns := strings.Split(jr, "\n")
54 cns = cns[:len(cns)-1]
55 return cns, nil
56}
57
58// GetMetadata is a function that takes a GetResult (of type *perigee.Response)
59// and returns the custom metadata associated with the container.
60func GetMetadata(gr GetResult) map[string]string {
61 metadata := make(map[string]string)
62 for k, v := range gr.HttpResponse.Header {
63 if strings.HasPrefix(k, "X-Container-Meta-") {
64 key := strings.TrimPrefix(k, "X-Container-Meta-")
65 metadata[key] = v[0]
66 }
67 }
68 return metadata
69}