Compare commits

...

18 Commits

Author SHA1 Message Date
Sodesnei e1dc747e78 Upload $M[U103]PF3L0]$W6B`8)2P.png by picGo - 2021-09-20 05:06:41 2021-09-20 09:06:40 +00:00
Sodesnei b62fade750 Deleted PV4EFFJW%RN(3M[JKE{@})9.png by PicGo - 2021-09-20 05:06:09 2021-09-20 09:06:08 +00:00
Sodesnei 8717b8d28f Upload PV4EFFJW%RN(3M[JKE{@})9.png by picGo - 2021-09-20 05:05:54 2021-09-20 09:05:52 +00:00
Sodesnei c20c5f3357 Deleted VI8LW~2L)Y[P}O_ZF(5_HNY.png by PicGo - 2021-09-20 05:04:32 2021-09-20 09:04:30 +00:00
Sodesnei cf705aaf6b Upload VI8LW~2L)Y[P}O_ZF(5_HNY.png by picGo - 2021-09-20 04:56:31 2021-09-20 08:56:30 +00:00
Sodesnei f68167f620 Deleted DSC_0237.JPG by PicGo - 2021-09-20 04:54:44 2021-09-20 08:54:42 +00:00
Sodesnei ce516d1b18 Upload 9326E4C59440D362045C8AA7AF1B5981.gif by picGo - 2021-09-20 04:54:36 2021-09-20 08:54:35 +00:00
Sodesnei 6650479282 Upload DSC_0237.JPG by picGo - 2021-09-20 04:52:35 2021-09-20 08:52:40 +00:00
Sodesnei b2b5eaba87 Deleted }M`]5~%@BOA67QG3YZ_F)BJ.png by PicGo - 2021-09-20 04:52:31 2021-09-20 08:52:29 +00:00
Sodesnei 7aada5be21 Deleted DSC_0258.JPG by PicGo - 2021-09-20 04:52:30 2021-09-20 08:52:29 +00:00
Sodesnei 32c679615c Upload }M`]5~%@BOA67QG3YZ_F)BJ.png by picGo - 2021-09-20 04:51:59 2021-09-20 08:51:58 +00:00
Sodesnei 675854207e Upload DSC_0258.JPG by picGo - 2021-09-20 04:47:56 2021-09-20 08:48:02 +00:00
Sodesnei 71381ad1a8 middle 2021-09-19 18:29:45 +08:00
Sodesnei d3c3c2bfe1 Merge branch 'cache-middle-zlj' 2021-09-19 18:11:43 +08:00
Sodesnei e742267b68 middle 2021-09-19 14:59:27 +08:00
86150 2c6bd99ccc 中间件 2021-08-30 14:46:31 +08:00
86150 8b676d1ad2 中间件 2021-08-22 15:31:53 +08:00
86150 f8f653c6f9 test 2021-08-22 15:00:32 +08:00
10 changed files with 167 additions and 1 deletions

BIN
$M[U103]PF3L0]$W6B`8)2P.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

1
go.mod
View File

@ -5,4 +5,5 @@ go 1.16
require ( require (
github.com/spf13/cobra v1.2.1 github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1 github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0
) )

24
pkg/middle/data.go Normal file
View File

@ -0,0 +1,24 @@
package middle
// 数据类型
type data struct {
m map[string]interface{}
}
// 数据初始化,分配内存
func NewData() *data {
return &data{
make(map[string]interface{}),
}
}
// 获取数据
func (d *data) Get(key string) interface{} {
return d.m[key]
}
// 推入数据
func (d *data) Put(key string, val interface{}) error {
d.m[key] = val
return nil
}

View File

@ -1 +0,0 @@
package define

62
pkg/middle/middle.go Normal file
View File

@ -0,0 +1,62 @@
package middle
// 获取数据的接口
type Msg interface {
Put(key string, val interface{}) error
Get(key string) interface{}
}
type middleWare interface {
Put(msg Msg)
Out() Msg
}
type MiddlewareConf struct {
Weight int
Middle middleWare
}
type Driver struct {
conf []*MiddlewareConf
}
func NewDriver() *Driver {
return new(Driver)
}
// 驱动
func (d *Driver) Start(msg Msg) {
for _, m := range d.conf {
go m.Middle.Put(msg)
msg = m.Middle.Out()
}
}
func main() {
conf := []*MiddlewareConf{
{
Weight: 1,
Middle: NewUpload(),
},
{
Weight: 2,
Middle: NewStorage(),
},
{
Weight: 3,
Middle: NewSend(),
},
}
da := NewDriver()
da.conf = conf
val := NewData()
val.Put("200", 2)
da.Start(val)
}

View File

@ -0,0 +1,7 @@
package middle
import "testing"
func TestMiddle(t *testing.T) {
main()
}

24
pkg/middle/send.go Normal file
View File

@ -0,0 +1,24 @@
package middle
import "fmt"
type Send struct {
ch chan *data
}
func NewSend() *Send {
return &Send{
make(chan *data),
}
}
func (m *Send) Put(msg Msg) {
da := NewData()
da.Put("1", msg)
fmt.Println("传入Send")
m.ch <- da
}
func (m *Send) Out() Msg {
return <-m.ch
}

24
pkg/middle/storage.go Normal file
View File

@ -0,0 +1,24 @@
package middle
import "fmt"
type Storage struct {
ch chan *data
}
func NewStorage() *Storage {
return &Storage{
make(chan *data),
}
}
func (m *Storage) Put(msg Msg) {
da := NewData()
da.Put("1", msg)
fmt.Println("传入Storage")
m.ch <- da
}
func (m *Storage) Out() Msg {
return <-m.ch
}

25
pkg/middle/upload.go Normal file
View File

@ -0,0 +1,25 @@
package middle
import "fmt"
type Upload struct {
ch chan *data
}
func NewUpload() *Upload {
return &Upload{
make(chan *data),
}
}
func (m *Upload) Put(msg Msg) {
da := NewData()
da.Put("1", msg)
fmt.Println("传入Upload")
m.ch <- da
}
func (m *Upload) Out() Msg {
return <-m.ch
}