Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ligaishun
chain33-pai
Commits
0d21d0b3
Commit
0d21d0b3
authored
Oct 16, 2019
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add binding
parent
e2307946
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
3 deletions
+43
-3
pai.go
routers/api/v1/pai.go
+2
-1
router.go
routers/router.go
+39
-0
pai.go
service/pai_service/pai.go
+2
-2
No files found.
routers/api/v1/pai.go
View file @
0d21d0b3
...
...
@@ -64,12 +64,13 @@ func RecordMineTime(c *gin.Context) {
appG
:=
app
.
Gin
{
C
:
c
}
var
req
pai_service
.
ReqMineTime
logging
.
Info
(
"req:"
,
req
)
err
:=
c
.
ShouldBindJSON
(
&
req
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
nil
)
}
logging
.
Info
(
"req:"
,
req
)
var
stat
stat_service
.
RaspMinerStat
err
=
stat
.
SetMineTime
(
req
.
Addr
,
req
.
Flag
)
if
err
!=
nil
{
...
...
routers/router.go
View file @
0d21d0b3
...
...
@@ -5,11 +5,23 @@ import (
_
"chain33-pai/docs"
"chain33-pai/routers/api/v1"
"net/http"
"reflect"
"strconv"
"gopkg.in/go-playground/validator.v8"
"github.com/gin-gonic/gin/binding"
"chain33-pai/pkg/logging"
)
// InitRouter initialize routing information
func
InitRouter
()
*
gin
.
Engine
{
r
:=
gin
.
Default
()
//Custom Validators
if
v
,
ok
:=
binding
.
Validator
.
Engine
()
.
(
*
validator
.
Validate
);
ok
{
err
:=
v
.
RegisterValidation
(
"LegalNumber"
,
CheckNumber
)
if
err
!=
nil
{
logging
.
Error
(
"gin custom validator init error, field:LegalNumber"
)
}
}
r
.
Use
(
gin
.
Logger
())
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
Cors
())
...
...
@@ -77,3 +89,30 @@ func Cors() gin.HandlerFunc {
c
.
Next
()
}
}
func
CheckNumber
(
v
*
validator
.
Validate
,
topStruct
reflect
.
Value
,
currentStructOrField
reflect
.
Value
,
field
reflect
.
Value
,
fieldType
reflect
.
Type
,
fieldKind
reflect
.
Kind
,
param
string
,
)
bool
{
val
:=
field
.
Interface
()
switch
val
.
(
type
)
{
case
int
:
return
true
case
string
:
if
val
.
(
string
)
==
""
{
return
true
}
_
,
err
:=
strconv
.
ParseInt
(
val
.
(
string
),
10
,
64
)
if
err
!=
nil
{
return
false
}
return
true
case
int64
:
return
true
default
:
//utility_log.Error("func ToInt error unknow type")
return
false
}
}
service/pai_service/pai.go
View file @
0d21d0b3
...
...
@@ -48,14 +48,14 @@ type MinedTxInfo struct {
type
ReqTicketInfo
struct
{
Addr
string
`json:"addr"
validate
:"requried"`
Addr
string
`json:"addr"
binding
:"requried"`
Page
int32
`json:"page"`
Pagesize
int32
`json:"pagesize"`
Detail
bool
`json:"detail"`
}
type
ReqMineTime
struct
{
Addr
string
`json:"addr"
validate
:"requried"`
Addr
string
`json:"addr"
binding
:"requried"`
Flag
string
`json:"flag"`
}
...
...
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