Skip to content

Commit

Permalink
feat(codec): support struct codec (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjunbiao authored Jul 10, 2020
1 parent f4a350d commit f63a3c0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/yomorun/yomo
go 1.14

require (
github.com/10cella/yomo-json-codec v0.1.0
github.com/10cella/yomo-json-codec v0.2.0
github.com/lucas-clemente/quic-go v0.17.1
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/10cella/yomo-json-codec v0.0.2 h1:1GZjMGJGr8V9j009sNZKwQaZlXTjiMqZCr2
github.com/10cella/yomo-json-codec v0.0.2/go.mod h1:9rwfqlpW8iZ9Ki5/frJsO2fBSl9x24QB16jloj7YPCc=
github.com/10cella/yomo-json-codec v0.1.0 h1:EE33np1AP3y67sbgZqWH4IroPtJubWQCoGzr39TEAuM=
github.com/10cella/yomo-json-codec v0.1.0/go.mod h1:9rwfqlpW8iZ9Ki5/frJsO2fBSl9x24QB16jloj7YPCc=
github.com/10cella/yomo-json-codec v0.2.0 h1:VCFrpoVeYX6AnVQcYaIKcPbMKNERx/ZKno7Ejuiudrc=
github.com/10cella/yomo-json-codec v0.2.0/go.mod h1:oApqc2PnZohrtlVJ3T1Knou9Ap9mcCJW1i3xiRtvF7c=
github.com/10cella/yomo-txtkv-codec v1.0.5 h1:rVdtBcsff3RG3BEq7AHq2WvNiGDF6IEKlTiplypfX+c=
github.com/10cella/yomo-txtkv-codec v1.0.5/go.mod h1:nBfcD3qVq6kkSRHOgSUxK1+gMRoXI0obLF+b1eiyCtM=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand Down Expand Up @@ -78,6 +80,8 @@ github.com/marten-seemann/qtls v0.9.1 h1:O0YKQxNVPaiFgMng0suWEOY2Sb4LT2sRn9Qimq3
github.com/marten-seemann/qtls v0.9.1/go.mod h1:T1MmAdDPyISzxlK6kjRr0pcZFBVd1OZbBb/j3cvzHhk=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/mitchellh/mapstructure v1.3.2 h1:mRS76wmkOn3KkKAyXDu42V+6ebnXWIztFSYGN7GeoRg=
github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin
type YomoObjectPlugin interface {
Handle(value interface{}) (interface{}, error)
Observed() string
Mold() interface{}
Name() string
}

Expand Down
24 changes: 20 additions & 4 deletions pkg/util/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io"
"log"
"math/big"
"net"
"time"
Expand All @@ -38,16 +38,32 @@ func (w YomoFrameworkStreamWriter) Write(b []byte) (int, error) {
w.Codec.Decoder(b)

for {
value, err = w.Codec.Read()
value, err = w.Codec.Read(w.Plugin.Mold())
if err != nil {
break
}

if len(value.(string)) > 0 {
if value != nil {
result, err = w.Plugin.Handle(value)
w.Codec.Write(w.Writer, fmt.Sprint(result)) // nolint
if err != nil {
log.Fatal(err)
}
//fmt.Println("handle result:", result)
w.Codec.Write(w.Writer, result, w.Plugin.Mold()) // nolint
break
}

//if len(value.(string)) > 0 {
// result, err = w.Plugin.Handle(value)
// if err != nil {
// log.Fatal(err)
// }
// if result == nil {
// result = ""
// }
// w.Codec.Write(w.Writer, fmt.Sprint(result)) // nolint
// break
//}
}
return len(b), err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/yomo/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func RunDev(plugin plugin.YomoObjectPlugin, endpoint string) {
}()

yomoEchoClient, err := util.QuicClient("161.189.140.133:11520")
//yomoEchoClient, err := util.QuicClient("localhost:11520")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit f63a3c0

Please sign in to comment.