-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscoveryCache.go
50 lines (38 loc) · 976 Bytes
/
discoveryCache.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
package gormid
import (
"log"
"github.com/Schrodinger-Box/openid-go"
"gorm.io/gorm"
"github.com/Schrodinger-Box/gormid/models"
)
type discoveryCache struct {
db *gorm.DB
}
type DiscoveredInfo struct {
opEndpoint string
opLocalID string
claimedID string
}
func (s *DiscoveredInfo) OpEndpoint() string {
return s.opEndpoint
}
func (s *DiscoveredInfo) OpLocalID() string {
return s.opLocalID
}
func (s *DiscoveredInfo) ClaimedID() string {
return s.claimedID
}
func (d *discoveryCache) Put(id string, info openid.DiscoveredInfo) {
dC := &models.DiscoveryCache{id, info.OpEndpoint(), info.OpLocalID(), info.ClaimedID()}
if err := d.db.Create(&dC).Error; err != nil {
log.Println(err)
}
}
func (d *discoveryCache) Get(id string) openid.DiscoveredInfo {
dC := &models.DiscoveryCache{}
if err := d.db.Where("cache_id = ?", id).First(&dC).Error; err != nil {
return nil
}
sDI := &DiscoveredInfo{dC.Endpoint, dC.LocalID, dC.ClaimedID}
return sDI
}