Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
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
Go
bwallet
Commits
45ff7424
Commit
45ff7424
authored
Jan 03, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
057331e0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
388 additions
and
660 deletions
+388
-660
bwallet
bwallet
+0
-0
coin.go
routers/api/v1/coin.go
+353
-294
router.go
routers/router.go
+9
-9
chain.go
validate_service/chain.go
+3
-3
coin.go
validate_service/coin.go
+21
-352
recommend_coin.go
validate_service/recommend_coin.go
+2
-2
No files found.
bwallet
deleted
100644 → 0
View file @
057331e0
File deleted
routers/api/v1/coin.go
View file @
45ff7424
package
v1
//
//import (
// "github.com/gin-gonic/gin"
// "github.com/astaxie/beego/validation"
// "github.com/Unknwon/com"
// "bwallet/service/coin_service"
// "bwallet/pkg/util"
// "bwallet/service/auth_service"
// "bwallet/pkg/handler"
// "bwallet/pkg/errno"
// "gopkg.in/go-playground/validator.v9"
// "bwallet/validate_service"
//)
//
//func GetCoin(c *gin.Context) {
// id := com.StrTo(c.Param("id")).MustInt()
// valid := validation.Validation{}
// valid.Min(id, 1, "id").Message("ID必须大于0")
//
// if valid.HasErrors() {
// handler.SendResponse(c, errno.ErrValidation, nil)
// return
// }
//
// token := c.Request.Header.Get("Token")
// authService := auth_service.Auth{Token: token}
// auth, _ := authService.GetUserInfo()
// group := auth.Group
// var platform_id int
// if ("administrator" == group) {
// platform_id = com.StrTo(c.DefaultQuery("platform_id", "1")).MustInt()
// } else {
// platform_id = auth.PlatformId
// }
// coinService := coin_service.Coin{
// Id: id,
// PlatformId: platform_id,
// PageNum: util.GetPage(c),
// PageSize: util.GetLimit(c),
// }
//
// coin, err := coinService.GetAll()
// if err != nil {
// handler.SendResponse(c, errno.ErrCoinNotFound, nil)
// return
// }
//
// handler.SendResponse(c, nil, coin)
// return
//}
//
//func GetCoins(c *gin.Context) {
// valid := validation.Validation{}
//
// name := ""
// if arg := c.Query("name"); arg != "" {
// name = c.Query("name")
// }
//
// platform := ""
// if arg := c.Query("platform"); arg != "" {
// platform = c.Query("platform")
// }
//
// chain := ""
// if arg := c.Query("chain"); arg != "" {
// chain = c.Query("chain")
// }
//
// token := c.Request.Header.Get("Token")
// authService := auth_service.Auth{Token: token}
// auth, _ := authService.GetUserInfo()
// group := auth.Group
//
// var platform_id int
// platform_id = auth.PlatformId
// if ("administrator" == group) {
// if arg := c.Query("platform_id"); arg != "" {
// platform_id = com.StrTo(c.Query("platform_id")).MustInt()
// }
// }
//
// if valid.HasErrors() {
// handler.SendResponse(c, errno.ErrValidation, nil)
// return
// }
//
// coinService := coin_service.Coin{
// Name: name,
// Chain: chain,
// Platform: platform,
// PlatformId: platform_id,
// PageNum: util.GetPage(c),
// PageSize: util.GetLimit(c),
// }
//
// total, err := coinService.Count()
// if err != nil {
// handler.SendResponse(c, errno.ErrCountCoin, nil)
// return
// }
//
// coins, err := coinService.GetAll()
// if err != nil {
// handler.SendResponse(c, errno.InternalServerError, nil)
// return
// }
//
// data := make(map[string]interface{})
// data["items"] = coins
// data["total"] = total
//
// handler.SendResponse(c, nil, data)
//}
//
//func AddCoin(c *gin.Context) {
// var addCoinRequest validate.AddCoinForm
//
// if err := c.ShouldBind(&addCoinRequest); err != nil {
// var msg = addCoinRequest.GetError(err.(validator.ValidationErrors))
// handler.SendResponse(c, errno.ErrBind, msg)
// return
// }
//
// token := c.Request.Header.Get("Token")
// authService := auth_service.Auth{Token: token}
// auth, _ := authService.GetUserInfo()
// group := auth.Group
// var platform_id int
// platform_id = auth.PlatformId
//
// if ("administrator" == group) {
// platform_id = addCoinRequest.PlatformId
// }
//
// coinService := coin_service.Coin{
// Sid: addCoinRequest.Sid,
// Name: addCoinRequest.Name,
// Nickname: addCoinRequest.Nickname,
// Icon: addCoinRequest.Icon,
// Introduce: addCoinRequest.Introduce,
// Official: addCoinRequest.Official,
// Paper: addCoinRequest.Paper,
// Platform: addCoinRequest.Platform,
// Chain: addCoinRequest.Chain,
// Release: addCoinRequest.Release,
// AreaSearch: addCoinRequest.AreaSearch,
// PublishCount: addCoinRequest.PublishCount,
// CirculateCount: addCoinRequest.CirculateCount,
// Decimals: addCoinRequest.Decimals,
// Address: addCoinRequest.Address,
// Treaty: addCoinRequest.Treaty,
// PlatformId: platform_id,
// }
//
// if err := coinService.Add(); err != nil {
// handler.SendResponse(c, errno.ErrAddCoin, nil)
// return
// }
// handler.SendResponse(c, nil, nil)
//}
//
//func EditCoin(c *gin.Context) {
// var editCoinRequest validate.EditCoinForm
//
// if err := c.ShouldBind(&editCoinRequest); err != nil {
// var msg = editCoinRequest.GetError(err.(validator.ValidationErrors))
// handler.SendResponse(c, errno.ErrBind, msg)
// return
// }
//
// coinService := coin_service.Coin{
// Id: editCoinRequest.Id,
// Sid: editCoinRequest.Sid,
// Name: editCoinRequest.Name,
// Nickname: editCoinRequest.Nickname,
// Icon: editCoinRequest.Icon,
// Introduce: editCoinRequest.Introduce,
// Official: editCoinRequest.Official,
// Paper: editCoinRequest.Paper,
// Platform: editCoinRequest.Platform,
// Chain: editCoinRequest.Chain,
// Release: editCoinRequest.Release,
// AreaSearch: editCoinRequest.AreaSearch,
// PublishCount: editCoinRequest.PublishCount,
// CirculateCount: editCoinRequest.CirculateCount,
// Decimals: editCoinRequest.Decimals,
// Address: editCoinRequest.Address,
// Treaty: editCoinRequest.Treaty,
// }
//
// exists, err := coinService.ExistById()
// if err != nil {
// handler.SendResponse(c, errno.ErrCoinNotFound, nil)
// return
// }
// if !exists {
// handler.SendResponse(c, errno.ErrCoinNotFound, nil)
// return
// }
//
// token := c.Request.Header.Get("Token")
// authService := auth_service.Auth{Token: token}
// auth, _ := authService.GetUserInfo()
// group := auth.Group
// if ("administrator" != group) {
// coin_model := coin_service.Coin{Id: editCoinRequest.Id}
// coin, _ := coin_model.Get()
// if coin.PlatformId != auth.PlatformId {
// handler.SendResponse(c, errno.ErrUserTokenIncorrect, nil)
// return
// }
// }
// if err := coinService.Edit(); err != nil {
// handler.SendResponse(c, errno.ErrUpdateCoin, nil)
// return
// }
//
// handler.SendResponse(c, nil, nil)
//}
//
//func DeleteCoin(c *gin.Context) {
// valid := validation.Validation{}
// id := com.StrTo(c.Param("id")).MustInt()
// valid.Min(id, 1, "id").Message("ID必须大于0")
//
// if valid.HasErrors() {
// handler.SendResponse(c, errno.ErrValidation, nil)
// return
// }
//
// coinService := coin_service.Coin{Id: id}
// exists, err := coinService.ExistById()
// if err != nil {
// handler.SendResponse(c, errno.ErrValidation, nil)
// return
// }
//
// if !exists {
// handler.SendResponse(c, errno.ErrValidation, nil)
// return
// }
//
// token := c.Request.Header.Get("Token")
// authService := auth_service.Auth{Token: token}
// auth, _ := authService.GetUserInfo()
// group := auth.Group
// if ("administrator" != group) {
// coin, _ := coinService.Get()
// if coin.PlatformId != auth.PlatformId {
// handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
// return
// }
// }
//
// err = coinService.Delete()
// if err != nil {
// handler.SendResponse(c, errno.ErrDeleteCoin, nil)
// return
// }
//
// handler.SendResponse(c, nil, nil)
//}
//
///*
//func GetCoinsPlatform(c *gin.Context) {
// appG := app.Gin{c}
// coinService := coin_service.Coin{}
// coins, err := coinService.GetCoinsPlatform()
// if err != nil {
// appG.Response(http.StatusInternalServerError, e.ERROR_GET_COIN_FAIL, nil)
// return
// }
//
// data := make(map[string]interface{})
// data["lists"] = coins
//
// appG.Response(http.StatusOK, e.SUCCESS, data)
//}
//*/
//
//func GetPrimaryChains(c *gin.Context) {
// data := make(map[string]interface{})
// data["items"] = [] string{"BTC", "ETH", "BTY", "DCR"}
//
// handler.SendResponse(c, nil, data)
//}
//
//func GetTypes(c *gin.Context) {
// data := make(map[string]interface{})
// data["items"] = [] string{"coins", "er c20/token"}
//
// handler.SendResponse(c, nil, data)
//}
import
(
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/auth_service"
"bwallet/service/coin_service"
"bwallet/validate_service"
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"gopkg.in/go-playground/validator.v9"
"reflect"
"strings"
)
func
validateCoinInputs
(
dataSet
interface
{})
(
bool
,
map
[
string
][]
string
)
{
validate
:=
validator
.
New
()
err
:=
validate
.
Struct
(
dataSet
)
if
err
!=
nil
{
//Validation syntax is invalid
if
err
,
ok
:=
err
.
(
*
validator
.
InvalidValidationError
);
ok
{
panic
(
err
)
}
//Validation errors occurred
errors
:=
make
(
map
[
string
][]
string
)
//Use reflector to reverse engineer struct
reflected
:=
reflect
.
ValueOf
(
dataSet
)
for
_
,
err
:=
range
err
.
(
validator
.
ValidationErrors
)
{
// Attempt to find field by name and get json tag name
field
,
_
:=
reflected
.
Type
()
.
FieldByName
(
err
.
StructField
())
var
name
string
//If json tag doesn't exist, use lower case of name
if
name
=
field
.
Tag
.
Get
(
"json"
);
name
==
""
{
name
=
strings
.
ToLower
(
err
.
StructField
())
}
switch
err
.
Tag
()
{
case
"required"
:
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" is required"
)
break
case
"email"
:
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" should be a valid email"
)
break
case
"url"
:
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" should be a valid url"
)
break
case
"eqfield"
:
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" should be equal to the "
+
err
.
Param
())
break
default
:
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" is invalid"
)
break
}
}
return
false
,
errors
}
return
true
,
nil
}
func
GetCoin
(
c
*
gin
.
Context
)
{
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
if
(
"administrator"
==
group
)
{
platform_id
=
com
.
StrTo
(
c
.
DefaultQuery
(
"platform_id"
,
"1"
))
.
MustInt
()
}
else
{
platform_id
=
auth
.
PlatformId
}
coinService
:=
coin_service
.
Coin
{
Id
:
id
,
PlatformId
:
platform_id
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
coin
,
err
:=
coinService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
coin
)
return
}
func
GetCoins
(
c
*
gin
.
Context
)
{
valid
:=
validation
.
Validation
{}
name
:=
""
if
arg
:=
c
.
Query
(
"name"
);
arg
!=
""
{
name
=
c
.
Query
(
"name"
)
}
platform
:=
""
if
arg
:=
c
.
Query
(
"platform"
);
arg
!=
""
{
platform
=
c
.
Query
(
"platform"
)
}
chain
:=
""
if
arg
:=
c
.
Query
(
"chain"
);
arg
!=
""
{
chain
=
c
.
Query
(
"chain"
)
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
platform_id
=
auth
.
PlatformId
if
(
"administrator"
==
group
)
{
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
platform_id
=
com
.
StrTo
(
c
.
Query
(
"platform_id"
))
.
MustInt
()
}
}
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
coinService
:=
coin_service
.
Coin
{
Name
:
name
,
Chain
:
chain
,
Platform
:
platform
,
PlatformId
:
platform_id
,
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
total
,
err
:=
coinService
.
Count
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCountCoin
,
nil
)
return
}
coins
,
err
:=
coinService
.
GetAll
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
return
}
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
coins
data
[
"total"
]
=
total
handler
.
SendResponse
(
c
,
nil
,
data
)
}
func
AddCoin
(
c
*
gin
.
Context
)
{
coin
:=
validate_service
.
Coin
{}
c
.
ShouldBindJSON
(
&
coin
)
//方法一
if
ok
,
errors
:=
validateCoinInputs
(
coin
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
}
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
var
platform_id
int
platform_id
=
auth
.
PlatformId
if
(
"administrator"
==
group
)
{
platform_id
=
coin
.
PlatformId
}
coinService
:=
coin_service
.
Coin
{
Sid
:
coin
.
Sid
,
Name
:
coin
.
Name
,
Nickname
:
coin
.
Nickname
,
Icon
:
coin
.
Icon
,
Introduce
:
coin
.
Introduce
,
Official
:
coin
.
Official
,
Paper
:
coin
.
Paper
,
Platform
:
coin
.
Platform
,
Chain
:
coin
.
Chain
,
Release
:
coin
.
Release
,
AreaSearch
:
coin
.
AreaSearch
,
PublishCount
:
coin
.
PublishCount
,
CirculateCount
:
coin
.
CirculateCount
,
Decimals
:
coin
.
Decimals
,
Address
:
coin
.
Address
,
Treaty
:
coin
.
Treaty
,
PlatformId
:
platform_id
,
}
if
err
:=
coinService
.
Add
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrAddCoin
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
EditCoin
(
c
*
gin
.
Context
)
{
wallet
:=
validate_service
.
EditCoin
{}
c
.
ShouldBindJSON
(
&
wallet
)
//方法一
if
ok
,
errors
:=
validateCoinInputs
(
wallet
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
}
}
coinService
:=
coin_service
.
Coin
{
Id
:
wallet
.
Id
,
Sid
:
wallet
.
Sid
,
Name
:
wallet
.
Name
,
Nickname
:
wallet
.
Nickname
,
Icon
:
wallet
.
Icon
,
Introduce
:
wallet
.
Introduce
,
Official
:
wallet
.
Official
,
Paper
:
wallet
.
Paper
,
Platform
:
wallet
.
Platform
,
Chain
:
wallet
.
Chain
,
Release
:
wallet
.
Release
,
AreaSearch
:
wallet
.
AreaSearch
,
PublishCount
:
wallet
.
PublishCount
,
CirculateCount
:
wallet
.
CirculateCount
,
Decimals
:
wallet
.
Decimals
,
Address
:
wallet
.
Address
,
Treaty
:
wallet
.
Treaty
,
}
exists
,
err
:=
coinService
.
ExistById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
return
}
if
!
exists
{
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
coin_model
:=
coin_service
.
Coin
{
Id
:
wallet
.
Id
}
coin
,
_
:=
coin_model
.
Get
()
if
coin
.
PlatformId
!=
auth
.
PlatformId
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserTokenIncorrect
,
nil
)
return
}
}
if
err
:=
coinService
.
Edit
();
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateCoin
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
func
DeleteCoin
(
c
*
gin
.
Context
)
{
valid
:=
validation
.
Validation
{}
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
coinService
:=
coin_service
.
Coin
{
Id
:
id
}
exists
,
err
:=
coinService
.
ExistById
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
if
!
exists
{
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
return
}
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
auth
,
_
:=
authService
.
GetUserInfo
()
group
:=
auth
.
Group
if
(
"administrator"
!=
group
)
{
coin
,
_
:=
coinService
.
Get
()
if
coin
.
PlatformId
!=
auth
.
PlatformId
{
handler
.
SendResponse
(
c
,
errno
.
ErrUserAuthIncorrect
,
nil
)
return
}
}
err
=
coinService
.
Delete
()
if
err
!=
nil
{
handler
.
SendResponse
(
c
,
errno
.
ErrDeleteCoin
,
nil
)
return
}
handler
.
SendResponse
(
c
,
nil
,
nil
)
}
/*
func GetCoinsPlatform(c *gin.Context) {
appG := app.Gin{c}
coinService := coin_service.Coin{}
coins, err := coinService.GetCoinsPlatform()
if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_GET_COIN_FAIL, nil)
return
}
data := make(map[string]interface{})
data["lists"] = coins
appG.Response(http.StatusOK, e.SUCCESS, data)
}
*/
func
GetPrimaryChains
(
c
*
gin
.
Context
)
{
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
[]
string
{
"BTC"
,
"ETH"
,
"BTY"
,
"DCR"
}
handler
.
SendResponse
(
c
,
nil
,
data
)
}
func
GetTypes
(
c
*
gin
.
Context
)
{
data
:=
make
(
map
[
string
]
interface
{})
data
[
"items"
]
=
[]
string
{
"coins"
,
"er c20/token"
}
handler
.
SendResponse
(
c
,
nil
,
data
)
}
routers/router.go
View file @
45ff7424
...
...
@@ -3,11 +3,11 @@ package routers
import
(
"github.com/gin-gonic/gin"
"bwallet/middleware/auth"
"bwallet/pkg/upload"
"bwallet/routers/api"
"bwallet/routers/api/v1"
"bwallet/middleware/auth"
"net/http"
"bwallet/pkg/upload"
)
func
InitRouter
()
*
gin
.
Engine
{
...
...
@@ -29,13 +29,13 @@ func InitRouter() *gin.Engine {
{
//api.POST("/upload",v1.Upload)
//
api.GET("/coins", v1.GetCoins)
//
api.POST("/coin", v1.AddCoin)
//
api.GET("/coin/:id", v1.GetCoin)
//
api.PUT("/coin", v1.EditCoin)
//
api.DELETE("/coin/:id", v1.DeleteCoin)
//
api.GET("/primary-chains", v1.GetPrimaryChains)
//
api.GET("/types", v1.GetTypes)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
api
.
GET
(
"/coin/:id"
,
v1
.
GetCoin
)
api
.
PUT
(
"/coin"
,
v1
.
EditCoin
)
api
.
DELETE
(
"/coin/:id"
,
v1
.
DeleteCoin
)
api
.
GET
(
"/primary-chains"
,
v1
.
GetPrimaryChains
)
api
.
GET
(
"/types"
,
v1
.
GetTypes
)
//api.GET("/get-platform", v1.GetCoinsPlatform)
api
.
GET
(
"/wallets"
,
v1
.
GetWallets
)
...
...
validate_service/chain.go
View file @
45ff7424
...
...
@@ -4,9 +4,9 @@ type Chain struct {
Platform
string
`json:"platform" validate:"required"`
Address
string
`json:"address" validate:"required"`
PrivateKey
string
`json:"private_key" validate:"required"`
Execer
string
`json:"execer" validate:"required"`
Token
string
`json:"token" validate:"required"`
Fee
float32
`json:"fee" validate:"required"`
Execer
string
`json:"execer" validate:"required"`
Token
string
`json:"token" validate:"required"`
Fee
float32
`json:"fee" validate:"required"`
BrowerUrl
string
`json:"brower_url" validate:"required,url"`
}
...
...
validate_service/coin.go
View file @
45ff7424
package
validate_service
import
"gopkg.in/go-playground/validator.v9"
type
Coin
struct
{
Sid
string
`json:"sid" validate:"required"`
Name
string
`json:"name" validate:"required"`
Nickname
string
`json:"nickname" validate:"required"`
Icon
string
`json:"icon" validate:"required"`
Introduce
string
`json:"introduce" validate:"required"`
type
AddCoinForm
struct
{
Sid
string
`form:"sid" json:"sid" binding:"required,gt=2,lt=20"`
Name
string
`form:"name" json:"name" binding:"required,gt=2,lt=20"`
Nickname
string
`form:"nickname" json:"nickname" binding:"required,gt=5,lt=50"`
Icon
string
`form:"icon" json:"icon" binding:"required"`
Introduce
string
`form:"introduce" json:"introduce" binding:"required,lt=500"`
Official
string
`form:"official" json:"official" binding:"required"`
Paper
string
`form:"paper" json:"paper" binding:"required"`
Platform
string
`form:"platform" json:"platform" binding:"required"`
Chain
string
`form:"chain" json:"chain" binding:"required"`
Release
string
`form:"release" json:"release" binding:"required"`
AreaSearch
string
`form:"area_search" json:"area_search" binding:"required"`
PublishCount
float64
`form:"publish_count" json:"publish_count" binding:"required"`
CirculateCount
float64
`form:"circulate_count" json:"circulate_count" binding:"required"`
Decimals
int
`form:"decimals" json:"decimals" binding:"required"`
Address
string
`form:"address" json:"address" binding:"required"`
Treaty
int
`form:"treaty" json:"treaty" binding:"required"`
PlatformId
int
`form:"platform_id" json:"platform_id" binding:"required"`
}
Official
string
`json:"official" validate:"required"`
Paper
string
`json:"paper" validate:"required"`
Platform
string
`json:"platform" validate:"required"`
Chain
string
`json:"chain" validate:"required"`
Release
string
`json:"release" validate:"required"`
type
EditCoinForm
struct
{
Id
int
`form:"id" json:"id" binding:"required"`
Sid
string
`form:"sid" json:"sid" binding:"required,gt=2,lt=20"`
Name
string
`form:"name" json:"name" binding:"required,gt=2,lt=20"`
Nickname
string
`form:"nickname" json:"nickname" binding:"required,gt=5,lt=50"`
Icon
string
`form:"icon" json:"icon" binding:"required"`
Introduce
string
`form:"introduce" json:"introduce" binding:"required,lt=500"`
Official
string
`form:"official" json:"official" binding:"required"`
Paper
string
`form:"paper" json:"paper" binding:"required"`
Platform
string
`form:"platform" json:"platform" binding:"required"`
Chain
string
`form:"chain" json:"chain" binding:"required"`
Release
string
`form:"release" json:"release" binding:"required"`
AreaSearch
string
`form:"area_search" json:"area_search" binding:"required"`
PublishCount
float64
`form:"publish_count" json:"publish_count" binding:"required"`
CirculateCount
float64
`form:"circulate_count" json:"circulate_count" binding:"required"`
Decimals
int
`form:"decimals" json:"decimals" binding:"required"`
Address
string
`form:"address" json:"address" binding:"required"`
Treaty
int
`form:"treaty" json:"treaty" binding:"required"`
PlatformId
int
`form:"platform_id" json:"platform_id" binding:"required"`
}
AreaSearch
string
`json:"area_search" validate:"required"`
PublishCount
float64
`json:"publish_count" validate:"required"`
CirculateCount
float64
`json:"circulate_count" validate:"required"`
Decimals
int
`json:"decimals" validate:"required"`
Address
string
`json:"address" validate:"required"`
func
(
r
*
AddCoinForm
)
GetError
(
err
validator
.
ValidationErrors
)
string
{
//if val, exist := err["AddCoinForm.Sid"]; exist {
// if val.Field == "Sid" {
// switch val.Tag {
// case "required":
// return "币种sid不能为空"
// case "gt":
// return "币种sid不能小于2个字符"
// case "lt":
// return "币种sid不能大于20个字符"
// }
// }
//}
//if val, exist := err["AddCoinForm.Name"]; exist {
// if val.Field == "Name" {
// switch val.Tag {
// case "required":
// return "币种名不能为空"
// case "gt":
// return "币种sid不能小于2个字符"
// case "lt":
// return "币种sid不能大于20个字符"
// }
// }
//}
//if val, exist := err["AddCoinForm.Nickname"]; exist {
// if val.Field == "Nickname" {
// switch val.Tag {
// case "required":
// return "Nickname不能为空"
// case "gt":
// return "Nickname不能小于5个字符"
// case "lt":
// return "Nickname不能大于50个字符"
// }
// }
//}
//if val, exist := err["AddCoinForm.Icon"]; exist {
// if val.Field == "Icon" {
// switch val.Tag {
// case "required":
// return "Icon不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Introduce"]; exist {
// if val.Field == "Introduce" {
// switch val.Tag {
// case "required":
// return "币种介绍不能为空"
// case "lt":
// return "币种sid不能大于500个字符"
// }
// }
//}
//if val, exist := err["AddCoinForm.Official"]; exist {
// if val.Field == "Official" {
// switch val.Tag {
// case "required":
// return "官网地址不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Paper"]; exist {
// if val.Field == "Paper" {
// switch val.Tag {
// case "required":
// return "白皮书地址不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Platform"]; exist {
// if val.Field == "Platform" {
// switch val.Tag {
// case "required":
// return "币种平台不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Chain"]; exist {
// if val.Field == "Chain" {
// switch val.Tag {
// case "required":
// return "币种Chain不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Release"]; exist {
// if val.Field == "Release" {
// switch val.Tag {
// case "required":
// return "发行时间不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.AreaSearch"]; exist {
// if val.Field == "AreaSearch" {
// switch val.Tag {
// case "required":
// return "币种区块查询url不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.PublishCount"]; exist {
// if val.Field == "PublishCount" {
// switch val.Tag {
// case "required":
// return "币种发行总量不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.CirculateCount"]; exist {
// if val.Field == "CirculateCount" {
// switch val.Tag {
// case "required":
// return "币种流通总量不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Decimals"]; exist {
// if val.Field == "Decimals" {
// switch val.Tag {
// case "required":
// return "币种精度不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Address"]; exist {
// if val.Field == "Address" {
// switch val.Tag {
// case "required":
// return "币种合约地址不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.Treaty"]; exist {
// if val.Field == "Treaty" {
// switch val.Tag {
// case "required":
// return "币种合约类型不能为空"
// }
// }
//}
//if val, exist := err["AddCoinForm.PlatformId"]; exist {
// if val.Field == "PlatformId" {
// switch val.Tag {
// case "required":
// return "币种平台不能为空"
// }
// }
//}
return
"参数错误"
Treaty
int
`json:"treaty" validate:"required"`
PlatformId
int
`json:"platform_id" validate:"required"`
}
func
(
r
*
EditCoinForm
)
GetError
(
err
validator
.
ValidationErrors
)
string
{
//if val, exist := err["EditCoinForm.Id"]; exist {
// if val.Field == "Id" {
// switch val.Tag {
// case "required":
// return "币种Id不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Sid"]; exist {
// if val.Field == "Sid" {
// switch val.Tag {
// case "required":
// return "币种sid不能为空"
// case "gt":
// return "币种sid不能小于2个字符"
// case "lt":
// return "币种sid不能大于20个字符"
// }
// }
//}
//if val, exist := err["EditCoinForm.Name"]; exist {
// if val.Field == "Name" {
// switch val.Tag {
// case "required":
// return "币种名不能为空"
// case "gt":
// return "币种sid不能小于2个字符"
// case "lt":
// return "币种sid不能大于20个字符"
// }
// }
//}
//if val, exist := err["EditCoinForm.Nickname"]; exist {
// if val.Field == "Nickname" {
// switch val.Tag {
// case "required":
// return "Nickname不能为空"
// case "gt":
// return "Nickname不能小于5个字符"
// case "lt":
// return "Nickname不能大于50个字符"
// }
// }
//}
//if val, exist := err["EditCoinForm.Icon"]; exist {
// if val.Field == "Icon" {
// switch val.Tag {
// case "required":
// return "Icon不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Introduce"]; exist {
// if val.Field == "Introduce" {
// switch val.Tag {
// case "required":
// return "币种介绍不能为空"
// case "lt":
// return "币种sid不能大于500个字符"
// }
// }
//}
//if val, exist := err["EditCoinForm.Official"]; exist {
// if val.Field == "Official" {
// switch val.Tag {
// case "required":
// return "官网地址不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Paper"]; exist {
// if val.Field == "Paper" {
// switch val.Tag {
// case "required":
// return "白皮书地址不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Platform"]; exist {
// if val.Field == "Platform" {
// switch val.Tag {
// case "required":
// return "币种平台不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Chain"]; exist {
// if val.Field == "Chain" {
// switch val.Tag {
// case "required":
// return "币种Chain不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Release"]; exist {
// if val.Field == "Release" {
// switch val.Tag {
// case "required":
// return "发行时间不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.AreaSearch"]; exist {
// if val.Field == "AreaSearch" {
// switch val.Tag {
// case "required":
// return "币种区块查询url不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.PublishCount"]; exist {
// if val.Field == "PublishCount" {
// switch val.Tag {
// case "required":
// return "币种发行总量不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.CirculateCount"]; exist {
// if val.Field == "CirculateCount" {
// switch val.Tag {
// case "required":
// return "币种流通总量不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Decimals"]; exist {
// if val.Field == "Decimals" {
// switch val.Tag {
// case "required":
// return "币种精度不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Address"]; exist {
// if val.Field == "Address" {
// switch val.Tag {
// case "required":
// return "币种合约地址不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.Treaty"]; exist {
// if val.Field == "Treaty" {
// switch val.Tag {
// case "required":
// return "币种合约类型不能为空"
// }
// }
//}
//if val, exist := err["EditCoinForm.PlatformId"]; exist {
// if val.Field == "PlatformId" {
// switch val.Tag {
// case "required":
// return "币种平台不能为空"
// }
// }
//}
return
"参数错误"
type
EditCoin
struct
{
Coin
Id
int
`json:"id" validate:"required"`
}
validate_service/recommend_coin.go
View file @
45ff7424
...
...
@@ -9,6 +9,6 @@ type RecommendCoin struct {
}
type
EditRecommendCoin
struct
{
Id
int
`json:"id" validate:"required"`
Sort
int
`json:"sort" validate:"required"`
Id
int
`json:"id" validate:"required"`
Sort
int
`json:"sort" validate:"required"`
}
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