-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository.go
41 lines (35 loc) · 1021 Bytes
/
repository.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
package id
import (
"fmt"
"github.com/deadcheat/cashew"
"github.com/deadcheat/cashew/values/consts"
"github.com/rs/xid"
)
// Repository id repository implementation
type Repository struct{}
// New return new IDRepository
func New() cashew.IDRepository {
return new(Repository)
}
// Issue creates new id
func (r *Repository) Issue(t cashew.TicketType) string {
return fmt.Sprintf("%s-%s", prefix(t), xid.New().String())
}
// make prefix string from ticket type
func prefix(t cashew.TicketType) string {
switch t {
case cashew.TicketTypeLogin:
return consts.PrefixLoginTicket
case cashew.TicketTypeService:
return consts.PrefixServiceTicket
case cashew.TicketTypeTicketGranting:
return consts.PrefixTicketGrantingCookie
case cashew.TicketTypeProxy:
return consts.PrefixProxyTicket
case cashew.TicketTypeProxyGranting:
return consts.PrefixProxyGrantingTicket
case cashew.TicketTypeProxyGrantingIOU:
return consts.PrefixProxyGrantingTicketIOU
}
panic("invalid ticket type may be creating")
}