-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.go
More file actions
50 lines (42 loc) · 926 Bytes
/
Copy pathtoken.go
File metadata and controls
50 lines (42 loc) · 926 Bytes
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
//
// token.go
//
// Created by Frederic DELBOS - fred@hyperboloide.com on Nov 10 2014.
//
package main
import (
"github.com/dchest/uniuri"
)
type Token struct {
Key string `json:"key"`
Service string `json:"service"`
Identifier string `json:"identifier,omitempty"`
}
type TokenService struct {
Service string
cache Cache
}
func (ts *TokenService) NewToken(service string) (*Token, error) {
token := &Token{
Key: uniuri.New(),
Service: service,
Identifier: "",
}
if err := ts.Set(token); err != nil {
return nil, err
}
return token, nil
}
func (ts *TokenService) Get(key string) (*Token, error) {
token := new(Token)
if err := ts.cache.Get(key, token); err != nil {
return nil, err
}
return token, nil
}
func (ts *TokenService) Del(key string) error {
return ts.cache.Del(key)
}
func (ts *TokenService) Set(token *Token) error {
return ts.cache.Set(token.Key, token)
}