Skip to content

Commit

Permalink
feat(codec): using json codec (#16)
Browse files Browse the repository at this point in the history
* feat(codec): using json codec

* fix(quic): fix for hg-29
  • Loading branch information
chenjunbiao authored Jul 10, 2020
1 parent eb3a12e commit 44b86aa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions 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-txtkv-codec v1.0.6
github.com/10cella/yomo-json-codec v0.1.0
github.com/lucas-clemente/quic-go v0.17.1
)
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBr
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
github.com/10cella/yomo-json-codec v0.0.2 h1:1GZjMGJGr8V9j009sNZKwQaZlXTjiMqZCr2GMFaaR5o=
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-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 All @@ -18,6 +22,7 @@ github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitf
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down Expand Up @@ -115,7 +120,9 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYED
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
Expand Down Expand Up @@ -203,6 +210,7 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/server.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package framework

import (
txtkv "github.com/10cella/yomo-txtkv-codec"
json "github.com/10cella/yomo-json-codec"
"github.com/yomorun/yomo/pkg/plugin"
"github.com/yomorun/yomo/pkg/util"
)

func NewServer(endpoint string, p plugin.YomoObjectPlugin) {
codec := txtkv.NewCodec(p.Observed())
codec := json.NewCodec(p.Observed())
util.QuicServer(endpoint, p, codec)
}
13 changes: 8 additions & 5 deletions pkg/util/quic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io"
"math/big"
"net"
"time"

txtkv "github.com/10cella/yomo-txtkv-codec"
json "github.com/10cella/yomo-json-codec"
"github.com/lucas-clemente/quic-go"
quicGo "github.com/lucas-clemente/quic-go"
"github.com/yomorun/yomo/pkg/plugin"
Expand All @@ -24,7 +25,7 @@ import (
// YomoFrameworkStreamWriter is the stream of framework
type YomoFrameworkStreamWriter struct {
Name string
Codec *txtkv.Codec
Codec *json.Codec
Plugin plugin.YomoObjectPlugin
io.Writer
}
Expand All @@ -44,7 +45,7 @@ func (w YomoFrameworkStreamWriter) Write(b []byte) (int, error) {

if len(value.(string)) > 0 {
result, err = w.Plugin.Handle(value)
w.Codec.Write(w.Writer, result.(string))
w.Codec.Write(w.Writer, fmt.Sprint(result)) // nolint
break
}
}
Expand All @@ -55,7 +56,8 @@ func (w YomoFrameworkStreamWriter) Write(b []byte) (int, error) {
func QuicClient(endpoint string) (quicGo.Stream, error) {
tlsConf := &tls.Config{
InsecureSkipVerify: true, // nolint
NextProtos: []string{"http/1.1"},
NextProtos: []string{"hq-29"},
//NextProtos: []string{"http/1.1"},
}

session, err := quicGo.DialAddr(endpoint, tlsConf, &quic.Config{
Expand All @@ -76,12 +78,13 @@ func QuicClient(endpoint string) (quicGo.Stream, error) {
}

// QuicServer create a QUIC server
func QuicServer(endpoint string, plugin plugin.YomoObjectPlugin, codec *txtkv.Codec) {
func QuicServer(endpoint string, plugin plugin.YomoObjectPlugin, codec *json.Codec) {
// Lock to use QUIC draft-29 version
conf := &quic.Config{
Versions: []quicGo.VersionNumber{0xff00001d},
}
listener, err := quicGo.ListenAddr(endpoint, GenerateTLSConfig(endpoint), conf)

if err != nil {
panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/yomo/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func RunDev(plugin plugin.YomoObjectPlugin, endpoint string) {
framework.NewServer(endpoint, plugin)
}()

yomoEchoClient, err := util.QuicClient("echo.cella.fun:11521")
//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 44b86aa

Please sign in to comment.