-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.go
47 lines (40 loc) · 933 Bytes
/
auth.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
package service
import (
"log"
"github.com/rudeigerc/broker-gateway/mapper"
"github.com/rudeigerc/broker-gateway/model"
)
type Auth struct {
}
func (a Auth) Sign(firmName string) model.Firm {
m := mapper.NewMapper()
firm := model.Firm{
FirmName: firmName,
}
err := m.Create(&firm)
if err != nil {
log.Printf("[service.auth.Sign] [ERROR] %s", err)
}
return firm
}
func (a Auth) Validate(firmID int) model.Firm {
m := mapper.NewMapper()
firm := model.Firm{}
err := m.FirstByID(&firm, firmID)
if err != nil {
log.Printf("[service.auth.Validate] [ERROR] %s", err)
}
return firm
}
func (a Auth) FirmNameByID(firmID int) string {
return a.Validate(firmID).FirmName
}
func (a Auth) FirmIDByName(firmName string) int {
m := mapper.NewMapper()
firm := model.Firm{}
err := m.FirstByFirmName(&firm, firmName)
if err != nil {
log.Printf("[service.auth.FirmIDByName] [ERROR] %s", err)
}
return firm.FirmID
}