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
118814fa
Commit
118814fa
authored
Jan 06, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
b16c21ed
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
262 deletions
+57
-262
coin.go
models/coin.go
+26
-25
chain.go
routers/api/v1/chain.go
+2
-55
coin.go
routers/api/v1/coin.go
+4
-55
recommend_coin.go
routers/api/v1/recommend_coin.go
+2
-55
wallet.go
routers/api/v1/wallet.go
+2
-55
coin.go
service/coin_service/coin.go
+14
-12
coin.go
validate_service/coin.go
+7
-5
No files found.
models/coin.go
View file @
118814fa
package
models
import
(
"github.com/jinzhu/gorm"
"bwallet/pkg/setting"
"encoding/json"
"github.com/jinzhu/gorm"
)
type
Coin
struct
{
Model
Id
int
`json:"primary_key,omitempt
y"`
Sid
string
`json:"sid,omitempty
"`
//全称
Name
string
`json:"name,omitempty
"`
//简称
Nickname
string
`json:"nickname,omitempty
"`
//全称
Icon
string
`json:"icon,omitempty
"`
//币种图标
Introduce
string
`json:"introduce,omitempty
"`
//币种介绍
Official
string
`json:"official,omitempty
"`
//官网
Paper
string
`json:"paper,omitempty
"`
//白皮书
Platform
string
`json:"platform,omitempty
"`
//平台
Chain
string
`json:"chain,omitempty
"`
//主链
Release
string
`json:"release,omitempty
"`
//发行时间
AreaSearch
string
`json:"area_search,omitempty
"`
//区块查询
PublishCount
float64
`json:"publish_count,omitempty
"`
//发行总量
CirculateCount
float64
`json:"circulate_count,omitempty
"`
//流通总量
Decimals
int
`json:"decimals,omitempty
"`
//币种精度
Address
string
`json:"address,omitempty
"`
//合约地址
Treaty
int
`json:"treaty,omitemp
ty"`
//币种类型
PlatformId
int
`json:"platform_id,omitempty
"`
//OptionalName string `json:"optional_name
,omitempty
"`
//Exchange int `json:"exchange
,omitempty
"`
//Price float64 `json:"price
,omitempty
"`
Id
int
`json:"primary_ke
y"`
Sid
string
`json:"sid
"`
//全称
Name
string
`json:"name
"`
//简称
Nickname
json
.
RawMessage
`json:"nickname
"`
//全称
Icon
string
`json:"icon
"`
//币种图标
Introduce
json
.
RawMessage
`json:"introduce
"`
//币种介绍
Official
string
`json:"official
"`
//官网
Paper
string
`json:"paper
"`
//白皮书
Platform
string
`json:"platform
"`
//平台
Chain
string
`json:"chain
"`
//主链
Release
string
`json:"release
"`
//发行时间
AreaSearch
string
`json:"area_search
"`
//区块查询
PublishCount
float64
`json:"publish_count
"`
//发行总量
CirculateCount
float64
`json:"circulate_count
"`
//流通总量
Decimals
int
`json:"decimals
"`
//币种精度
Address
string
`json:"address
"`
//合约地址
Treaty
int
`json:"trea
ty"`
//币种类型
PlatformId
int
`json:"platform_id
"`
//OptionalName string `json:"optional_name"`
//Exchange int `json:"exchange"`
//Price float64 `json:"price"`
}
func
(
c
Coin
)
TableName
()
string
{
...
...
@@ -114,9 +115,9 @@ func AddCoin(data map[string]interface{}) (error) {
coin
:=
Coin
{
Sid
:
data
[
"sid"
]
.
(
string
),
Name
:
data
[
"name"
]
.
(
string
),
Nickname
:
"{
\"
ja
\"
:
\"\"
,
\"
en-US
\"
:
\"\"
,
\"
zh-CN
\"
:
\"
ICON
\"
}"
,
Nickname
:
data
[
"nickname"
]
.
(
json
.
RawMessage
)
,
Icon
:
data
[
"icon"
]
.
(
string
),
Introduce
:
"{
\"
ja
\"
:
\"\"
,
\"
en-US
\"
:
\"\"
,
\"
zh-CN
\"
:
\"
ICON
\"
}"
,
Introduce
:
data
[
"introduce"
]
.
(
json
.
RawMessage
)
,
Official
:
data
[
"official"
]
.
(
string
),
Paper
:
data
[
"paper"
]
.
(
string
),
Platform
:
data
[
"platform"
]
.
(
string
),
...
...
routers/api/v1/chain.go
View file @
118814fa
...
...
@@ -10,62 +10,9 @@ import (
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"gopkg.in/go-playground/validator.v9"
"reflect"
"strings"
)
func
validateChainInputs
(
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
GetChain
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
authService
:=
auth_service
.
Auth
{
Token
:
token
}
...
...
@@ -167,7 +114,7 @@ func AddChain(c *gin.Context) {
c
.
ShouldBindJSON
(
&
chain
)
//方法一
if
ok
,
errors
:=
validate
Chain
Inputs
(
chain
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
chain
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
@@ -206,7 +153,7 @@ func EditChain(c *gin.Context) {
c
.
ShouldBindJSON
(
&
chain
)
//方法一
if
ok
,
errors
:=
validate
Chain
Inputs
(
chain
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
chain
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
routers/api/v1/coin.go
View file @
118814fa
...
...
@@ -7,65 +7,13 @@ import (
"bwallet/service/auth_service"
"bwallet/service/coin_service"
"bwallet/validate_service"
"fmt"
"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
{}
...
...
@@ -170,8 +118,9 @@ func GetCoins(c *gin.Context) {
func
AddCoin
(
c
*
gin
.
Context
)
{
coin
:=
validate_service
.
Coin
{}
c
.
ShouldBindJSON
(
&
coin
)
fmt
.
Println
(
coin
)
//方法一
if
ok
,
errors
:=
validate
Coin
Inputs
(
coin
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
coin
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
@@ -221,7 +170,7 @@ func EditCoin(c *gin.Context) {
c
.
ShouldBindJSON
(
&
coin
)
//方法一
if
ok
,
errors
:=
validate
Coin
Inputs
(
coin
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
coin
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
routers/api/v1/recommend_coin.go
View file @
118814fa
...
...
@@ -10,62 +10,9 @@ import (
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"gopkg.in/go-playground/validator.v9"
"reflect"
"strings"
)
func
validateRecommendCoinInputs
(
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
GetRecommendCoins
(
c
*
gin
.
Context
)
{
token
:=
c
.
Request
.
Header
.
Get
(
"Token"
)
...
...
@@ -111,7 +58,7 @@ func AddRecommendCoin(c *gin.Context) {
c
.
ShouldBindJSON
(
&
recommend_coin
)
//方法一
if
ok
,
errors
:=
validate
RecommendCoin
Inputs
(
recommend_coin
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
recommend_coin
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
@@ -150,7 +97,7 @@ func EditRecommendCoin(c *gin.Context) {
c
.
ShouldBindJSON
(
&
recommend_coin
)
//方法一
if
ok
,
errors
:=
validate
Wallet
Inputs
(
recommend_coin
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
recommend_coin
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
routers/api/v1/wallet.go
View file @
118814fa
...
...
@@ -10,62 +10,9 @@ import (
"github.com/Unknwon/com"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"gopkg.in/go-playground/validator.v9"
"reflect"
"strings"
)
func
validateWalletInputs
(
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
GetWallet
(
c
*
gin
.
Context
)
{
id
:=
com
.
StrTo
(
c
.
Param
(
"id"
))
.
MustInt
()
valid
:=
validation
.
Validation
{}
...
...
@@ -178,7 +125,7 @@ func AddWallet(c *gin.Context) {
c
.
ShouldBindJSON
(
&
wallet
)
//方法一
if
ok
,
errors
:=
validate
Wallet
Inputs
(
wallet
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
wallet
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
@@ -257,7 +204,7 @@ func EditWallet(c *gin.Context) {
c
.
ShouldBindJSON
(
&
wallet
)
//方法一
if
ok
,
errors
:=
validate
Wallet
Inputs
(
wallet
);
!
ok
{
if
ok
,
errors
:=
validate
_service
.
Validate
Inputs
(
wallet
);
!
ok
{
for
_
,
err
:=
range
errors
{
handler
.
SendResponse
(
c
,
errno
.
ErrBind
,
strings
.
Join
(
err
,
" "
))
return
...
...
service/coin_service/coin.go
View file @
118814fa
...
...
@@ -3,15 +3,17 @@ package coin_service
import
(
"bwallet/models"
"encoding/json"
//"encoding/json"
)
type
Coin
struct
{
Id
int
Sid
string
Name
string
Nickname
string
Nickname
json
.
RawMessage
Icon
string
Introduce
string
Introduce
json
.
RawMessage
Official
string
Paper
string
Platform
string
...
...
@@ -40,10 +42,10 @@ func (c *Coin) Get() (*models.Coin, error) {
return
nil
,
err
}
var
m
map
[
string
]
interface
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
coin
.
Nickname
),
&
m
);
err
==
nil
{
coin
.
Nickname
=
m
[
"zh-CN"
]
.
(
string
)
}
//
var m map[string]interface{}
//
if err := json.Unmarshal([]byte(coin.Nickname), &m); err == nil {
//
coin.Nickname = m["zh-CN"].(string)
//
}
return
coin
,
nil
}
...
...
@@ -60,12 +62,12 @@ func (c *Coin) GetAll() ([]*models.Coin, error) {
return
nil
,
err
}
var
m
map
[
string
]
interface
{}
for
_
,
value
:=
range
coins
{
if
err
:=
json
.
Unmarshal
([]
byte
(
value
.
Nickname
),
&
m
);
err
==
nil
{
value
.
Nickname
=
m
[
"zh-CN"
]
.
(
string
)
}
}
//
var m map[string]interface{}
//
for _, value := range coins {
//
if err := json.Unmarshal([]byte(value.Nickname), &m); err == nil {
//
value.Nickname = m["zh-CN"].(string)
//
}
//
}
return
coins
,
nil
}
...
...
validate_service/coin.go
View file @
118814fa
package
validate_service
import
"encoding/json"
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"`
Sid
string
`json:"sid" validate:"required"`
Name
string
`json:"name" validate:"required"`
Nickname
json
.
RawMessage
`json:"nickname" validate:"required"`
Icon
string
`json:"icon" validate:"required"`
Introduce
json
.
RawMessage
`json:"introduce" validate:"required"`
Official
string
`json:"official" validate:"required"`
Paper
string
`json:"paper" 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