Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
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
63802148
authored
Nov 26, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
1320a5e2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
1 deletions
controller/sku_controller.go
doc/test/c2.go
doc/test/channal.go
controller/sku_controller.go
View file @
63802148
...
@@ -12,7 +12,7 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
...
@@ -12,7 +12,7 @@ const goods_slice_count = 10 //每多少个型号id开启一个协程
/*
/*
查询商品详情(自营或者联营)
查询商品详情(自营或者联营)
@doc http://192.168.
2.232
:3000/project/128/interface/api/649
@doc http://192.168.
1.237
:3000/project/128/interface/api/649
@param goods_id 支持批量,不建议超过40个,超过会导致处理时间超过2秒,进程异常 : 74564,65897,456464131
@param goods_id 支持批量,不建议超过40个,超过会导致处理时间超过2秒,进程异常 : 74564,65897,456464131
@param power[newCustomer] 是否获取新客价 :true
@param power[newCustomer] 是否获取新客价 :true
...
...
doc/test/c2.go
0 → 100644
View file @
63802148
/*
go通道选择 Select
go 的select关键字可以让你同时等待多个通道操作
将协程
通道和select结合起来构成了go的一个强大特性
*/
package
main
import
(
"fmt"
"github.com/syyongx/php2go"
"time"
)
func
main
()
{
c1
:=
make
(
chan
string
)
go
func
()
{
fmt
.
Println
(
php2go
.
Time
())
time
.
Sleep
(
time
.
Second
*
1
)
c1
<-
"one"
}()
go
func
()
{
fmt
.
Println
(
php2go
.
Time
())
time
.
Sleep
(
time
.
Second
*
2
)
c1
<-
"two"
}()
go
func
()
{
fmt
.
Println
(
php2go
.
Time
())
time
.
Sleep
(
time
.
Second
*
10
)
c1
<-
"10"
}()
/*
如我们所期望的 程序输出了正确的值 对于select语句而言
它不断地检测通道是否有值过来 一旦有值过来立刻获取输出
*/
//我们使用select来等待通道的值 然后输出
for
i
:=
0
;
i
<
3
;
i
++
{
select
{
case
x
:=
<-
c1
:
fmt
.
Println
(
x
)
case
<-
time
.
After
(
time
.
Second
*
2
)
:
fmt
.
Println
(
"read time out"
)
}
}
}
\ No newline at end of file
doc/test/channal.go
0 → 100644
View file @
63802148
package
main
import
(
"errors"
"fmt"
"time"
)
func
main
()
{
// 构建一个通道
ch
:=
make
(
chan
string
)
// 开启一个并发匿名函数
go
func
()
{
ch
<-
"gagagagagga111"
}()
go
func
()
{
ch
<-
"gagagagagga223"
}()
go
func
()
{
time
.
Sleep
(
1
*
time
.
Second
)
ch
<-
"gagagagagga44444"
}()
//无限循环从通道中读取数据
for
{
i
,
err
:=
ReadWithSelect
(
ch
)
//i, ok := <-ch
if
err
!=
nil
{
fmt
.
Println
(
err
)
break
}
fmt
.
Println
(
i
)
}
}
//使用Select+超时改善无阻塞读写
func
ReadWithSelect
(
ch
chan
string
)
(
x
string
,
err
error
)
{
timeout
:=
time
.
NewTimer
(
time
.
Microsecond
*
50000
)
.
C
//等待5s
select
{
case
x
=
<-
ch
:
return
x
,
nil
case
<-
timeout
.
C
:
return
""
,
errors
.
New
(
"read time out"
)
}
}
func
WriteChWithSelect
(
ch
chan
int
)
error
{
timeout
:=
time
.
NewTimer
(
time
.
Microsecond
*
500
)
select
{
case
ch
<-
1
:
return
nil
case
<-
timeout
.
C
:
return
errors
.
New
(
"write time out"
)
}
}
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