Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wang
/
golang-open-platform
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
43dfb990
authored
Feb 24, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'dev' into ws-limiting=20210222
parents
67ad96bf
83b2ede0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
46 deletions
cmd/http_server.go
controller/sku_controller.go
doc/redis_config_generate.go
model/filter.go
service/service_sku.go
cmd/http_server.go
deleted
100644 → 0
View file @
67ad96bf
package
main
import
(
"flag"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web"
"golang_open_platform/boot"
"golang_open_platform/pkg/config"
"golang_open_platform/routes"
)
func
main
()
{
var
path
string
flag
.
StringVar
(
&
path
,
"config"
,
"conf"
,
"配置文件"
)
flag
.
Parse
()
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
panic
(
err
)
}
gin
.
SetMode
(
config
.
Get
(
"web.mode"
)
.
String
())
r
:=
routes
.
InitRouter
()
port
:=
config
.
Get
(
"web.port"
)
.
String
()
//web改成micro 就是grpc,并直接注册到etcd里面
service
:=
web
.
NewService
(
web
.
Name
(
"go.micro.api.http.search"
),
web
.
Handler
(
r
),
web
.
Address
(
":"
+
port
),
)
if
err
:=
service
.
Init
();
err
!=
nil
{
panic
(
err
)
}
if
err
:=
service
.
Run
();
err
!=
nil
{
panic
(
err
)
}
}
controller/sku_controller.go
View file @
43dfb990
...
...
@@ -26,7 +26,7 @@ func GetSkuListByClass(ctx *gin.Context) {
e
.
CheckError
(
model
.
ValidateBind
(
ctx
,
req
))
rsp
,
err
:=
service
.
NewSkuService
()
.
GetSkuListByClass
(
req
)
e
.
CheckError
(
err
)
common
.
NResponse
(
""
,
20
0
,
rsp
)
.
OutPut
(
ctx
)
common
.
NResponse
(
""
,
0
,
rsp
)
.
OutPut
(
ctx
)
}
/**
用goods_id 获取sku列表完整字段
...
...
doc/redis_config_generate.go
View file @
43dfb990
...
...
@@ -56,7 +56,7 @@ func generate() {
//白名单配置
func
whiteIp
()
{
redisKey
:=
openWhiteList
whiteList
:=
[]
string
{
/*
whiteList:=[]string{
"127.0.0.1",
"127.0.0.2",
"192.168.2.72",
...
...
@@ -64,8 +64,27 @@ func whiteIp() {
"192.168.2.241",
"192.168.1.1",
"192.168.2.129",
}*/
//线上配置
whiteList
:=
[]
string
{
"127.0.0.1"
,
"::1"
,
"119.123.78.115"
,
"172.18.137.41"
,
"172.18.137.42"
,
"192.168.2.129"
,
"19.123.78.115"
,
"222.92.21.99"
,
"::1"
,
}
/*whiteList:=[]string{
"172.18.137.41",
"::1",
}*/
fmt
.
Println
(
"白名单配置:"
+
redisKey
)
redisStringSet
(
redisKey
,
whiteList
)
}
...
...
model/filter.go
View file @
43dfb990
...
...
@@ -10,6 +10,9 @@ import (
//过滤
func
SkuFilter
(
remoteData
RemoteSkuData
,
filedStr
[]
string
)
(
data
RemoteSkuData
)
{
remoteData
=
filterData
(
remoteData
,
filedStr
)
if
(
len
(
remoteData
)
==
0
){
return
nil
}
return
remoteData
}
...
...
service/service_sku.go
View file @
43dfb990
...
...
@@ -11,7 +11,6 @@ import (
"golang_open_platform/pkg/common"
"golang_open_platform/pkg/config"
"golang_open_platform/pkg/e"
"math"
"strings"
)
type
SkuService
struct
{
...
...
@@ -33,9 +32,9 @@ func (this *SkuService)GetSkuListByClass(req *model.QuerySkuCreq) (rsp *model.Qu
}
if
(
req
.
Page
>
0
){
//验证下page是否有效
if
(
math
.
Ceil
(
float64
(
pageData
.
Count
/
rsp
.
PageSize
))
<
float64
(
req
.
Page
)){
/*
if(math.Ceil(float64(pageData.Count/rsp.PageSize))<float64(req.Page)){
return nil,e.NewApiError("page invalid",open.PARAM1)
}
}
*/
mongoOpenSku
,
err
:=
dao
.
GetMongoOpenSku
(
req
.
ClassId
,
req
.
Page
)
if
(
err
!=
nil
){
return
nil
,
e
.
NewApiError
(
"service error"
,
open
.
OTHERERROR
)
...
...
@@ -54,7 +53,7 @@ func (this *SkuService)GetSkuListByClass(req *model.QuerySkuCreq) (rsp *model.Qu
return
rsp
,
e
.
NewApiError
(
"service error"
,
open
.
REMOTESKUINFO
)
}
field
:=
[]
string
{
"goods_id"
,
"spu_id"
,
"brand_id"
,
"brand_name"
,
"goods_name"
,
"stock"
,
"moq"
,
"mpq"
,
"class_id1"
,
"class_id2"
,
"class_id1_name"
,
"class_id2_name"
,
"attrs"
,
"ladder_price"
,}
"class_id1"
,
"class_id2"
,
"class_id1_name"
,
"class_id2_name"
,
"attrs"
,
"ladder_price"
,
"supplier_name"
,
}
//field:=[]string{"spu_id","attrs","supplier_name","goods_images","hk_delivery_time"}
rsp
.
SkuData
=
model
.
SkuFilter
(
*
remoteData
,
field
)
...
...
@@ -72,12 +71,8 @@ func (this *SkuService) GetSkuListFull(req * model.QuerySkuReq)(rsp *model.Query
common
.
PrintStdout
()
.
Printf
(
err
.
Error
())
return
rsp
,
e
.
NewApiError
(
"service error"
,
open
.
REMOTESKUINFO
)
}
//"class_id1": 10014,
// "class_id2": 10031,
// "class_id1_name": "处理器及微控制器",
// "class_id2_name": "ADI(亚德诺)",
field
:=
[]
string
{
"goods_id"
,
"spu_id"
,
"brand_id"
,
"brand_name"
,
"goods_name"
,
"stock"
,
"moq"
,
"mpq"
,
"class_id1"
,
"class_id2"
,
"class_id1_name"
,
"class_id2_name"
,
"attrs"
,
"ladder_price"
,}
"class_id1"
,
"class_id2"
,
"class_id1_name"
,
"class_id2_name"
,
"attrs"
,
"ladder_price"
,
"supplier_name"
}
rsp
.
SkuData
=
model
.
SkuFilter
(
*
remoteData
,
field
)
return
}
...
...
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