ljw 1 year ago
parent
commit
22a4546d0f

+ 74 - 6
cmd/apimain.go

@@ -14,6 +14,9 @@ import (
14
 	"fmt"
14
 	"fmt"
15
 	"github.com/go-redis/redis/v8"
15
 	"github.com/go-redis/redis/v8"
16
 	"github.com/nicksnyder/go-i18n/v2/i18n"
16
 	"github.com/nicksnyder/go-i18n/v2/i18n"
17
+	"github.com/spf13/cobra"
18
+	"os"
19
+	"strconv"
17
 )
20
 )
18
 
21
 
19
 // @title 管理系统API
22
 // @title 管理系统API
@@ -26,9 +29,79 @@ import (
26
 // @securitydefinitions.apikey BearerAuth
29
 // @securitydefinitions.apikey BearerAuth
27
 // @in header
30
 // @in header
28
 // @name Authorization
31
 // @name Authorization
32
+
33
+var rootCmd = &cobra.Command{
34
+	Use:   "apimain",
35
+	Short: "RUSTDESK API SERVER",
36
+	PersistentPreRun: func(cmd *cobra.Command, args []string) {
37
+		InitGlobal()
38
+	},
39
+	Run: func(cmd *cobra.Command, args []string) {
40
+		//gin
41
+		http.ApiInit()
42
+	},
43
+}
44
+
45
+var resetPwdCmd = &cobra.Command{
46
+	Use:     "reset-admin-pwd [pwd]",
47
+	Example: "reset-admin-pwd 123456",
48
+	Short:   "Reset Admin Password",
49
+	Args:    cobra.ExactArgs(1),
50
+	Run: func(cmd *cobra.Command, args []string) {
51
+		pwd := args[0]
52
+		admin := service.AllService.UserService.InfoById(1)
53
+		err := service.AllService.UserService.UpdatePassword(admin, pwd)
54
+		if err != nil {
55
+			fmt.Printf("reset password fail! %v \n", err)
56
+			return
57
+		}
58
+		fmt.Printf("reset password success! \n")
59
+	},
60
+}
61
+var resetUserPwdCmd = &cobra.Command{
62
+	Use:     "reset-pwd [userId] [pwd]",
63
+	Example: "reset-pwd 2 123456",
64
+	Short:   "Reset User Password",
65
+	Args:    cobra.ExactArgs(2),
66
+	Run: func(cmd *cobra.Command, args []string) {
67
+		userId := args[0]
68
+		pwd := args[1]
69
+		uid, err := strconv.Atoi(userId)
70
+		if err != nil {
71
+			fmt.Printf("userId must be int! \n")
72
+			return
73
+		}
74
+		if uid <= 0 {
75
+			fmt.Printf("userId must be greater than 0! \n")
76
+			return
77
+		}
78
+		u := service.AllService.UserService.InfoById(uint(uid))
79
+		err = service.AllService.UserService.UpdatePassword(u, pwd)
80
+		if err != nil {
81
+			fmt.Printf("reset password fail! %v \n", err)
82
+			return
83
+		}
84
+		fmt.Printf("reset password success! \n")
85
+	},
86
+}
87
+
88
+func init() {
89
+	rootCmd.PersistentFlags().StringVarP(&global.ConfigPath, "config", "c", "./conf/config.yaml", "choose config file")
90
+	rootCmd.AddCommand(resetPwdCmd, resetUserPwdCmd)
91
+}
29
 func main() {
92
 func main() {
93
+	if err := rootCmd.Execute(); err != nil {
94
+		fmt.Println(err)
95
+		os.Exit(1)
96
+	}
97
+}
98
+
99
+func InitGlobal() {
30
 	//配置解析
100
 	//配置解析
31
-	global.Viper = config.Init(&global.Config)
101
+	global.Viper = config.Init(&global.Config, global.ConfigPath)
102
+
103
+	//从配置文件中加载密钥
104
+	config.LoadKeyFile(&global.Config.Rustdesk)
32
 
105
 
33
 	//日志
106
 	//日志
34
 	global.Logger = logger.New(&logger.Config{
107
 	global.Logger = logger.New(&logger.Config{
@@ -94,12 +167,7 @@ func main() {
94
 
167
 
95
 	//locker
168
 	//locker
96
 	global.Lock = lock.NewLocal()
169
 	global.Lock = lock.NewLocal()
97
-
98
-	//gin
99
-	http.ApiInit()
100
-
101
 }
170
 }
102
-
103
 func DatabaseAutoUpdate() {
171
 func DatabaseAutoUpdate() {
104
 	version := 246
172
 	version := 246
105
 
173
 

+ 6 - 10
config/config.go

@@ -1,7 +1,6 @@
1
 package config
1
 package config
2
 
2
 
3
 import (
3
 import (
4
-	"flag"
5
 	"fmt"
4
 	"fmt"
6
 	"github.com/fsnotify/fsnotify"
5
 	"github.com/fsnotify/fsnotify"
7
 	"github.com/spf13/viper"
6
 	"github.com/spf13/viper"
@@ -35,18 +34,15 @@ type Config struct {
35
 }
34
 }
36
 
35
 
37
 // Init 初始化配置
36
 // Init 初始化配置
38
-func Init(rowVal interface{}) *viper.Viper {
39
-	var config string
40
-	flag.StringVar(&config, "c", "", "choose config file.")
41
-	flag.Parse()
42
-	if config == "" { // 优先级: 命令行 > 默认值
43
-		config = DefaultConfig
37
+func Init(rowVal interface{}, path string) *viper.Viper {
38
+	if path == "" {
39
+		path = DefaultConfig
44
 	}
40
 	}
45
-	v := viper.New()
41
+	v := viper.GetViper()
46
 	v.AutomaticEnv()
42
 	v.AutomaticEnv()
47
 	v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
43
 	v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_"))
48
 	v.SetEnvPrefix("RUSTDESK_API")
44
 	v.SetEnvPrefix("RUSTDESK_API")
49
-	v.SetConfigFile(config)
45
+	v.SetConfigFile(path)
50
 	v.SetConfigType("yaml")
46
 	v.SetConfigType("yaml")
51
 	err := v.ReadInConfig()
47
 	err := v.ReadInConfig()
52
 	if err != nil {
48
 	if err != nil {
@@ -63,7 +59,7 @@ func Init(rowVal interface{}) *viper.Viper {
63
 	if err := v.Unmarshal(rowVal); err != nil {
59
 	if err := v.Unmarshal(rowVal); err != nil {
64
 		fmt.Println(err)
60
 		fmt.Println(err)
65
 	}
61
 	}
66
-	LoadKeyFile(&rowVal.(*Config).Rustdesk)
62
+
67
 	return v
63
 	return v
68
 }
64
 }
69
 
65
 

+ 117 - 5
docs/admin/admin_docs.go

@@ -3067,6 +3067,90 @@ const docTemplateadmin = `{
3067
                 }
3067
                 }
3068
             }
3068
             }
3069
         },
3069
         },
3070
+        "/admin/user/myPeer": {
3071
+            "get": {
3072
+                "security": [
3073
+                    {
3074
+                        "token": []
3075
+                    }
3076
+                ],
3077
+                "description": "设备列表",
3078
+                "consumes": [
3079
+                    "application/json"
3080
+                ],
3081
+                "produces": [
3082
+                    "application/json"
3083
+                ],
3084
+                "tags": [
3085
+                    "设备"
3086
+                ],
3087
+                "summary": "设备列表",
3088
+                "parameters": [
3089
+                    {
3090
+                        "type": "integer",
3091
+                        "description": "页码",
3092
+                        "name": "page",
3093
+                        "in": "query"
3094
+                    },
3095
+                    {
3096
+                        "type": "integer",
3097
+                        "description": "页大小",
3098
+                        "name": "page_size",
3099
+                        "in": "query"
3100
+                    },
3101
+                    {
3102
+                        "type": "integer",
3103
+                        "description": "时间",
3104
+                        "name": "time_ago",
3105
+                        "in": "query"
3106
+                    },
3107
+                    {
3108
+                        "type": "string",
3109
+                        "description": "ID",
3110
+                        "name": "id",
3111
+                        "in": "query"
3112
+                    },
3113
+                    {
3114
+                        "type": "string",
3115
+                        "description": "主机名",
3116
+                        "name": "hostname",
3117
+                        "in": "query"
3118
+                    },
3119
+                    {
3120
+                        "type": "string",
3121
+                        "description": "uuids 用逗号分隔",
3122
+                        "name": "uuids",
3123
+                        "in": "query"
3124
+                    }
3125
+                ],
3126
+                "responses": {
3127
+                    "200": {
3128
+                        "description": "OK",
3129
+                        "schema": {
3130
+                            "allOf": [
3131
+                                {
3132
+                                    "$ref": "#/definitions/response.Response"
3133
+                                },
3134
+                                {
3135
+                                    "type": "object",
3136
+                                    "properties": {
3137
+                                        "data": {
3138
+                                            "$ref": "#/definitions/model.PeerList"
3139
+                                        }
3140
+                                    }
3141
+                                }
3142
+                            ]
3143
+                        }
3144
+                    },
3145
+                    "500": {
3146
+                        "description": "Internal Server Error",
3147
+                        "schema": {
3148
+                            "$ref": "#/definitions/response.Response"
3149
+                        }
3150
+                    }
3151
+                }
3152
+            }
3153
+        },
3070
         "/admin/user/update": {
3154
         "/admin/user/update": {
3071
             "post": {
3155
             "post": {
3072
                 "security": [
3156
                 "security": [
@@ -3407,6 +3491,12 @@ const docTemplateadmin = `{
3407
         "admin.LoginPayload": {
3491
         "admin.LoginPayload": {
3408
             "type": "object",
3492
             "type": "object",
3409
             "properties": {
3493
             "properties": {
3494
+                "avatar": {
3495
+                    "type": "string"
3496
+                },
3497
+                "email": {
3498
+                    "type": "string"
3499
+                },
3410
                 "nickname": {
3500
                 "nickname": {
3411
                     "type": "string"
3501
                     "type": "string"
3412
                 },
3502
                 },
@@ -3429,7 +3519,7 @@ const docTemplateadmin = `{
3429
             "required": [
3519
             "required": [
3430
                 "client_id",
3520
                 "client_id",
3431
                 "client_secret",
3521
                 "client_secret",
3432
-                "op",
3522
+                "oauth_type",
3433
                 "redirect_url"
3523
                 "redirect_url"
3434
             ],
3524
             ],
3435
             "properties": {
3525
             "properties": {
@@ -3448,6 +3538,9 @@ const docTemplateadmin = `{
3448
                 "issuer": {
3538
                 "issuer": {
3449
                     "type": "string"
3539
                     "type": "string"
3450
                 },
3540
                 },
3541
+                "oauth_type": {
3542
+                    "type": "string"
3543
+                },
3451
                 "op": {
3544
                 "op": {
3452
                     "type": "string"
3545
                     "type": "string"
3453
                 },
3546
                 },
@@ -3567,6 +3660,10 @@ const docTemplateadmin = `{
3567
                 "avatar": {
3660
                 "avatar": {
3568
                     "type": "string"
3661
                     "type": "string"
3569
                 },
3662
                 },
3663
+                "email": {
3664
+                    "description": "validate:\"required,email\" email不强制",
3665
+                    "type": "string"
3666
+                },
3570
                 "group_id": {
3667
                 "group_id": {
3571
                     "type": "integer"
3668
                     "type": "integer"
3572
                 },
3669
                 },
@@ -3591,18 +3688,18 @@ const docTemplateadmin = `{
3591
                 "username": {
3688
                 "username": {
3592
                     "type": "string",
3689
                     "type": "string",
3593
                     "maxLength": 10,
3690
                     "maxLength": 10,
3594
-                    "minLength": 4
3691
+                    "minLength": 2
3595
                 }
3692
                 }
3596
             }
3693
             }
3597
         },
3694
         },
3598
         "admin.UserOauthItem": {
3695
         "admin.UserOauthItem": {
3599
             "type": "object",
3696
             "type": "object",
3600
             "properties": {
3697
             "properties": {
3698
+                "op": {
3699
+                    "type": "string"
3700
+                },
3601
                 "status": {
3701
                 "status": {
3602
                     "type": "integer"
3702
                     "type": "integer"
3603
-                },
3604
-                "third_type": {
3605
-                    "type": "string"
3606
                 }
3703
                 }
3607
             }
3704
             }
3608
         },
3705
         },
@@ -3973,6 +4070,9 @@ const docTemplateadmin = `{
3973
                 "created_at": {
4070
                 "created_at": {
3974
                     "type": "string"
4071
                     "type": "string"
3975
                 },
4072
                 },
4073
+                "device_id": {
4074
+                    "type": "string"
4075
+                },
3976
                 "id": {
4076
                 "id": {
3977
                     "type": "integer"
4077
                     "type": "integer"
3978
                 },
4078
                 },
@@ -4042,6 +4142,9 @@ const docTemplateadmin = `{
4042
                 "issuer": {
4142
                 "issuer": {
4043
                     "type": "string"
4143
                     "type": "string"
4044
                 },
4144
                 },
4145
+                "oauth_type": {
4146
+                    "type": "string"
4147
+                },
4045
                 "op": {
4148
                 "op": {
4046
                     "type": "string"
4149
                     "type": "string"
4047
                 },
4150
                 },
@@ -4220,6 +4323,9 @@ const docTemplateadmin = `{
4220
                 "created_at": {
4323
                 "created_at": {
4221
                     "type": "string"
4324
                     "type": "string"
4222
                 },
4325
                 },
4326
+                "email": {
4327
+                    "type": "string"
4328
+                },
4223
                 "group_id": {
4329
                 "group_id": {
4224
                     "type": "integer"
4330
                     "type": "integer"
4225
                 },
4331
                 },
@@ -4269,6 +4375,12 @@ const docTemplateadmin = `{
4269
                 "created_at": {
4375
                 "created_at": {
4270
                     "type": "string"
4376
                     "type": "string"
4271
                 },
4377
                 },
4378
+                "device_id": {
4379
+                    "type": "string"
4380
+                },
4381
+                "device_uuid": {
4382
+                    "type": "string"
4383
+                },
4272
                 "expired_at": {
4384
                 "expired_at": {
4273
                     "type": "integer"
4385
                     "type": "integer"
4274
                 },
4386
                 },

+ 117 - 5
docs/admin/admin_swagger.json

@@ -3060,6 +3060,90 @@
3060
                 }
3060
                 }
3061
             }
3061
             }
3062
         },
3062
         },
3063
+        "/admin/user/myPeer": {
3064
+            "get": {
3065
+                "security": [
3066
+                    {
3067
+                        "token": []
3068
+                    }
3069
+                ],
3070
+                "description": "设备列表",
3071
+                "consumes": [
3072
+                    "application/json"
3073
+                ],
3074
+                "produces": [
3075
+                    "application/json"
3076
+                ],
3077
+                "tags": [
3078
+                    "设备"
3079
+                ],
3080
+                "summary": "设备列表",
3081
+                "parameters": [
3082
+                    {
3083
+                        "type": "integer",
3084
+                        "description": "页码",
3085
+                        "name": "page",
3086
+                        "in": "query"
3087
+                    },
3088
+                    {
3089
+                        "type": "integer",
3090
+                        "description": "页大小",
3091
+                        "name": "page_size",
3092
+                        "in": "query"
3093
+                    },
3094
+                    {
3095
+                        "type": "integer",
3096
+                        "description": "时间",
3097
+                        "name": "time_ago",
3098
+                        "in": "query"
3099
+                    },
3100
+                    {
3101
+                        "type": "string",
3102
+                        "description": "ID",
3103
+                        "name": "id",
3104
+                        "in": "query"
3105
+                    },
3106
+                    {
3107
+                        "type": "string",
3108
+                        "description": "主机名",
3109
+                        "name": "hostname",
3110
+                        "in": "query"
3111
+                    },
3112
+                    {
3113
+                        "type": "string",
3114
+                        "description": "uuids 用逗号分隔",
3115
+                        "name": "uuids",
3116
+                        "in": "query"
3117
+                    }
3118
+                ],
3119
+                "responses": {
3120
+                    "200": {
3121
+                        "description": "OK",
3122
+                        "schema": {
3123
+                            "allOf": [
3124
+                                {
3125
+                                    "$ref": "#/definitions/response.Response"
3126
+                                },
3127
+                                {
3128
+                                    "type": "object",
3129
+                                    "properties": {
3130
+                                        "data": {
3131
+                                            "$ref": "#/definitions/model.PeerList"
3132
+                                        }
3133
+                                    }
3134
+                                }
3135
+                            ]
3136
+                        }
3137
+                    },
3138
+                    "500": {
3139
+                        "description": "Internal Server Error",
3140
+                        "schema": {
3141
+                            "$ref": "#/definitions/response.Response"
3142
+                        }
3143
+                    }
3144
+                }
3145
+            }
3146
+        },
3063
         "/admin/user/update": {
3147
         "/admin/user/update": {
3064
             "post": {
3148
             "post": {
3065
                 "security": [
3149
                 "security": [
@@ -3400,6 +3484,12 @@
3400
         "admin.LoginPayload": {
3484
         "admin.LoginPayload": {
3401
             "type": "object",
3485
             "type": "object",
3402
             "properties": {
3486
             "properties": {
3487
+                "avatar": {
3488
+                    "type": "string"
3489
+                },
3490
+                "email": {
3491
+                    "type": "string"
3492
+                },
3403
                 "nickname": {
3493
                 "nickname": {
3404
                     "type": "string"
3494
                     "type": "string"
3405
                 },
3495
                 },
@@ -3422,7 +3512,7 @@
3422
             "required": [
3512
             "required": [
3423
                 "client_id",
3513
                 "client_id",
3424
                 "client_secret",
3514
                 "client_secret",
3425
-                "op",
3515
+                "oauth_type",
3426
                 "redirect_url"
3516
                 "redirect_url"
3427
             ],
3517
             ],
3428
             "properties": {
3518
             "properties": {
@@ -3441,6 +3531,9 @@
3441
                 "issuer": {
3531
                 "issuer": {
3442
                     "type": "string"
3532
                     "type": "string"
3443
                 },
3533
                 },
3534
+                "oauth_type": {
3535
+                    "type": "string"
3536
+                },
3444
                 "op": {
3537
                 "op": {
3445
                     "type": "string"
3538
                     "type": "string"
3446
                 },
3539
                 },
@@ -3560,6 +3653,10 @@
3560
                 "avatar": {
3653
                 "avatar": {
3561
                     "type": "string"
3654
                     "type": "string"
3562
                 },
3655
                 },
3656
+                "email": {
3657
+                    "description": "validate:\"required,email\" email不强制",
3658
+                    "type": "string"
3659
+                },
3563
                 "group_id": {
3660
                 "group_id": {
3564
                     "type": "integer"
3661
                     "type": "integer"
3565
                 },
3662
                 },
@@ -3584,18 +3681,18 @@
3584
                 "username": {
3681
                 "username": {
3585
                     "type": "string",
3682
                     "type": "string",
3586
                     "maxLength": 10,
3683
                     "maxLength": 10,
3587
-                    "minLength": 4
3684
+                    "minLength": 2
3588
                 }
3685
                 }
3589
             }
3686
             }
3590
         },
3687
         },
3591
         "admin.UserOauthItem": {
3688
         "admin.UserOauthItem": {
3592
             "type": "object",
3689
             "type": "object",
3593
             "properties": {
3690
             "properties": {
3691
+                "op": {
3692
+                    "type": "string"
3693
+                },
3594
                 "status": {
3694
                 "status": {
3595
                     "type": "integer"
3695
                     "type": "integer"
3596
-                },
3597
-                "third_type": {
3598
-                    "type": "string"
3599
                 }
3696
                 }
3600
             }
3697
             }
3601
         },
3698
         },
@@ -3966,6 +4063,9 @@
3966
                 "created_at": {
4063
                 "created_at": {
3967
                     "type": "string"
4064
                     "type": "string"
3968
                 },
4065
                 },
4066
+                "device_id": {
4067
+                    "type": "string"
4068
+                },
3969
                 "id": {
4069
                 "id": {
3970
                     "type": "integer"
4070
                     "type": "integer"
3971
                 },
4071
                 },
@@ -4035,6 +4135,9 @@
4035
                 "issuer": {
4135
                 "issuer": {
4036
                     "type": "string"
4136
                     "type": "string"
4037
                 },
4137
                 },
4138
+                "oauth_type": {
4139
+                    "type": "string"
4140
+                },
4038
                 "op": {
4141
                 "op": {
4039
                     "type": "string"
4142
                     "type": "string"
4040
                 },
4143
                 },
@@ -4213,6 +4316,9 @@
4213
                 "created_at": {
4316
                 "created_at": {
4214
                     "type": "string"
4317
                     "type": "string"
4215
                 },
4318
                 },
4319
+                "email": {
4320
+                    "type": "string"
4321
+                },
4216
                 "group_id": {
4322
                 "group_id": {
4217
                     "type": "integer"
4323
                     "type": "integer"
4218
                 },
4324
                 },
@@ -4262,6 +4368,12 @@
4262
                 "created_at": {
4368
                 "created_at": {
4263
                     "type": "string"
4369
                     "type": "string"
4264
                 },
4370
                 },
4371
+                "device_id": {
4372
+                    "type": "string"
4373
+                },
4374
+                "device_uuid": {
4375
+                    "type": "string"
4376
+                },
4265
                 "expired_at": {
4377
                 "expired_at": {
4266
                     "type": "integer"
4378
                     "type": "integer"
4267
                 },
4379
                 },

+ 74 - 4
docs/admin/admin_swagger.yaml

@@ -84,6 +84,10 @@ definitions:
84
     type: object
84
     type: object
85
   admin.LoginPayload:
85
   admin.LoginPayload:
86
     properties:
86
     properties:
87
+      avatar:
88
+        type: string
89
+      email:
90
+        type: string
87
       nickname:
91
       nickname:
88
         type: string
92
         type: string
89
       route_names:
93
       route_names:
@@ -107,6 +111,8 @@ definitions:
107
         type: integer
111
         type: integer
108
       issuer:
112
       issuer:
109
         type: string
113
         type: string
114
+      oauth_type:
115
+        type: string
110
       op:
116
       op:
111
         type: string
117
         type: string
112
       redirect_url:
118
       redirect_url:
@@ -116,7 +122,7 @@ definitions:
116
     required:
122
     required:
117
     - client_id
123
     - client_id
118
     - client_secret
124
     - client_secret
119
-    - op
125
+    - oauth_type
120
     - redirect_url
126
     - redirect_url
121
     type: object
127
     type: object
122
   admin.PeerBatchDeleteForm:
128
   admin.PeerBatchDeleteForm:
@@ -188,6 +194,9 @@ definitions:
188
     properties:
194
     properties:
189
       avatar:
195
       avatar:
190
         type: string
196
         type: string
197
+      email:
198
+        description: validate:"required,email" email不强制
199
+        type: string
191
       group_id:
200
       group_id:
192
         type: integer
201
         type: integer
193
       id:
202
       id:
@@ -203,7 +212,7 @@ definitions:
203
         minimum: 0
212
         minimum: 0
204
       username:
213
       username:
205
         maxLength: 10
214
         maxLength: 10
206
-        minLength: 4
215
+        minLength: 2
207
         type: string
216
         type: string
208
     required:
217
     required:
209
     - group_id
218
     - group_id
@@ -212,10 +221,10 @@ definitions:
212
     type: object
221
     type: object
213
   admin.UserOauthItem:
222
   admin.UserOauthItem:
214
     properties:
223
     properties:
224
+      op:
225
+        type: string
215
       status:
226
       status:
216
         type: integer
227
         type: integer
217
-      third_type:
218
-        type: string
219
     type: object
228
     type: object
220
   admin.UserPasswordForm:
229
   admin.UserPasswordForm:
221
     properties:
230
     properties:
@@ -462,6 +471,8 @@ definitions:
462
         type: string
471
         type: string
463
       created_at:
472
       created_at:
464
         type: string
473
         type: string
474
+      device_id:
475
+        type: string
465
       id:
476
       id:
466
         type: integer
477
         type: integer
467
       ip:
478
       ip:
@@ -508,6 +519,8 @@ definitions:
508
         type: integer
519
         type: integer
509
       issuer:
520
       issuer:
510
         type: string
521
         type: string
522
+      oauth_type:
523
+        type: string
511
       op:
524
       op:
512
         type: string
525
         type: string
513
       redirect_url:
526
       redirect_url:
@@ -627,6 +640,8 @@ definitions:
627
         type: string
640
         type: string
628
       created_at:
641
       created_at:
629
         type: string
642
         type: string
643
+      email:
644
+        type: string
630
       group_id:
645
       group_id:
631
         type: integer
646
         type: integer
632
       id:
647
       id:
@@ -659,6 +674,10 @@ definitions:
659
     properties:
674
     properties:
660
       created_at:
675
       created_at:
661
         type: string
676
         type: string
677
+      device_id:
678
+        type: string
679
+      device_uuid:
680
+        type: string
662
       expired_at:
681
       expired_at:
663
         type: integer
682
         type: integer
664
       id:
683
       id:
@@ -2519,6 +2538,57 @@ paths:
2519
       summary: 我的授权
2538
       summary: 我的授权
2520
       tags:
2539
       tags:
2521
       - 用户
2540
       - 用户
2541
+  /admin/user/myPeer:
2542
+    get:
2543
+      consumes:
2544
+      - application/json
2545
+      description: 设备列表
2546
+      parameters:
2547
+      - description: 页码
2548
+        in: query
2549
+        name: page
2550
+        type: integer
2551
+      - description: 页大小
2552
+        in: query
2553
+        name: page_size
2554
+        type: integer
2555
+      - description: 时间
2556
+        in: query
2557
+        name: time_ago
2558
+        type: integer
2559
+      - description: ID
2560
+        in: query
2561
+        name: id
2562
+        type: string
2563
+      - description: 主机名
2564
+        in: query
2565
+        name: hostname
2566
+        type: string
2567
+      - description: uuids 用逗号分隔
2568
+        in: query
2569
+        name: uuids
2570
+        type: string
2571
+      produces:
2572
+      - application/json
2573
+      responses:
2574
+        "200":
2575
+          description: OK
2576
+          schema:
2577
+            allOf:
2578
+            - $ref: '#/definitions/response.Response'
2579
+            - properties:
2580
+                data:
2581
+                  $ref: '#/definitions/model.PeerList'
2582
+              type: object
2583
+        "500":
2584
+          description: Internal Server Error
2585
+          schema:
2586
+            $ref: '#/definitions/response.Response'
2587
+      security:
2588
+      - token: []
2589
+      summary: 设备列表
2590
+      tags:
2591
+      - 设备
2522
   /admin/user/update:
2592
   /admin/user/update:
2523
     post:
2593
     post:
2524
       consumes:
2594
       consumes:

+ 1 - 1
docs/api/api_docs.go

@@ -1365,7 +1365,7 @@ const docTemplateapi = `{
1365
                 "username": {
1365
                 "username": {
1366
                     "type": "string",
1366
                     "type": "string",
1367
                     "maxLength": 10,
1367
                     "maxLength": 10,
1368
-                    "minLength": 4
1368
+                    "minLength": 2
1369
                 },
1369
                 },
1370
                 "uuid": {
1370
                 "uuid": {
1371
                     "type": "string"
1371
                     "type": "string"

+ 1 - 1
docs/api/api_swagger.json

@@ -1358,7 +1358,7 @@
1358
                 "username": {
1358
                 "username": {
1359
                     "type": "string",
1359
                     "type": "string",
1360
                     "maxLength": 10,
1360
                     "maxLength": 10,
1361
-                    "minLength": 4
1361
+                    "minLength": 2
1362
                 },
1362
                 },
1363
                 "uuid": {
1363
                 "uuid": {
1364
                     "type": "string"
1364
                     "type": "string"

+ 1 - 1
docs/api/api_swagger.yaml

@@ -69,7 +69,7 @@ definitions:
69
         type: string
69
         type: string
70
       username:
70
       username:
71
         maxLength: 10
71
         maxLength: 10
72
-        minLength: 4
72
+        minLength: 2
73
         type: string
73
         type: string
74
       uuid:
74
       uuid:
75
         type: string
75
         type: string

+ 8 - 7
global/global.go

@@ -17,13 +17,14 @@ import (
17
 )
17
 )
18
 
18
 
19
 var (
19
 var (
20
-	DB        *gorm.DB
21
-	Logger    *logrus.Logger
22
-	Config    config.Config
23
-	Viper     *viper.Viper
24
-	Redis     *redis.Client
25
-	Cache     cache.Handler
26
-	Validator struct {
20
+	DB         *gorm.DB
21
+	Logger     *logrus.Logger
22
+	ConfigPath string = ""
23
+	Config     config.Config
24
+	Viper      *viper.Viper
25
+	Redis      *redis.Client
26
+	Cache      cache.Handler
27
+	Validator  struct {
27
 		Validate    *validator.Validate
28
 		Validate    *validator.Validate
28
 		UT          *ut.UniversalTranslator
29
 		UT          *ut.UniversalTranslator
29
 		VTrans      ut.Translator
30
 		VTrans      ut.Translator

+ 2 - 1
go.mod

@@ -16,6 +16,7 @@ require (
16
 	github.com/google/uuid v1.1.2
16
 	github.com/google/uuid v1.1.2
17
 	github.com/nicksnyder/go-i18n/v2 v2.4.0
17
 	github.com/nicksnyder/go-i18n/v2 v2.4.0
18
 	github.com/sirupsen/logrus v1.8.1
18
 	github.com/sirupsen/logrus v1.8.1
19
+	github.com/spf13/cobra v1.8.1
19
 	github.com/spf13/viper v1.9.0
20
 	github.com/spf13/viper v1.9.0
20
 	github.com/swaggo/files v1.0.1
21
 	github.com/swaggo/files v1.0.1
21
 	github.com/swaggo/gin-swagger v1.6.0
22
 	github.com/swaggo/gin-swagger v1.6.0
@@ -28,7 +29,6 @@ require (
28
 )
29
 )
29
 
30
 
30
 require (
31
 require (
31
-	cloud.google.com/go/compute/metadata v0.5.1 // indirect
32
 	github.com/KyleBanks/depth v1.2.1 // indirect
32
 	github.com/KyleBanks/depth v1.2.1 // indirect
33
 	github.com/PuerkitoBio/purell v1.1.1 // indirect
33
 	github.com/PuerkitoBio/purell v1.1.1 // indirect
34
 	github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
34
 	github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
@@ -44,6 +44,7 @@ require (
44
 	github.com/go-sql-driver/mysql v1.7.0 // indirect
44
 	github.com/go-sql-driver/mysql v1.7.0 // indirect
45
 	github.com/goccy/go-json v0.10.0 // indirect
45
 	github.com/goccy/go-json v0.10.0 // indirect
46
 	github.com/hashicorp/hcl v1.0.0 // indirect
46
 	github.com/hashicorp/hcl v1.0.0 // indirect
47
+	github.com/inconshreveable/mousetrap v1.1.0 // indirect
47
 	github.com/jinzhu/inflection v1.0.0 // indirect
48
 	github.com/jinzhu/inflection v1.0.0 // indirect
48
 	github.com/jinzhu/now v1.1.5 // indirect
49
 	github.com/jinzhu/now v1.1.5 // indirect
49
 	github.com/josharian/intern v1.0.0 // indirect
50
 	github.com/josharian/intern v1.0.0 // indirect