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