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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
383 additions
and
655 deletions
+383
-655
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
+0
-0
coin.go
validate_service/coin.go
+21
-352
recommend_coin.go
validate_service/recommend_coin.go
+0
-0
No files found.
bwallet
deleted
100644 → 0
View file @
057331e0
File deleted
routers/api/v1/coin.go
View file @
45ff7424
package
v1
package
v1
//
//import (
import
(
// "github.com/gin-gonic/gin"
"bwallet/pkg/errno"
// "github.com/astaxie/beego/validation"
"bwallet/pkg/handler"
// "github.com/Unknwon/com"
"bwallet/pkg/util"
// "bwallet/service/coin_service"
"bwallet/service/auth_service"
// "bwallet/pkg/util"
"bwallet/service/coin_service"
// "bwallet/service/auth_service"
"bwallet/validate_service"
// "bwallet/pkg/handler"
"github.com/Unknwon/com"
// "bwallet/pkg/errno"
"github.com/astaxie/beego/validation"
// "gopkg.in/go-playground/validator.v9"
"github.com/gin-gonic/gin"
// "bwallet/validate_service"
"gopkg.in/go-playground/validator.v9"
//)
"reflect"
//
"strings"
//func GetCoin(c *gin.Context) {
)
// id := com.StrTo(c.Param("id")).MustInt()
// valid := validation.Validation{}
func
validateCoinInputs
(
dataSet
interface
{})
(
bool
,
map
[
string
][]
string
)
{
// valid.Min(id, 1, "id").Message("ID必须大于0")
validate
:=
validator
.
New
()
//
// if valid.HasErrors() {
err
:=
validate
.
Struct
(
dataSet
)
// handler.SendResponse(c, errno.ErrValidation, nil)
// return
if
err
!=
nil
{
// }
//
//Validation syntax is invalid
// token := c.Request.Header.Get("Token")
if
err
,
ok
:=
err
.
(
*
validator
.
InvalidValidationError
);
ok
{
// authService := auth_service.Auth{Token: token}
panic
(
err
)
// auth, _ := authService.GetUserInfo()
}
// group := auth.Group
// var platform_id int
//Validation errors occurred
// if ("administrator" == group) {
errors
:=
make
(
map
[
string
][]
string
)
// platform_id = com.StrTo(c.DefaultQuery("platform_id", "1")).MustInt()
//Use reflector to reverse engineer struct
// } else {
reflected
:=
reflect
.
ValueOf
(
dataSet
)
// platform_id = auth.PlatformId
for
_
,
err
:=
range
err
.
(
validator
.
ValidationErrors
)
{
// }
// coinService := coin_service.Coin{
// Attempt to find field by name and get json tag name
// Id: id,
field
,
_
:=
reflected
.
Type
()
.
FieldByName
(
err
.
StructField
())
// PlatformId: platform_id,
var
name
string
// PageNum: util.GetPage(c),
// PageSize: util.GetLimit(c),
//If json tag doesn't exist, use lower case of name
// }
if
name
=
field
.
Tag
.
Get
(
"json"
);
name
==
""
{
//
name
=
strings
.
ToLower
(
err
.
StructField
())
// coin, err := coinService.GetAll()
}
// if err != nil {
// handler.SendResponse(c, errno.ErrCoinNotFound, nil)
switch
err
.
Tag
()
{
// return
case
"required"
:
// }
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" is required"
)
//
break
// handler.SendResponse(c, nil, coin)
case
"email"
:
// return
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" should be a valid email"
)
//}
break
//
case
"url"
:
//func GetCoins(c *gin.Context) {
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" should be a valid url"
)
// valid := validation.Validation{}
break
//
case
"eqfield"
:
// name := ""
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" should be equal to the "
+
err
.
Param
())
// if arg := c.Query("name"); arg != "" {
break
// name = c.Query("name")
default
:
// }
errors
[
name
]
=
append
(
errors
[
name
],
"The "
+
name
+
" is invalid"
)
//
break
// platform := ""
}
// if arg := c.Query("platform"); arg != "" {
}
// platform = c.Query("platform")
// }
return
false
,
errors
//
}
// chain := ""
return
true
,
nil
// if arg := c.Query("chain"); arg != "" {
}
// chain = c.Query("chain")
// }
func
GetCoin
(
c
*
gin
.
Context
)
{
//
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
// token := c.Request.Header.Get("Token")
valid
:=
validation
.
Validation
{}
// authService := auth_service.Auth{Token: token}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
// auth, _ := authService.GetUserInfo()
// group := auth.Group
if
valid
.
HasErrors
()
{
//
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
// var platform_id int
return
// platform_id = auth.PlatformId
}
// if ("administrator" == group) {
// if arg := c.Query("platform_id"); arg != "" {
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
// platform_id = com.StrTo(c.Query("platform_id")).MustInt()
authService
:=
auth_service
.
Auth
{
Token
:
token
}
// }
auth
,
_
:=
authService
.
GetUserInfo
()
// }
group
:=
auth
.
Group
//
var
platform_id
int
// if valid.HasErrors() {
if
(
"administrator"
==
group
)
{
// handler.SendResponse(c, errno.ErrValidation, nil)
platform_id
=
com
.
StrTo
(
c
.
DefaultQuery
(
"platform_id"
,
"1"
))
.
MustInt
()
// return
}
else
{
// }
platform_id
=
auth
.
PlatformId
//
}
// coinService := coin_service.Coin{
coinService
:=
coin_service
.
Coin
{
// Name: name,
Id
:
id
,
// Chain: chain,
PlatformId
:
platform_id
,
// Platform: platform,
PageNum
:
util
.
GetPage
(
c
),
// PlatformId: platform_id,
PageSize
:
util
.
GetLimit
(
c
),
// PageNum: util.GetPage(c),
}
// PageSize: util.GetLimit(c),
// }
coin
,
err
:=
coinService
.
GetAll
()
//
if
err
!=
nil
{
// total, err := coinService.Count()
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
// if err != nil {
return
// handler.SendResponse(c, errno.ErrCountCoin, nil)
}
// return
// }
handler
.
SendResponse
(
c
,
nil
,
coin
)
//
return
// coins, err := coinService.GetAll()
}
// if err != nil {
// handler.SendResponse(c, errno.InternalServerError, nil)
func
GetCoins
(
c
*
gin
.
Context
)
{
// return
valid
:=
validation
.
Validation
{}
// }
//
name
:=
""
// data := make(map[string]interface{})
if
arg
:=
c
.
Query
(
"name"
);
arg
!=
""
{
// data["items"] = coins
name
=
c
.
Query
(
"name"
)
// data["total"] = total
}
//
// handler.SendResponse(c, nil, data)
platform
:=
""
//}
if
arg
:=
c
.
Query
(
"platform"
);
arg
!=
""
{
//
platform
=
c
.
Query
(
"platform"
)
//func AddCoin(c *gin.Context) {
}
// var addCoinRequest validate.AddCoinForm
//
chain
:=
""
// if err := c.ShouldBind(&addCoinRequest); err != nil {
if
arg
:=
c
.
Query
(
"chain"
);
arg
!=
""
{
// var msg = addCoinRequest.GetError(err.(validator.ValidationErrors))
chain
=
c
.
Query
(
"chain"
)
// handler.SendResponse(c, errno.ErrBind, msg)
}
// return
// }
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
//
authService
:=
auth_service
.
Auth
{
Token
:
token
}
// token := c.Request.Header.Get("Token")
auth
,
_
:=
authService
.
GetUserInfo
()
// authService := auth_service.Auth{Token: token}
group
:=
auth
.
Group
// auth, _ := authService.GetUserInfo()
// group := auth.Group
var
platform_id
int
// var platform_id int
platform_id
=
auth
.
PlatformId
// platform_id = auth.PlatformId
if
(
"administrator"
==
group
)
{
//
if
arg
:=
c
.
Query
(
"platform_id"
);
arg
!=
""
{
// if ("administrator" == group) {
platform_id
=
com
.
StrTo
(
c
.
Query
(
"platform_id"
))
.
MustInt
()
// platform_id = addCoinRequest.PlatformId
}
// }
}
//
// coinService := coin_service.Coin{
if
valid
.
HasErrors
()
{
// Sid: addCoinRequest.Sid,
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
// Name: addCoinRequest.Name,
return
// Nickname: addCoinRequest.Nickname,
}
// Icon: addCoinRequest.Icon,
// Introduce: addCoinRequest.Introduce,
coinService
:=
coin_service
.
Coin
{
// Official: addCoinRequest.Official,
Name
:
name
,
// Paper: addCoinRequest.Paper,
Chain
:
chain
,
// Platform: addCoinRequest.Platform,
Platform
:
platform
,
// Chain: addCoinRequest.Chain,
PlatformId
:
platform_id
,
// Release: addCoinRequest.Release,
PageNum
:
util
.
GetPage
(
c
),
// AreaSearch: addCoinRequest.AreaSearch,
PageSize
:
util
.
GetLimit
(
c
),
// PublishCount: addCoinRequest.PublishCount,
}
// CirculateCount: addCoinRequest.CirculateCount,
// Decimals: addCoinRequest.Decimals,
total
,
err
:=
coinService
.
Count
()
// Address: addCoinRequest.Address,
if
err
!=
nil
{
// Treaty: addCoinRequest.Treaty,
handler
.
SendResponse
(
c
,
errno
.
ErrCountCoin
,
nil
)
// PlatformId: platform_id,
return
// }
}
//
// if err := coinService.Add(); err != nil {
coins
,
err
:=
coinService
.
GetAll
()
// handler.SendResponse(c, errno.ErrAddCoin, nil)
if
err
!=
nil
{
// return
handler
.
SendResponse
(
c
,
errno
.
InternalServerError
,
nil
)
// }
return
// handler.SendResponse(c, nil, nil)
}
//}
//
data
:=
make
(
map
[
string
]
interface
{})
//func EditCoin(c *gin.Context) {
data
[
"items"
]
=
coins
// var editCoinRequest validate.EditCoinForm
data
[
"total"
]
=
total
//
// if err := c.ShouldBind(&editCoinRequest); err != nil {
handler
.
SendResponse
(
c
,
nil
,
data
)
// var msg = editCoinRequest.GetError(err.(validator.ValidationErrors))
}
// handler.SendResponse(c, errno.ErrBind, msg)
// return
func
AddCoin
(
c
*
gin
.
Context
)
{
// }
coin
:=
validate_service
.
Coin
{}
//
c
.
ShouldBindJSON
(
&
coin
)
// coinService := coin_service.Coin{
// Id: editCoinRequest.Id,
//方法一
// Sid: editCoinRequest.Sid,
if
ok
,
errors
:=
validateCoinInputs
(
coin
);
!
ok
{
// Name: editCoinRequest.Name,
for
_
,
err
:=
range
errors
{
// Nickname: editCoinRequest.Nickname,
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
// Icon: editCoinRequest.Icon,
return
// Introduce: editCoinRequest.Introduce,
}
// Official: editCoinRequest.Official,
}
// Paper: editCoinRequest.Paper,
// Platform: editCoinRequest.Platform,
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
// Chain: editCoinRequest.Chain,
authService
:=
auth_service
.
Auth
{
Token
:
token
}
// Release: editCoinRequest.Release,
auth
,
_
:=
authService
.
GetUserInfo
()
// AreaSearch: editCoinRequest.AreaSearch,
group
:=
auth
.
Group
// PublishCount: editCoinRequest.PublishCount,
var
platform_id
int
// CirculateCount: editCoinRequest.CirculateCount,
platform_id
=
auth
.
PlatformId
// Decimals: editCoinRequest.Decimals,
// Address: editCoinRequest.Address,
if
(
"administrator"
==
group
)
{
// Treaty: editCoinRequest.Treaty,
platform_id
=
coin
.
PlatformId
// }
}
//
// exists, err := coinService.ExistById()
coinService
:=
coin_service
.
Coin
{
// if err != nil {
Sid
:
coin
.
Sid
,
// handler.SendResponse(c, errno.ErrCoinNotFound, nil)
Name
:
coin
.
Name
,
// return
Nickname
:
coin
.
Nickname
,
// }
Icon
:
coin
.
Icon
,
// if !exists {
Introduce
:
coin
.
Introduce
,
// handler.SendResponse(c, errno.ErrCoinNotFound, nil)
Official
:
coin
.
Official
,
// return
Paper
:
coin
.
Paper
,
// }
Platform
:
coin
.
Platform
,
//
Chain
:
coin
.
Chain
,
// token := c.Request.Header.Get("Token")
Release
:
coin
.
Release
,
// authService := auth_service.Auth{Token: token}
AreaSearch
:
coin
.
AreaSearch
,
// auth, _ := authService.GetUserInfo()
PublishCount
:
coin
.
PublishCount
,
// group := auth.Group
CirculateCount
:
coin
.
CirculateCount
,
// if ("administrator" != group) {
Decimals
:
coin
.
Decimals
,
// coin_model := coin_service.Coin{Id: editCoinRequest.Id}
Address
:
coin
.
Address
,
// coin, _ := coin_model.Get()
Treaty
:
coin
.
Treaty
,
// if coin.PlatformId != auth.PlatformId {
PlatformId
:
platform_id
,
// handler.SendResponse(c, errno.ErrUserTokenIncorrect, nil)
}
// return
// }
if
err
:=
coinService
.
Add
();
err
!=
nil
{
// }
handler
.
SendResponse
(
c
,
errno
.
ErrAddCoin
,
nil
)
// if err := coinService.Edit(); err != nil {
return
// handler.SendResponse(c, errno.ErrUpdateCoin, nil)
}
// return
handler
.
SendResponse
(
c
,
nil
,
nil
)
// }
}
//
// handler.SendResponse(c, nil, nil)
func
EditCoin
(
c
*
gin
.
Context
)
{
//}
wallet
:=
validate_service
.
EditCoin
{}
//
c
.
ShouldBindJSON
(
&
wallet
)
//func DeleteCoin(c *gin.Context) {
// valid := validation.Validation{}
//方法一
// id := com.StrTo(c.Param("id")).MustInt()
if
ok
,
errors
:=
validateCoinInputs
(
wallet
);
!
ok
{
// valid.Min(id, 1, "id").Message("ID必须大于0")
for
_
,
err
:=
range
errors
{
//
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
// if valid.HasErrors() {
return
// handler.SendResponse(c, errno.ErrValidation, nil)
}
// return
}
// }
//
coinService
:=
coin_service
.
Coin
{
// coinService := coin_service.Coin{Id: id}
Id
:
wallet
.
Id
,
// exists, err := coinService.ExistById()
Sid
:
wallet
.
Sid
,
// if err != nil {
Name
:
wallet
.
Name
,
// handler.SendResponse(c, errno.ErrValidation, nil)
Nickname
:
wallet
.
Nickname
,
// return
Icon
:
wallet
.
Icon
,
// }
Introduce
:
wallet
.
Introduce
,
//
Official
:
wallet
.
Official
,
// if !exists {
Paper
:
wallet
.
Paper
,
// handler.SendResponse(c, errno.ErrValidation, nil)
Platform
:
wallet
.
Platform
,
// return
Chain
:
wallet
.
Chain
,
// }
Release
:
wallet
.
Release
,
//
AreaSearch
:
wallet
.
AreaSearch
,
// token := c.Request.Header.Get("Token")
PublishCount
:
wallet
.
PublishCount
,
// authService := auth_service.Auth{Token: token}
CirculateCount
:
wallet
.
CirculateCount
,
// auth, _ := authService.GetUserInfo()
Decimals
:
wallet
.
Decimals
,
// group := auth.Group
Address
:
wallet
.
Address
,
// if ("administrator" != group) {
Treaty
:
wallet
.
Treaty
,
// coin, _ := coinService.Get()
}
// if coin.PlatformId != auth.PlatformId {
// handler.SendResponse(c, errno.ErrUserAuthIncorrect, nil)
exists
,
err
:=
coinService
.
ExistById
()
// return
if
err
!=
nil
{
// }
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
// }
return
//
}
// err = coinService.Delete()
if
!
exists
{
// if err != nil {
handler
.
SendResponse
(
c
,
errno
.
ErrCoinNotFound
,
nil
)
// handler.SendResponse(c, errno.ErrDeleteCoin, nil)
return
// return
}
// }
//
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
// handler.SendResponse(c, nil, nil)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
//}
auth
,
_
:=
authService
.
GetUserInfo
()
//
group
:=
auth
.
Group
///*
if
(
"administrator"
!=
group
)
{
//func GetCoinsPlatform(c *gin.Context) {
coin_model
:=
coin_service
.
Coin
{
Id
:
wallet
.
Id
}
// appG := app.Gin{c}
coin
,
_
:=
coin_model
.
Get
()
// coinService := coin_service.Coin{}
if
coin
.
PlatformId
!=
auth
.
PlatformId
{
// coins, err := coinService.GetCoinsPlatform()
handler
.
SendResponse
(
c
,
errno
.
ErrUserTokenIncorrect
,
nil
)
// if err != nil {
return
// appG.Response(http.StatusInternalServerError, e.ERROR_GET_COIN_FAIL, nil)
}
// return
}
// }
if
err
:=
coinService
.
Edit
();
err
!=
nil
{
//
handler
.
SendResponse
(
c
,
errno
.
ErrUpdateCoin
,
nil
)
// data := make(map[string]interface{})
return
// data["lists"] = coins
}
//
// appG.Response(http.StatusOK, e.SUCCESS, data)
handler
.
SendResponse
(
c
,
nil
,
nil
)
//}
}
//*/
//
func
DeleteCoin
(
c
*
gin
.
Context
)
{
//func GetPrimaryChains(c *gin.Context) {
valid
:=
validation
.
Validation
{}
// data := make(map[string]interface{})
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
// data["items"] = [] string{"BTC", "ETH", "BTY", "DCR"}
valid
.
Min
(
id
,
1
,
"id"
)
.
Message
(
"ID必须大于0"
)
//
// handler.SendResponse(c, nil, data)
if
valid
.
HasErrors
()
{
//}
handler
.
SendResponse
(
c
,
errno
.
ErrValidation
,
nil
)
//
return
//func GetTypes(c *gin.Context) {
}
// data := make(map[string]interface{})
// data["items"] = [] string{"coins", "er c20/token"}
coinService
:=
coin_service
.
Coin
{
Id
:
id
}
//
exists
,
err
:=
coinService
.
ExistById
()
// handler.SendResponse(c, nil, data)
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
...
@@ -3,11 +3,11 @@ package routers
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"bwallet/middleware/auth"
"bwallet/pkg/upload"
"bwallet/routers/api"
"bwallet/routers/api"
"bwallet/routers/api/v1"
"bwallet/routers/api/v1"
"bwallet/middleware/auth"
"net/http"
"net/http"
"bwallet/pkg/upload"
)
)
func
InitRouter
()
*
gin
.
Engine
{
func
InitRouter
()
*
gin
.
Engine
{
...
@@ -29,13 +29,13 @@ func InitRouter() *gin.Engine {
...
@@ -29,13 +29,13 @@ func InitRouter() *gin.Engine {
{
{
//api.POST("/upload",v1.Upload)
//api.POST("/upload",v1.Upload)
//
api.GET("/coins", v1.GetCoins)
api
.
GET
(
"/coins"
,
v1
.
GetCoins
)
//
api.POST("/coin", v1.AddCoin)
api
.
POST
(
"/coin"
,
v1
.
AddCoin
)
//
api.GET("/coin/:id", v1.GetCoin)
api
.
GET
(
"/coin/:id"
,
v1
.
GetCoin
)
//
api.PUT("/coin", v1.EditCoin)
api
.
PUT
(
"/coin"
,
v1
.
EditCoin
)
//
api.DELETE("/coin/:id", v1.DeleteCoin)
api
.
DELETE
(
"/coin/:id"
,
v1
.
DeleteCoin
)
//
api.GET("/primary-chains", v1.GetPrimaryChains)
api
.
GET
(
"/primary-chains"
,
v1
.
GetPrimaryChains
)
//
api.GET("/types", v1.GetTypes)
api
.
GET
(
"/types"
,
v1
.
GetTypes
)
//api.GET("/get-platform", v1.GetCoinsPlatform)
//api.GET("/get-platform", v1.GetCoinsPlatform)
api
.
GET
(
"/wallets"
,
v1
.
GetWallets
)
api
.
GET
(
"/wallets"
,
v1
.
GetWallets
)
...
...
validate_service/chain.go
View file @
45ff7424
validate_service/coin.go
View file @
45ff7424
package
validate_service
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
{
Official
string
`json:"official" validate:"required"`
Sid
string
`form:"sid" json:"sid" binding:"required,gt=2,lt=20"`
Paper
string
`json:"paper" validate:"required"`
Name
string
`form:"name" json:"name" binding:"required,gt=2,lt=20"`
Platform
string
`json:"platform" validate:"required"`
Nickname
string
`form:"nickname" json:"nickname" binding:"required,gt=5,lt=50"`
Chain
string
`json:"chain" validate:"required"`
Icon
string
`form:"icon" json:"icon" binding:"required"`
Release
string
`json:"release" validate:"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"`
}
type
EditCoinForm
struct
{
AreaSearch
string
`json:"area_search" validate:"required"`
Id
int
`form:"id" json:"id" binding:"required"`
PublishCount
float64
`json:"publish_count" validate:"required"`
Sid
string
`form:"sid" json:"sid" binding:"required,gt=2,lt=20"`
CirculateCount
float64
`json:"circulate_count" validate:"required"`
Name
string
`form:"name" json:"name" binding:"required,gt=2,lt=20"`
Decimals
int
`json:"decimals" validate:"required"`
Nickname
string
`form:"nickname" json:"nickname" binding:"required,gt=5,lt=50"`
Address
string
`json:"address" validate:"required"`
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"`
}
func
(
r
*
AddCoinForm
)
GetError
(
err
validator
.
ValidationErrors
)
string
{
Treaty
int
`json:"treaty" validate:"required"`
//if val, exist := err["AddCoinForm.Sid"]; exist {
PlatformId
int
`json:"platform_id" validate:"required"`
// 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
"参数错误"
}
}
func
(
r
*
EditCoinForm
)
GetError
(
err
validator
.
ValidationErrors
)
string
{
type
EditCoin
struct
{
//if val, exist := err["EditCoinForm.Id"]; exist {
Coin
// if val.Field == "Id" {
Id
int
`json:"id" validate:"required"`
// 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
"参数错误"
}
}
validate_service/recommend_coin.go
View file @
45ff7424
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