|
|
|
@ -93,18 +93,9 @@ func (s *Session) Create(se *SessionEntry, q *WriteOptions) (string, *WriteMeta,
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Session) create(obj interface{}, q *WriteOptions) (string, *WriteMeta, error) { |
|
|
|
|
r := s.c.newRequest("PUT", "/v1/session/create") |
|
|
|
|
r.setWriteOptions(q) |
|
|
|
|
r.obj = obj |
|
|
|
|
rtt, resp, err := requireOK(s.c.doRequest(r)) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", nil, err |
|
|
|
|
} |
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
|
|
wm := &WriteMeta{RequestTime: rtt} |
|
|
|
|
var out struct{ ID string } |
|
|
|
|
if err := decodeBody(resp, &out); err != nil { |
|
|
|
|
wm, err := s.c.write("/v1/session/create", obj, &out, q) |
|
|
|
|
if err != nil { |
|
|
|
|
return "", nil, err |
|
|
|
|
} |
|
|
|
|
return out.ID, wm, nil |
|
|
|
@ -112,35 +103,20 @@ func (s *Session) create(obj interface{}, q *WriteOptions) (string, *WriteMeta,
|
|
|
|
|
|
|
|
|
|
// Destroy invalides a given session
|
|
|
|
|
func (s *Session) Destroy(id string, q *WriteOptions) (*WriteMeta, error) { |
|
|
|
|
r := s.c.newRequest("PUT", "/v1/session/destroy/"+id) |
|
|
|
|
r.setWriteOptions(q) |
|
|
|
|
rtt, resp, err := requireOK(s.c.doRequest(r)) |
|
|
|
|
wm, err := s.c.write("/v1/session/destroy/"+id, nil, nil, q) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
resp.Body.Close() |
|
|
|
|
|
|
|
|
|
wm := &WriteMeta{RequestTime: rtt} |
|
|
|
|
return wm, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Renew renews the TTL on a given session
|
|
|
|
|
func (s *Session) Renew(id string, q *WriteOptions) (*SessionEntry, *WriteMeta, error) { |
|
|
|
|
r := s.c.newRequest("PUT", "/v1/session/renew/"+id) |
|
|
|
|
r.setWriteOptions(q) |
|
|
|
|
rtt, resp, err := requireOK(s.c.doRequest(r)) |
|
|
|
|
var entries []*SessionEntry |
|
|
|
|
wm, err := s.c.write("/v1/session/renew/"+id, nil, &entries, q) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
} |
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
|
|
wm := &WriteMeta{RequestTime: rtt} |
|
|
|
|
|
|
|
|
|
var entries []*SessionEntry |
|
|
|
|
if err := decodeBody(resp, &entries); err != nil { |
|
|
|
|
return nil, wm, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(entries) > 0 { |
|
|
|
|
return entries[0], wm, nil |
|
|
|
|
} |
|
|
|
|