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