forked from gophercloud/gophercloud
/
results.go
85 lines (68 loc) · 1.83 KB
/
results.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package acls
import (
"encoding/json"
"time"
"github.com/yyf330/gophercloud"
)
// ACL represents an ACL on a resource.
type ACL map[string]ACLDetails
// ACLDetails represents the details of an ACL.
type ACLDetails struct {
// Created is when the ACL was created.
Created time.Time `json:"-"`
// ProjectAccess denotes project-level access of the resource.
ProjectAccess bool `json:"project-access"`
// Updated is when the ACL was updated
Updated time.Time `json:"-"`
// Users are the UserIDs who have access to the resource.
Users []string `json:"users"`
}
func (r *ACLDetails) UnmarshalJSON(b []byte) error {
type tmp ACLDetails
var s struct {
tmp
Created gophercloud.JSONRFC3339NoZ `json:"created"`
Updated gophercloud.JSONRFC3339NoZ `json:"updated"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = ACLDetails(s.tmp)
r.Created = time.Time(s.Created)
r.Updated = time.Time(s.Updated)
return nil
}
// ACLRef represents an ACL reference.
type ACLRef string
type commonResult struct {
gophercloud.Result
}
// Extract interprets any commonResult as an ACL.
func (r commonResult) Extract() (*ACL, error) {
var s *ACL
err := r.ExtractInto(&s)
return s, err
}
// ACLResult is the response from a Get operation. Call its Extract method
// to interpret it as an ACL.
type ACLResult struct {
commonResult
}
// ACLRefResult is the response from a Set or Update operation. Call its
// Extract method to interpret it as an ACLRef.
type ACLRefResult struct {
gophercloud.Result
}
func (r ACLRefResult) Extract() (*ACLRef, error) {
var s struct {
ACLRef ACLRef `json:"acl_ref"`
}
err := r.ExtractInto(&s)
return &s.ACLRef, err
}
// DeleteResult is the response from a Delete operation. Call its ExtractErr to
// determine if the request succeeded or failed.
type DeleteResult struct {
gophercloud.ErrResult
}