Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
7d7ae412
Commit
7d7ae412
authored
Aug 10, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
197cd255
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
0 deletions
+53
-0
go.mod
go.mod
+2
-0
router.go
router/router.go
+28
-0
Validator.go
router/validator/Validator.go
+23
-0
No files found.
go.mod
View file @
7d7ae412
...
...
@@ -9,6 +9,8 @@ require (
github.com/olivere/elastic/v7 v7.0.32
gorm.io/driver/mysql v1.2.2
gorm.io/gorm v1.22.4
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
github.com/swaggo/gin-swagger v1.5.2
)
require (
...
...
router/router.go
0 → 100644
View file @
7d7ae412
package
router
import
(
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/router/validator"
"github.com/gin-gonic/gin"
_
"github.com/swaggo/files"
swaggerFiles
"github.com/swaggo/files"
"github.com/swaggo/gin-swagger"
"net/http"
)
func
InitGinEngine
()
*
gin
.
Engine
{
gin
.
SetMode
(
gin
.
ReleaseMode
)
c
:=
gin
.
New
()
//便于工具监测
c
.
GET
(
"/favicon.ico"
,
func
(
c
*
gin
.
Context
)
{
c
.
JSON
(
http
.
StatusOK
,
nil
)
})
//自定义验证器
validator
.
RegisterValidate
()
if
conf
.
Env
==
"dev"
||
conf
.
Env
==
"test"
{
//swagger
c
.
GET
(
"/swagger/*any"
,
ginSwagger
.
WrapHandler
(
swaggerFiles
.
Handler
))
}
return
c
}
router/validator/Validator.go
0 → 100644
View file @
7d7ae412
package
validator
import
(
"github.com/gin-gonic/gin/binding"
"github.com/go-playground/validator/v10"
)
func
RegisterValidate
()
{
// 注册验证器
validate
,
ok
:=
binding
.
Validator
.
Engine
()
.
(
*
validator
.
Validate
)
if
ok
{
validate
.
RegisterValidation
(
"NotNull"
,
notNullValidator
)
}
}
// 参数不能为空(包括不传参数及参数值为空字符串)
var
notNullValidator
validator
.
Func
=
func
(
fl
validator
.
FieldLevel
)
bool
{
if
value
,
ok
:=
fl
.
Field
()
.
Interface
()
.
(
string
);
ok
{
// 字段不能为空,并且不等于 admin
return
value
!=
""
}
return
true
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment