正在显示
35 个修改的文件
包含
1168 行增加
和
1 行删除
deploy/k8s/dev/install.sh
0 → 100644
1 | +#!/bin/bash | ||
2 | +export PATH=/root/local/bin:$PATH | ||
3 | +kubectl -n <replace-your-k8s-namespace> get pods | grep -q project | ||
4 | +if [ "$?" == "1" ];then | ||
5 | + kubectl create -f /tmp/dev/project/project.yaml --record | ||
6 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q project | ||
7 | + if [ "$?" == "0" ];then | ||
8 | + echo "project service install success!" | ||
9 | + else | ||
10 | + echo "project service install fail!" | ||
11 | + fi | ||
12 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q project | ||
13 | + if [ "$?" == "0" ];then | ||
14 | + echo "project deployment install success!" | ||
15 | + else | ||
16 | + echo "project deployment install fail!" | ||
17 | + fi | ||
18 | +else | ||
19 | + kubectl delete -f /tmp/dev/project/project.yaml | ||
20 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q project | ||
21 | + while [ "$?" == "0" ] | ||
22 | + do | ||
23 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q project | ||
24 | + done | ||
25 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q project | ||
26 | + while [ "$?" == "0" ] | ||
27 | + do | ||
28 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q project | ||
29 | + done | ||
30 | + kubectl create -f /tmp/dev/project/project.yaml --record | ||
31 | + kubectl -n <replace-your-k8s-namespace> get svc | grep -q project | ||
32 | + if [ "$?" == "0" ];then | ||
33 | + echo "project service update success!" | ||
34 | + else | ||
35 | + echo "project service update fail!" | ||
36 | + fi | ||
37 | + kubectl -n <replace-your-k8s-namespace> get pods | grep -q project | ||
38 | + if [ "$?" == "0" ];then | ||
39 | + echo "project deployment update success!" | ||
40 | + else | ||
41 | + echo "project deployment update fail!" | ||
42 | + fi | ||
43 | +fi |
deploy/k8s/dev/project.yaml
0 → 100644
1 | +apiVersion: v1 | ||
2 | +kind: Service | ||
3 | +metadata: | ||
4 | + name: project | ||
5 | + namespace: <replace-your-k8s-namespace> | ||
6 | + labels: | ||
7 | + k8s-app: project | ||
8 | +spec: | ||
9 | + ports: | ||
10 | + - name: "http" | ||
11 | + port: 80 | ||
12 | + targetPort: 8082 | ||
13 | + selector: | ||
14 | + k8s-app: project | ||
15 | +--- | ||
16 | +apiVersion: extensions/v1beta1 | ||
17 | +kind: Deployment | ||
18 | +metadata: | ||
19 | + name: project | ||
20 | + namespace: <replace-your-k8s-namespace> | ||
21 | + labels: | ||
22 | + k8s-app: project | ||
23 | +spec: | ||
24 | + replicas: 1 | ||
25 | + template: | ||
26 | + metadata: | ||
27 | + labels: | ||
28 | + k8s-app: project | ||
29 | + spec: | ||
30 | + affinity: | ||
31 | + nodeAffinity: | ||
32 | + preferredDuringSchedulingIgnoredDuringExecution: | ||
33 | + - preference: {} | ||
34 | + weight: 100 | ||
35 | + requiredDuringSchedulingIgnoredDuringExecution: | ||
36 | + nodeSelectorTerms: | ||
37 | + - matchExpressions: | ||
38 | + - key: kubernetes.io/hostname | ||
39 | + operator: In | ||
40 | + values: | ||
41 | + - cn-hangzhou.i-bp1djh1xn7taumbue1ze | ||
42 | + - cn-hangzhou.i-bp1djh1xn7taumbue1zd | ||
43 | + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb | ||
44 | + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy | ||
45 | + containers: | ||
46 | + - name: project | ||
47 | + image: 192.168.0.243:5000/mmm/project:dev | ||
48 | + imagePullPolicy: Always | ||
49 | + ports: | ||
50 | + - containerPort: 8082 | ||
51 | + volumeMounts: | ||
52 | + - mountPath: /opt/logs | ||
53 | + name: accesslogs | ||
54 | + env: | ||
55 | + - name: LOG_LEVEL | ||
56 | + value: "debug" | ||
57 | + - name: ERROR_BASE_CODE | ||
58 | + value: "1" | ||
59 | + - name: ERROR_BASE_CODE_MULTIPLE | ||
60 | + value: "1000" | ||
61 | + volumes: | ||
62 | + - name: accesslogs | ||
63 | + emptyDir: {} |
@@ -2,4 +2,12 @@ module gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway | @@ -2,4 +2,12 @@ module gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway | ||
2 | 2 | ||
3 | go 1.16 | 3 | go 1.16 |
4 | 4 | ||
5 | -require github.com/beego/beego/v2 v2.0.1 | 5 | +require ( |
6 | + github.com/beego/beego/v2 v2.0.1 | ||
7 | + github.com/boombuler/barcode v1.0.1 | ||
8 | + github.com/dgrijalva/jwt-go v3.2.0+incompatible | ||
9 | + github.com/go-pg/pg/v10 v10.10.1 | ||
10 | + github.com/go-redis/redis v6.14.2+incompatible | ||
11 | + github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6 | ||
12 | + github.com/sony/sonyflake v1.0.0 | ||
13 | +) |
pkg/application/factory/domain_service.go
0 → 100644
1 | +package factory |
pkg/application/factory/repository.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/transaction/pg" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/repository" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateLoginAccessRepository(options map[string]interface{}) (domain.LoginAccessRepository, error) { | ||
10 | + var transactionContext *pg.TransactionContext | ||
11 | + if value, ok := options["transactionContext"]; ok { | ||
12 | + transactionContext = value.(*pg.TransactionContext) | ||
13 | + } | ||
14 | + return repository.NewLoginAccessRepository(transactionContext) | ||
15 | +} |
pkg/application/factory/transaction.go
0 → 100644
1 | +package factory | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + pG "github.com/linmadan/egglib-go/transaction/pg" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg" | ||
7 | +) | ||
8 | + | ||
9 | +func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) { | ||
10 | + return pG.NewPGTransactionContext(pg.DB), nil | ||
11 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type GetQrcodeForLoginQuery struct { | ||
10 | +} | ||
11 | + | ||
12 | +func (getQrcodeForLoginQuery *GetQrcodeForLoginQuery) Valid(validation *validation.Validation) { | ||
13 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
14 | +} | ||
15 | + | ||
16 | +func (getQrcodeForLoginQuery *GetQrcodeForLoginQuery) ValidateQuery() error { | ||
17 | + valid := validation.Validation{} | ||
18 | + b, err := valid.Valid(getQrcodeForLoginQuery) | ||
19 | + if err != nil { | ||
20 | + return err | ||
21 | + } | ||
22 | + if !b { | ||
23 | + for _, validErr := range valid.Errors { | ||
24 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
25 | + } | ||
26 | + } | ||
27 | + return nil | ||
28 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginByAccountQuery struct { | ||
10 | + // 账号 | ||
11 | + Account string `json:"account,omitempty"` | ||
12 | + // 密码 | ||
13 | + Passwd string `json:"passwd,omitempty"` | ||
14 | +} | ||
15 | + | ||
16 | +func (loginByAccountQuery *LoginByAccountQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (loginByAccountQuery *LoginByAccountQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(loginByAccountQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginByScanQrcodeQuery struct { | ||
10 | + // 登录认证的凭证 | ||
11 | + AuthCode string `json:"authCode,omitempty"` | ||
12 | +} | ||
13 | + | ||
14 | +func (loginByScanQrcodeQuery *LoginByScanQrcodeQuery) Valid(validation *validation.Validation) { | ||
15 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
16 | +} | ||
17 | + | ||
18 | +func (loginByScanQrcodeQuery *LoginByScanQrcodeQuery) ValidateQuery() error { | ||
19 | + valid := validation.Validation{} | ||
20 | + b, err := valid.Valid(loginByScanQrcodeQuery) | ||
21 | + if err != nil { | ||
22 | + return err | ||
23 | + } | ||
24 | + if !b { | ||
25 | + for _, validErr := range valid.Errors { | ||
26 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
27 | + } | ||
28 | + } | ||
29 | + return nil | ||
30 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginBySmsCodeQuery struct { | ||
10 | + // 手机号 | ||
11 | + Phone string `json:"phone,omitempty"` | ||
12 | + // 短信验证码 | ||
13 | + SmsCode string `json:"smsCode,omitempty"` | ||
14 | +} | ||
15 | + | ||
16 | +func (loginBySmsCodeQuery *LoginBySmsCodeQuery) Valid(validation *validation.Validation) { | ||
17 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
18 | +} | ||
19 | + | ||
20 | +func (loginBySmsCodeQuery *LoginBySmsCodeQuery) ValidateQuery() error { | ||
21 | + valid := validation.Validation{} | ||
22 | + b, err := valid.Valid(loginBySmsCodeQuery) | ||
23 | + if err != nil { | ||
24 | + return err | ||
25 | + } | ||
26 | + if !b { | ||
27 | + for _, validErr := range valid.Errors { | ||
28 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
29 | + } | ||
30 | + } | ||
31 | + return nil | ||
32 | +} |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/beego/beego/v2/core/validation" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginInfoByAuthCodeQuery struct { | ||
10 | + // 登录认证的凭证 | ||
11 | + AuthCode string `json:"authCode,omitempty"` | ||
12 | + // 公司id | ||
13 | + CompanyId string `json:"companyId,omitempty"` | ||
14 | + // 组织id | ||
15 | + OrganizationId string `json:"organizationId,omitempty"` | ||
16 | +} | ||
17 | + | ||
18 | +func (loginInfoByAuthCodeQuery *LoginInfoByAuthCodeQuery) Valid(validation *validation.Validation) { | ||
19 | + validation.SetError("CustomValid", "未实现的自定义认证") | ||
20 | +} | ||
21 | + | ||
22 | +func (loginInfoByAuthCodeQuery *LoginInfoByAuthCodeQuery) ValidateQuery() error { | ||
23 | + valid := validation.Validation{} | ||
24 | + b, err := valid.Valid(loginInfoByAuthCodeQuery) | ||
25 | + if err != nil { | ||
26 | + return err | ||
27 | + } | ||
28 | + if !b { | ||
29 | + for _, validErr := range valid.Errors { | ||
30 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
31 | + } | ||
32 | + } | ||
33 | + return nil | ||
34 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/loginAccess/query" | ||
7 | +) | ||
8 | + | ||
9 | +// 登录访问 | ||
10 | +type LoginAccessService struct { | ||
11 | +} | ||
12 | + | ||
13 | +// 获取扫码登录用的二维码信息 | ||
14 | +func (loginAccessService *LoginAccessService) GetQrcodeForLogin(getQrcodeForLoginQuery *query.GetQrcodeForLoginQuery) (interface{}, error) { | ||
15 | + if err := getQrcodeForLoginQuery.ValidateQuery(); err != nil { | ||
16 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
17 | + } | ||
18 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
19 | + if err != nil { | ||
20 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
21 | + } | ||
22 | + if err := transactionContext.StartTransaction(); err != nil { | ||
23 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
24 | + } | ||
25 | + defer func() { | ||
26 | + transactionContext.RollbackTransaction() | ||
27 | + }() | ||
28 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
29 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
30 | + } | ||
31 | + return nil, nil | ||
32 | +} | ||
33 | + | ||
34 | +// 使用手机号和密码登录系统 | ||
35 | +func (loginAccessService *LoginAccessService) LoginByAccount(loginByAccountQuery *query.LoginByAccountQuery) (interface{}, error) { | ||
36 | + if err := loginByAccountQuery.ValidateQuery(); err != nil { | ||
37 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
38 | + } | ||
39 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
40 | + if err != nil { | ||
41 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
42 | + } | ||
43 | + if err := transactionContext.StartTransaction(); err != nil { | ||
44 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
45 | + } | ||
46 | + defer func() { | ||
47 | + transactionContext.RollbackTransaction() | ||
48 | + }() | ||
49 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
50 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
51 | + } | ||
52 | + return nil, nil | ||
53 | +} | ||
54 | + | ||
55 | +// 询问扫二维码方式登录的状态 | ||
56 | +func (loginAccessService *LoginAccessService) LoginByScanQrcode(loginByScanQrcodeQuery *query.LoginByScanQrcodeQuery) (interface{}, error) { | ||
57 | + if err := loginByScanQrcodeQuery.ValidateQuery(); err != nil { | ||
58 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
59 | + } | ||
60 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
61 | + if err != nil { | ||
62 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
63 | + } | ||
64 | + if err := transactionContext.StartTransaction(); err != nil { | ||
65 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
66 | + } | ||
67 | + defer func() { | ||
68 | + transactionContext.RollbackTransaction() | ||
69 | + }() | ||
70 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
71 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
72 | + } | ||
73 | + return nil, nil | ||
74 | +} | ||
75 | + | ||
76 | +// 使用手机号和短信验证码登录系统 | ||
77 | +func (loginAccessService *LoginAccessService) LoginBySmsCode(loginBySmsCodeQuery *query.LoginBySmsCodeQuery) (interface{}, error) { | ||
78 | + if err := loginBySmsCodeQuery.ValidateQuery(); err != nil { | ||
79 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
80 | + } | ||
81 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
82 | + if err != nil { | ||
83 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
84 | + } | ||
85 | + if err := transactionContext.StartTransaction(); err != nil { | ||
86 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
87 | + } | ||
88 | + defer func() { | ||
89 | + transactionContext.RollbackTransaction() | ||
90 | + }() | ||
91 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
92 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
93 | + } | ||
94 | + return nil, nil | ||
95 | +} | ||
96 | + | ||
97 | +// 获取具体的进入系统的凭证 | ||
98 | +func (loginAccessService *LoginAccessService) LoginInfoByAuthCode(loginInfoByAuthCodeQuery *query.LoginInfoByAuthCodeQuery) (interface{}, error) { | ||
99 | + if err := loginInfoByAuthCodeQuery.ValidateQuery(); err != nil { | ||
100 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
101 | + } | ||
102 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
103 | + if err != nil { | ||
104 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
105 | + } | ||
106 | + if err := transactionContext.StartTransaction(); err != nil { | ||
107 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
108 | + } | ||
109 | + defer func() { | ||
110 | + transactionContext.RollbackTransaction() | ||
111 | + }() | ||
112 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
113 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
114 | + } | ||
115 | + return nil, nil | ||
116 | +} | ||
117 | + | ||
118 | +func NewLoginAccessService(options map[string]interface{}) *LoginAccessService { | ||
119 | + newLoginAccessService := &LoginAccessService{} | ||
120 | + return newLoginAccessService | ||
121 | +} |
1 | +package services | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/dgrijalva/jwt-go" | ||
7 | + "github.com/sony/sonyflake" | ||
8 | +) | ||
9 | + | ||
10 | +var idwork *sonyflake.Sonyflake | ||
11 | + | ||
12 | +func init() { | ||
13 | + setting := sonyflake.Settings{ | ||
14 | + MachineID: func() (uint16, error) { | ||
15 | + return 1, nil | ||
16 | + }, | ||
17 | + CheckMachineID: func(u uint16) bool { | ||
18 | + return true | ||
19 | + }, | ||
20 | + } | ||
21 | + idwork = sonyflake.NewSonyflake(setting) | ||
22 | +} | ||
23 | + | ||
24 | +const ( | ||
25 | + qrcodeExpires int64 = 3600 //二维码的有效时长,单位:秒 | ||
26 | + qrcodeSecret string = "27e6741f0e0b658c" | ||
27 | +) | ||
28 | + | ||
29 | +type qrcodeMessage struct { | ||
30 | + Key string `json:"key"` | ||
31 | + jwt.StandardClaims | ||
32 | +} | ||
33 | + | ||
34 | +func (msg *qrcodeMessage) GenrateToken() (string, error) { | ||
35 | + id, err := idwork.NextID() | ||
36 | + if err != nil { | ||
37 | + return "", fmt.Errorf("生成二维信息失败:%w", err) | ||
38 | + } | ||
39 | + msg.Key = fmt.Sprint(id) | ||
40 | + //TODO jwt | ||
41 | + return "", nil | ||
42 | +} | ||
43 | + | ||
44 | +func (msg *qrcodeMessage) ParseToken(token string) error { | ||
45 | + //TODO jwt | ||
46 | + return nil | ||
47 | +} |
1 | +package services | ||
2 | + | ||
3 | +import ( | ||
4 | + "bytes" | ||
5 | + "context" | ||
6 | + "encoding/base64" | ||
7 | + "image/png" | ||
8 | + | ||
9 | + "github.com/boombuler/barcode" | ||
10 | + "github.com/boombuler/barcode/qr" | ||
11 | +) | ||
12 | + | ||
13 | +//LoginAccessService 登录功能 | ||
14 | +type LoginAccessService struct { | ||
15 | +} | ||
16 | + | ||
17 | +//LoginByAccount 账号登录获取authcode和可选择列表 | ||
18 | +func (srv LoginAccessService) LoginByAccount(ctx context.Context) error { | ||
19 | + return nil | ||
20 | +} | ||
21 | + | ||
22 | +//LoginBySmsCode 短信验证码登录获取authcode和可选择列表 | ||
23 | +func (srv LoginAccessService) LoginBySmsCode(ctx context.Context) error { | ||
24 | + return nil | ||
25 | +} | ||
26 | + | ||
27 | +//LoginByAuthCode 使用authCode进行登录获取accessToken和用户权限信息 | ||
28 | +func (srv LoginAccessService) LoginInfoByAuthCode(ctx context.Context) error { | ||
29 | + return nil | ||
30 | +} | ||
31 | + | ||
32 | +//GetQrcodeLogin 获取用于登录的二维码以及相应的key数据 | ||
33 | +func (srv LoginAccessService) GetQrcodeForLogin(ctx context.Context) error { | ||
34 | + | ||
35 | + qrCode, err := qr.Encode("Hello World", qr.M, qr.Auto) | ||
36 | + if err != nil { | ||
37 | + return err | ||
38 | + } | ||
39 | + // Scale the barcode to 200x200 pixels | ||
40 | + qrCode, err = barcode.Scale(qrCode, 200, 200) | ||
41 | + if err != nil { | ||
42 | + return err | ||
43 | + } | ||
44 | + var imgByte bytes.Buffer | ||
45 | + // encode the barcode as png | ||
46 | + err = png.Encode(&imgByte, qrCode) | ||
47 | + if err != nil { | ||
48 | + return err | ||
49 | + } | ||
50 | + imgBase64 := base64.StdEncoding.EncodeToString(imgByte.Bytes()) | ||
51 | + _ = imgBase64 | ||
52 | + return err | ||
53 | +} | ||
54 | + | ||
55 | +//ValidLoginForQrcode 检查以扫描二维码方式进行登录的状态 | ||
56 | +func (srv LoginAccessService) LoginByScanQrcode(ctx context.Context) error { | ||
57 | + return nil | ||
58 | +} | ||
59 | + | ||
60 | +// ValidToken 检查token信息 | ||
61 | +func (srv LoginAccessService) ValidAccessToken(ctx context.Context) error { | ||
62 | + return nil | ||
63 | +} | ||
64 | + | ||
65 | +// AuthCodeToAccessToken 用authcode交换accessToken | ||
66 | +func (srv LoginAccessService) AuthCodeToAccessToken(ctx context.Context) error { | ||
67 | + return nil | ||
68 | +} |
pkg/constant/common.go
0 → 100644
pkg/constant/postgresql.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +import "os" | ||
4 | + | ||
5 | +var POSTGRESQL_DB_NAME = "project" | ||
6 | +var POSTGRESQL_USER = "postgres" | ||
7 | +var POSTGRESQL_PASSWORD = "" | ||
8 | +var POSTGRESQL_HOST = "127.0.0.1" | ||
9 | +var POSTGRESQL_PORT = "32432" | ||
10 | +var DISABLE_CREATE_TABLE = false | ||
11 | +var DISABLE_SQL_GENERATE_PRINT = false | ||
12 | + | ||
13 | +func init() { | ||
14 | + if os.Getenv("POSTGRESQL_DB_NAME") != "" { | ||
15 | + POSTGRESQL_DB_NAME = os.Getenv("POSTGRESQL_DB_NAME") | ||
16 | + } | ||
17 | + if os.Getenv("POSTGRESQL_USER") != "" { | ||
18 | + POSTGRESQL_USER = os.Getenv("POSTGRESQL_USER") | ||
19 | + } | ||
20 | + if os.Getenv("POSTGRESQL_PASSWORD") != "" { | ||
21 | + POSTGRESQL_PASSWORD = os.Getenv("POSTGRESQL_PASSWORD") | ||
22 | + } | ||
23 | + if os.Getenv("POSTGRESQL_HOST") != "" { | ||
24 | + POSTGRESQL_HOST = os.Getenv("POSTGRESQL_HOST") | ||
25 | + } | ||
26 | + if os.Getenv("POSTGRESQL_PORT") != "" { | ||
27 | + POSTGRESQL_PORT = os.Getenv("POSTGRESQL_PORT") | ||
28 | + } | ||
29 | + if os.Getenv("DISABLE_CREATE_TABLE") != "" { | ||
30 | + DISABLE_CREATE_TABLE = true | ||
31 | + } | ||
32 | + if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" { | ||
33 | + DISABLE_SQL_GENERATE_PRINT = true | ||
34 | + } | ||
35 | +} |
pkg/constant/validation.go
0 → 100644
1 | +package constant | ||
2 | + | ||
3 | +var ValidationMessageTmpls = map[string]string{ | ||
4 | + "Required": "不能为空", | ||
5 | + "Min": "最小值: %d", | ||
6 | + "Max": "最大值: %d", | ||
7 | + "Range": "数值的范围 %d - %d", | ||
8 | + "MinSize": "最小长度: %d", | ||
9 | + "MaxSize": "最大长度: %d", | ||
10 | + "Length": "指定长度: %d", | ||
11 | + "Alpha": "必须为有效的字母字符", | ||
12 | + "Numeric": "必须为有效的数字", | ||
13 | + "AlphaNumeric": "必须为有效的字母或数字", | ||
14 | + "Match": "必须匹配 %s", | ||
15 | + "NoMatch": "必须不匹配 %s", | ||
16 | + "AlphaDash": "必须为字母、数字或横杠(-_)", | ||
17 | + "Email": "必须为邮箱格式", | ||
18 | + "IP": "必须为有效的IP格式", | ||
19 | + "Base64": "必须为有效的base64字符", | ||
20 | + "Mobile": "必须有效的手机号码", | ||
21 | + "Tel": "必须是有效的电话号码", | ||
22 | + "Phone": "必须是有效的电话或手机号码", | ||
23 | + "ZipCode": "必须是有效的邮政编码", | ||
24 | +} |
pkg/domain/login_access.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +// 登录凭证存储 | ||
6 | +type LoginAccess struct { | ||
7 | + LoginAccessId int64 `json:"loginAccessId"` | ||
8 | + // 账号 | ||
9 | + Account string `json:"account"` | ||
10 | + // 对应平台 | ||
11 | + Platform string `json:"platform"` | ||
12 | + // 公司id | ||
13 | + CompanyId int64 `json:"companyId"` | ||
14 | + // 组织id | ||
15 | + OrganizationId int64 `json:"organizationId"` | ||
16 | + // 登录凭证存储 | ||
17 | + AccessToken string `json:"accessToken"` | ||
18 | + // 刷新登录凭证 | ||
19 | + RefreshToken string `json:"refreshToken"` | ||
20 | + // 登录凭证过期时间,时间戳精度秒 | ||
21 | + AccessExpired int64 `json:"accessExpired"` | ||
22 | + // 刷新登录凭证过期时间,时间戳精度秒 | ||
23 | + RefreshExpired int64 `json:"refreshExpired"` | ||
24 | + // 创建时间 | ||
25 | + CreatedTime time.Time `json:"createdTime"` | ||
26 | + // 更新时间 | ||
27 | + UpdatedTime time.Time `json:"updatedTime"` | ||
28 | +} | ||
29 | + | ||
30 | +type LoginAccessRepository interface { | ||
31 | + Save(loginAccess *LoginAccess) (*LoginAccess, error) | ||
32 | + Remove(loginAccess *LoginAccess) (*LoginAccess, error) | ||
33 | + FindOne(queryOptions map[string]interface{}) (*LoginAccess, error) | ||
34 | + Find(queryOptions map[string]interface{}) (int64, []*LoginAccess, error) | ||
35 | +} | ||
36 | + | ||
37 | +func (loginAccess *LoginAccess) Identify() interface{} { | ||
38 | + if loginAccess.LoginAccessId == 0 { | ||
39 | + return nil | ||
40 | + } | ||
41 | + return loginAccess.LoginAccessId | ||
42 | +} | ||
43 | + | ||
44 | +func (loginAccess *LoginAccess) Update(data map[string]interface{}) error { | ||
45 | + if account, ok := data["account"]; ok { | ||
46 | + loginAccess.Account = account.(string) | ||
47 | + } | ||
48 | + if platform, ok := data["platform"]; ok { | ||
49 | + loginAccess.Platform = platform.(string) | ||
50 | + } | ||
51 | + if companyId, ok := data["companyId"]; ok { | ||
52 | + loginAccess.CompanyId = companyId.(int64) | ||
53 | + } | ||
54 | + if organizationId, ok := data["organizationId"]; ok { | ||
55 | + loginAccess.OrganizationId = organizationId.(int64) | ||
56 | + } | ||
57 | + if accessToken, ok := data["accessToken"]; ok { | ||
58 | + loginAccess.AccessToken = accessToken.(string) | ||
59 | + } | ||
60 | + if refreshToken, ok := data["refreshToken"]; ok { | ||
61 | + loginAccess.RefreshToken = refreshToken.(string) | ||
62 | + } | ||
63 | + if accessExpired, ok := data["accessExpired"]; ok { | ||
64 | + loginAccess.AccessExpired = accessExpired.(int64) | ||
65 | + } | ||
66 | + if refreshExpired, ok := data["refreshExpired"]; ok { | ||
67 | + loginAccess.RefreshExpired = refreshExpired.(int64) | ||
68 | + } | ||
69 | + if createdTime, ok := data["createdTime"]; ok { | ||
70 | + loginAccess.CreatedTime = createdTime.(time.Time) | ||
71 | + } | ||
72 | + if updatedTime, ok := data["updatedTime"]; ok { | ||
73 | + loginAccess.UpdatedTime = updatedTime.(time.Time) | ||
74 | + } | ||
75 | + return nil | ||
76 | +} |
pkg/domain/login_qrcode.go
0 → 100644
1 | +package domain |
pkg/domain/login_token.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +const ( | ||
4 | + loginTokenSecret string = "bbe35ad433dd8e67" | ||
5 | +) | ||
6 | + | ||
7 | +type LoginToken struct { | ||
8 | + Account string `json:"account"` | ||
9 | + CompanyId int64 `json:"companyId"` | ||
10 | + DepartmentId int64 `json:"departmentId"` | ||
11 | +} | ||
12 | + | ||
13 | +func (t *LoginToken) GenerateAccessToken() error { | ||
14 | + | ||
15 | + return nil | ||
16 | +} | ||
17 | + | ||
18 | +func (t *LoginToken) GenerateRefreshToken() error { | ||
19 | + | ||
20 | + return nil | ||
21 | +} | ||
22 | + | ||
23 | +func (t *LoginToken) ParseToken(str string) error { | ||
24 | + return nil | ||
25 | +} |
pkg/infrastructure/cache/login_access.go
0 → 100644
1 | +package cache | ||
2 | + | ||
3 | +import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
4 | + | ||
5 | +type LoginAccessCache struct { | ||
6 | +} | ||
7 | + | ||
8 | +func (ca LoginAccessCache) Save(param *domain.LoginAccess) (*domain.LoginAccess, error) { | ||
9 | + return nil, nil | ||
10 | +} | ||
11 | +func (ca LoginAccessCache) Remove(param *domain.LoginAccess) (*domain.LoginAccess, error) { | ||
12 | + return nil, nil | ||
13 | +} | ||
14 | + | ||
15 | +func (ca LoginAccessCache) FindOne(account string, platform string) (*domain.LoginAccess, error) { | ||
16 | + return nil, nil | ||
17 | +} |
pkg/infrastructure/cache/login_qrcode.go
0 → 100644
pkg/infrastructure/cache/redis.go
0 → 100644
1 | +package cache | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/go-redis/redis" | ||
7 | +) | ||
8 | + | ||
9 | +var clientRedis *redis.Client | ||
10 | + | ||
11 | +const ( | ||
12 | + keyPrefix string = "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway" | ||
13 | +) | ||
14 | + | ||
15 | +func Init() *redis.Client { | ||
16 | + options := redis.Options{ | ||
17 | + Network: "tcp", | ||
18 | + Addr: fmt.Sprintf("%s:%s", "127.0.0.1", "6379"), | ||
19 | + Dialer: nil, | ||
20 | + OnConnect: nil, | ||
21 | + Password: "", | ||
22 | + DB: 1, | ||
23 | + MaxRetries: 0, | ||
24 | + MinRetryBackoff: 0, | ||
25 | + MaxRetryBackoff: 0, | ||
26 | + DialTimeout: 0, | ||
27 | + ReadTimeout: 0, | ||
28 | + WriteTimeout: 0, | ||
29 | + PoolSize: 0, | ||
30 | + MinIdleConns: 0, | ||
31 | + MaxConnAge: 0, | ||
32 | + PoolTimeout: 0, | ||
33 | + IdleTimeout: 0, | ||
34 | + IdleCheckFrequency: 0, | ||
35 | + TLSConfig: nil, | ||
36 | + } | ||
37 | + // 新建一个client | ||
38 | + clientRedis = redis.NewClient(&options) | ||
39 | + return clientRedis | ||
40 | +} |
pkg/infrastructure/pg/init.go
0 → 100644
1 | +package pg | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/go-pg/pg/v10" | ||
7 | + "github.com/go-pg/pg/v10/orm" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" | ||
9 | + | ||
10 | + //_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg/models" | ||
11 | + "github.com/linmadan/egglib-go/persistent/pg/hooks" | ||
12 | +) | ||
13 | + | ||
14 | +var DB *pg.DB | ||
15 | + | ||
16 | +func init() { | ||
17 | + DB = pg.Connect(&pg.Options{ | ||
18 | + User: constant.POSTGRESQL_USER, | ||
19 | + Password: constant.POSTGRESQL_PASSWORD, | ||
20 | + Database: constant.POSTGRESQL_DB_NAME, | ||
21 | + Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), | ||
22 | + }) | ||
23 | + if !constant.DISABLE_SQL_GENERATE_PRINT { | ||
24 | + DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) | ||
25 | + } | ||
26 | + m := []interface{}{} | ||
27 | + if !constant.DISABLE_CREATE_TABLE { | ||
28 | + for _, model := range m { | ||
29 | + err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ | ||
30 | + Temp: false, | ||
31 | + IfNotExists: true, | ||
32 | + FKConstraints: true, | ||
33 | + }) | ||
34 | + if err != nil { | ||
35 | + panic(err) | ||
36 | + } | ||
37 | + } | ||
38 | + } | ||
39 | +} |
pkg/infrastructure/pg/models/login_access.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +type LoginAccess struct { | ||
6 | + tableName string `pg:"login_accesss,alias:login_access"` | ||
7 | + | ||
8 | + LoginAccessId int64 `pg:",pk"` | ||
9 | + // 账号 | ||
10 | + Account string | ||
11 | + // 对应平台 | ||
12 | + Platform string | ||
13 | + // 公司id | ||
14 | + CompanyId int64 | ||
15 | + // 组织id | ||
16 | + OrganizationId int64 | ||
17 | + // 登录凭证存储 | ||
18 | + AccessToken string | ||
19 | + // 刷新登录凭证 | ||
20 | + RefreshToken string | ||
21 | + // 登录凭证过期时间,时间戳精度秒 | ||
22 | + AccessExpired int64 | ||
23 | + // 刷新登录凭证过期时间,时间戳精度秒 | ||
24 | + RefreshExpired int64 | ||
25 | + // 创建时间 | ||
26 | + CreatedTime time.Time | ||
27 | + // 更新时间 | ||
28 | + UpdatedTime time.Time | ||
29 | +} |
1 | +package transform | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg/models" | ||
6 | +) | ||
7 | + | ||
8 | +func TransformToLoginAccessDomainModelFromPgModels(loginAccessModel *models.LoginAccess) (*domain.LoginAccess, error) { | ||
9 | + return &domain.LoginAccess{ | ||
10 | + Account: loginAccessModel.Account, | ||
11 | + Platform: loginAccessModel.Platform, | ||
12 | + CompanyId: loginAccessModel.CompanyId, | ||
13 | + OrganizationId: loginAccessModel.OrganizationId, | ||
14 | + AccessToken: loginAccessModel.AccessToken, | ||
15 | + RefreshToken: loginAccessModel.RefreshToken, | ||
16 | + AccessExpired: loginAccessModel.AccessExpired, | ||
17 | + RefreshExpired: loginAccessModel.RefreshExpired, | ||
18 | + CreatedTime: loginAccessModel.CreatedTime, | ||
19 | + UpdatedTime: loginAccessModel.UpdatedTime, | ||
20 | + }, nil | ||
21 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + | ||
6 | + "github.com/go-pg/pg/v10" | ||
7 | + "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | ||
8 | + pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | ||
9 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg/models" | ||
12 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg/transform" | ||
13 | +) | ||
14 | + | ||
15 | +type LoginAccessRepository struct { | ||
16 | + transactionContext *pgTransaction.TransactionContext | ||
17 | +} | ||
18 | + | ||
19 | +func (repository *LoginAccessRepository) nextIdentify() (int64, error) { | ||
20 | + IdWorker, err := snowflake.NewIdWorker(1) | ||
21 | + if err != nil { | ||
22 | + return 0, err | ||
23 | + } | ||
24 | + id, err := IdWorker.NextId() | ||
25 | + return id, err | ||
26 | +} | ||
27 | +func (repository *LoginAccessRepository) Save(loginAccess *domain.LoginAccess) (*domain.LoginAccess, error) { | ||
28 | + sqlBuildFields := []string{ | ||
29 | + "account", | ||
30 | + "platform", | ||
31 | + "company_id", | ||
32 | + "organization_id", | ||
33 | + "access_token", | ||
34 | + "refresh_token", | ||
35 | + "access_expired", | ||
36 | + "refresh_expired", | ||
37 | + "created_time", | ||
38 | + "updated_time", | ||
39 | + } | ||
40 | + insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
41 | + insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields) | ||
42 | + returningFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields) | ||
43 | + updateFields := sqlbuilder.RemoveSqlFields(sqlBuildFields, "loginAccess_id") | ||
44 | + updateFieldsSnippet := sqlbuilder.SqlUpdateFieldsSnippet(updateFields) | ||
45 | + tx := repository.transactionContext.PgTx | ||
46 | + if loginAccess.Identify() == nil { | ||
47 | + loginAccessId, err := repository.nextIdentify() | ||
48 | + if err != nil { | ||
49 | + return loginAccess, err | ||
50 | + } else { | ||
51 | + loginAccess.LoginAccessId = loginAccessId | ||
52 | + } | ||
53 | + if _, err := tx.QueryOne( | ||
54 | + pg.Scan( | ||
55 | + &loginAccess.Account, | ||
56 | + &loginAccess.Platform, | ||
57 | + &loginAccess.CompanyId, | ||
58 | + &loginAccess.OrganizationId, | ||
59 | + &loginAccess.AccessToken, | ||
60 | + &loginAccess.RefreshToken, | ||
61 | + &loginAccess.AccessExpired, | ||
62 | + &loginAccess.RefreshExpired, | ||
63 | + &loginAccess.CreatedTime, | ||
64 | + &loginAccess.UpdatedTime, | ||
65 | + ), | ||
66 | + fmt.Sprintf("INSERT INTO login_accesss (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet), | ||
67 | + loginAccess.Account, | ||
68 | + loginAccess.Platform, | ||
69 | + loginAccess.CompanyId, | ||
70 | + loginAccess.OrganizationId, | ||
71 | + loginAccess.AccessToken, | ||
72 | + loginAccess.RefreshToken, | ||
73 | + loginAccess.AccessExpired, | ||
74 | + loginAccess.RefreshExpired, | ||
75 | + loginAccess.CreatedTime, | ||
76 | + loginAccess.UpdatedTime, | ||
77 | + ); err != nil { | ||
78 | + return loginAccess, err | ||
79 | + } | ||
80 | + } else { | ||
81 | + if _, err := tx.QueryOne( | ||
82 | + pg.Scan( | ||
83 | + &loginAccess.Account, | ||
84 | + &loginAccess.Platform, | ||
85 | + &loginAccess.CompanyId, | ||
86 | + &loginAccess.OrganizationId, | ||
87 | + &loginAccess.AccessToken, | ||
88 | + &loginAccess.RefreshToken, | ||
89 | + &loginAccess.AccessExpired, | ||
90 | + &loginAccess.RefreshExpired, | ||
91 | + &loginAccess.CreatedTime, | ||
92 | + &loginAccess.UpdatedTime, | ||
93 | + ), | ||
94 | + fmt.Sprintf("UPDATE login_accesss SET %s WHERE login_access_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet), | ||
95 | + loginAccess.Account, | ||
96 | + loginAccess.Platform, | ||
97 | + loginAccess.CompanyId, | ||
98 | + loginAccess.OrganizationId, | ||
99 | + loginAccess.AccessToken, | ||
100 | + loginAccess.RefreshToken, | ||
101 | + loginAccess.AccessExpired, | ||
102 | + loginAccess.RefreshExpired, | ||
103 | + loginAccess.CreatedTime, | ||
104 | + loginAccess.UpdatedTime, | ||
105 | + loginAccess.Identify(), | ||
106 | + ); err != nil { | ||
107 | + return loginAccess, err | ||
108 | + } | ||
109 | + } | ||
110 | + return loginAccess, nil | ||
111 | +} | ||
112 | +func (repository *LoginAccessRepository) Remove(loginAccess *domain.LoginAccess) (*domain.LoginAccess, error) { | ||
113 | + tx := repository.transactionContext.PgTx | ||
114 | + loginAccessModel := new(models.LoginAccess) | ||
115 | + loginAccessModel.LoginAccessId = loginAccess.Identify().(int64) | ||
116 | + if _, err := tx.Model(loginAccessModel).WherePK().Delete(); err != nil { | ||
117 | + return loginAccess, err | ||
118 | + } | ||
119 | + return loginAccess, nil | ||
120 | +} | ||
121 | +func (repository *LoginAccessRepository) FindOne(queryOptions map[string]interface{}) (*domain.LoginAccess, error) { | ||
122 | + tx := repository.transactionContext.PgTx | ||
123 | + loginAccessModel := new(models.LoginAccess) | ||
124 | + query := sqlbuilder.BuildQuery(tx.Model(loginAccessModel), queryOptions) | ||
125 | + query.SetWhereByQueryOption("login_access.login_access_id = ?", "loginAccessId") | ||
126 | + if err := query.First(); err != nil { | ||
127 | + if err.Error() == "pg: no rows in result set" { | ||
128 | + return nil, fmt.Errorf("没有此资源") | ||
129 | + } else { | ||
130 | + return nil, err | ||
131 | + } | ||
132 | + } | ||
133 | + if loginAccessModel.LoginAccessId == 0 { | ||
134 | + return nil, nil | ||
135 | + } else { | ||
136 | + return transform.TransformToLoginAccessDomainModelFromPgModels(loginAccessModel) | ||
137 | + } | ||
138 | +} | ||
139 | +func (repository *LoginAccessRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.LoginAccess, error) { | ||
140 | + tx := repository.transactionContext.PgTx | ||
141 | + var loginAccessModels []*models.LoginAccess | ||
142 | + loginAccesss := make([]*domain.LoginAccess, 0) | ||
143 | + query := sqlbuilder.BuildQuery(tx.Model(&loginAccessModels), queryOptions) | ||
144 | + query.SetOffsetAndLimit(20) | ||
145 | + query.SetOrderDirect("login_access_id", "DESC") | ||
146 | + if count, err := query.SelectAndCount(); err != nil { | ||
147 | + return 0, loginAccesss, err | ||
148 | + } else { | ||
149 | + for _, loginAccessModel := range loginAccessModels { | ||
150 | + if loginAccess, err := transform.TransformToLoginAccessDomainModelFromPgModels(loginAccessModel); err != nil { | ||
151 | + return 0, loginAccesss, err | ||
152 | + } else { | ||
153 | + loginAccesss = append(loginAccesss, loginAccess) | ||
154 | + } | ||
155 | + } | ||
156 | + return int64(count), loginAccesss, nil | ||
157 | + } | ||
158 | +} | ||
159 | +func NewLoginAccessRepository(transactionContext *pgTransaction.TransactionContext) (*LoginAccessRepository, error) { | ||
160 | + if transactionContext == nil { | ||
161 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
162 | + } else { | ||
163 | + return &LoginAccessRepository{ | ||
164 | + transactionContext: transactionContext, | ||
165 | + }, nil | ||
166 | + } | ||
167 | +} |
1 | +package snowflake | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/utils/snowflake" | ||
5 | +) | ||
6 | + | ||
7 | +// 这里workId进行分组防止数组序列化时报错 | ||
8 | +func NextIdentify(workId int64) (int64, error) { | ||
9 | + IdWorker, err := snowflake.NewIdWorker(workId) | ||
10 | + if err != nil { | ||
11 | + return 0, err | ||
12 | + } | ||
13 | + id, err := IdWorker.NextId() | ||
14 | + return id, err | ||
15 | +} |
pkg/log/logger.go
0 → 100644
1 | +package log | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" | ||
5 | + | ||
6 | + "github.com/linmadan/egglib-go/log" | ||
7 | + "github.com/linmadan/egglib-go/log/logrus" | ||
8 | +) | ||
9 | + | ||
10 | +var Logger log.Logger | ||
11 | + | ||
12 | +func init() { | ||
13 | + Logger = logrus.NewLogrusLogger() | ||
14 | + Logger.SetServiceName(constant.SERVICE_NAME) | ||
15 | + Logger.SetLevel(constant.LOG_LEVEL) | ||
16 | +} |
pkg/port/beego/beego.go
0 → 100644
1 | +package beego | ||
2 | + | ||
3 | +import ( | ||
4 | + "os" | ||
5 | + "strconv" | ||
6 | + | ||
7 | + "github.com/beego/beego/v2/server/web" | ||
8 | + "github.com/linmadan/egglib-go/web/beego/filters" | ||
9 | + | ||
10 | + //_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/routers" | ||
11 | + . "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log" | ||
12 | +) | ||
13 | + | ||
14 | +func init() { | ||
15 | + web.BConfig.AppName = "project" | ||
16 | + web.BConfig.CopyRequestBody = true | ||
17 | + web.BConfig.RunMode = "dev" | ||
18 | + web.BConfig.Listen.HTTPPort = 8080 | ||
19 | + web.BConfig.Listen.EnableAdmin = false | ||
20 | + web.BConfig.WebConfig.CommentRouterPath = "/pkg/port/beego" | ||
21 | + if os.Getenv("RUN_MODE") != "" { | ||
22 | + web.BConfig.RunMode = os.Getenv("RUN_MODE") | ||
23 | + } | ||
24 | + if os.Getenv("HTTP_PORT") != "" { | ||
25 | + portStr := os.Getenv("HTTP_PORT") | ||
26 | + if port, err := strconv.Atoi(portStr); err == nil { | ||
27 | + web.BConfig.Listen.HTTPPort = port | ||
28 | + } | ||
29 | + } | ||
30 | + web.InsertFilter("/*", web.BeforeExec, filters.AllowCors()) | ||
31 | + web.InsertFilter("/*", web.BeforeExec, filters.CreateRequstLogFilter(Logger)) | ||
32 | + web.InsertFilter("/*", web.AfterExec, filters.CreateResponseLogFilter(Logger), web.WithReturnOnOutput(false)) | ||
33 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/web/beego" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/loginAccess/query" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/loginAccess/service" | ||
7 | +) | ||
8 | + | ||
9 | +type LoginAccessController struct { | ||
10 | + beego.BaseController | ||
11 | +} | ||
12 | + | ||
13 | +func (controller *LoginAccessController) LoginByAccount() { | ||
14 | + loginAccessService := service.NewLoginAccessService(nil) | ||
15 | + loginByAccountQuery := &query.LoginByAccountQuery{} | ||
16 | + data, err := loginAccessService.LoginByAccount(loginByAccountQuery) | ||
17 | + controller.Response(data, err) | ||
18 | +} | ||
19 | + | ||
20 | +func (controller *LoginAccessController) LoginBySmsCode() { | ||
21 | + loginAccessService := service.NewLoginAccessService(nil) | ||
22 | + loginBySmsCodeQuery := &query.LoginBySmsCodeQuery{} | ||
23 | + data, err := loginAccessService.LoginBySmsCode(loginBySmsCodeQuery) | ||
24 | + controller.Response(data, err) | ||
25 | +} | ||
26 | + | ||
27 | +func (controller *LoginAccessController) LoginByScanQrcode() { | ||
28 | + loginAccessService := service.NewLoginAccessService(nil) | ||
29 | + loginByScanQrcodeQuery := &query.LoginByScanQrcodeQuery{} | ||
30 | + data, err := loginAccessService.LoginByScanQrcode(loginByScanQrcodeQuery) | ||
31 | + controller.Response(data, err) | ||
32 | +} | ||
33 | + | ||
34 | +func (controller *LoginAccessController) GetQrcodeForLogin() { | ||
35 | + loginAccessService := service.NewLoginAccessService(nil) | ||
36 | + getQrcodeForLoginQuery := &query.GetQrcodeForLoginQuery{} | ||
37 | + data, err := loginAccessService.GetQrcodeForLogin(getQrcodeForLoginQuery) | ||
38 | + controller.Response(data, err) | ||
39 | +} | ||
40 | + | ||
41 | +func (controller *LoginAccessController) LoginInfoByAuthCode() { | ||
42 | + loginAccessService := service.NewLoginAccessService(nil) | ||
43 | + loginInfoByAuthCodeQuery := &query.LoginInfoByAuthCodeQuery{} | ||
44 | + data, err := loginAccessService.LoginInfoByAuthCode(loginInfoByAuthCodeQuery) | ||
45 | + controller.Response(data, err) | ||
46 | +} |
1 | +package routers | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/beego/beego/v2/server/web" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers" | ||
6 | +) | ||
7 | + | ||
8 | +func init() { | ||
9 | + web.Router("/auth/by-account", &controllers.LoginAccessController{}, "Post:LoginByAccount") | ||
10 | + web.Router("/auth/by-smscode", &controllers.LoginAccessController{}, "Post:LoginBySmsCode") | ||
11 | + web.Router("/auth/by-qrcode", &controllers.LoginAccessController{}, "Get:LoginByScanQrcode") | ||
12 | + web.Router("/auth/get-qrcode", &controllers.LoginAccessController{}, "Get:GetQrcodeForLogin") | ||
13 | + web.Router("/auth/profile", &controllers.LoginAccessController{}, "Get:LoginInfoByAuthCode") | ||
14 | +} |
pkg/service_gateway/interface.go
0 → 100644
1 | +package service_gateway |
-
请 注册 或 登录 后发表评论