Skip to content

Commit

Permalink
trifle: remove all examples from the source-code repo
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Jul 4, 2020
1 parent 1c2f4b0 commit a704e06
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 858 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ before_install:

install:
- go get -u golang.org/x/lint/golint
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.26.0
- curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b ~/bin

script:
Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
// Echo synchronously.
out = frame
Expand Down Expand Up @@ -336,6 +337,7 @@ func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
// Echo synchronously.
out = frame
Expand Down Expand Up @@ -390,6 +392,7 @@ func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
// Echo synchronously.
out = frame
Expand Down Expand Up @@ -452,8 +455,10 @@ type httpServer struct {
*gnet.EventServer
}

var errMsg = "Internal Server Error"
var errMsgBytes = []byte(errMsg)
var (
errMsg = "Internal Server Error"
errMsgBytes = []byte(errMsg)
)

type httpCodec struct {
req request
Expand Down Expand Up @@ -566,7 +571,7 @@ func parseReq(data []byte, req *request) (leftover []byte, err error) {
var i, s int
var head string
var clen int
var q = -1
q := -1
// method, path, proto line
for ; i < len(sdata); i++ {
if sdata[i] == ' ' {
Expand Down Expand Up @@ -655,16 +660,19 @@ func (ps *pushServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
"pushing data every %s ...\n", srv.Addr.String(), srv.Multicore, srv.NumEventLoop, ps.tick.String())
return
}

func (ps *pushServer) OnOpened(c gnet.Conn) (out []byte, action gnet.Action) {
log.Printf("Socket with addr: %s has been opened...\n", c.RemoteAddr().String())
ps.connectedSockets.Store(c.RemoteAddr().String(), c)
return
}

func (ps *pushServer) OnClosed(c gnet.Conn, err error) (action gnet.Action) {
log.Printf("Socket with addr: %s is closing...\n", c.RemoteAddr().String())
ps.connectedSockets.Delete(c.RemoteAddr().String())
return
}

func (ps *pushServer) Tick() (delay time.Duration, action gnet.Action) {
log.Println("It's time to push data to clients!!!")
ps.connectedSockets.Range(func(key, value interface{}) bool {
Expand All @@ -676,6 +684,7 @@ func (ps *pushServer) Tick() (delay time.Duration, action gnet.Action) {
delay = ps.tick
return
}

func (ps *pushServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
out = frame
return
Expand Down Expand Up @@ -917,7 +926,7 @@ func (cc *CustomLengthFieldProtocol) Decode(c gnet.Conn) ([]byte, error) {
return nil, errors.New("not normal protocol")
}
// parse payload
dataLen := int(dataLength) //max int32 can contain 210MB payload
dataLen := int(dataLength) // max int32 can contain 210MB payload
protocolLen := headerLen + dataLen
if dataSize, data := c.ReadN(protocolLen); dataSize == protocolLen {
c.ShiftN(protocolLen)
Expand All @@ -936,10 +945,10 @@ func (cc *CustomLengthFieldProtocol) Decode(c gnet.Conn) ([]byte, error) {
```

**Client/Server:**
[Check out the source code](https://github.com/panjf2000/gnet/tree/master/examples/custom_codec).
[Check out the source code](https://github.com/gnet-io/gnet-examples/tree/master/examples/custom_codec).
</details>

**For more details, check out here: [examples of gnet](https://github.com/panjf2000/gnet/tree/master/examples).**
**For more details, check out here: [all examples of gnet](https://github.com/gnet-io/gnet-examples/tree/master/examples).**

## I/O Events

Expand Down
21 changes: 15 additions & 6 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
// Echo synchronously.
out = frame
Expand Down Expand Up @@ -334,6 +335,7 @@ func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
// Echo synchronously.
out = frame
Expand Down Expand Up @@ -388,6 +390,7 @@ func (es *echoServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
srv.Addr.String(), srv.Multicore, srv.NumEventLoop)
return
}

func (es *echoServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
// Echo synchronously.
out = frame
Expand Down Expand Up @@ -450,8 +453,10 @@ type httpServer struct {
*gnet.EventServer
}

var errMsg = "Internal Server Error"
var errMsgBytes = []byte(errMsg)
var (
errMsg = "Internal Server Error"
errMsgBytes = []byte(errMsg)
)

type httpCodec struct {
req request
Expand Down Expand Up @@ -564,7 +569,7 @@ func parseReq(data []byte, req *request) (leftover []byte, err error) {
var i, s int
var head string
var clen int
var q = -1
q := -1
// method, path, proto line
for ; i < len(sdata); i++ {
if sdata[i] == ' ' {
Expand Down Expand Up @@ -653,16 +658,19 @@ func (ps *pushServer) OnInitComplete(srv gnet.Server) (action gnet.Action) {
"pushing data every %s ...\n", srv.Addr.String(), srv.Multicore, srv.NumEventLoop, ps.tick.String())
return
}

func (ps *pushServer) OnOpened(c gnet.Conn) (out []byte, action gnet.Action) {
log.Printf("Socket with addr: %s has been opened...\n", c.RemoteAddr().String())
ps.connectedSockets.Store(c.RemoteAddr().String(), c)
return
}

func (ps *pushServer) OnClosed(c gnet.Conn, err error) (action gnet.Action) {
log.Printf("Socket with addr: %s is closing...\n", c.RemoteAddr().String())
ps.connectedSockets.Delete(c.RemoteAddr().String())
return
}

func (ps *pushServer) Tick() (delay time.Duration, action gnet.Action) {
log.Println("It's time to push data to clients!!!")
ps.connectedSockets.Range(func(key, value interface{}) bool {
Expand All @@ -674,6 +682,7 @@ func (ps *pushServer) Tick() (delay time.Duration, action gnet.Action) {
delay = ps.tick
return
}

func (ps *pushServer) React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) {
out = frame
return
Expand Down Expand Up @@ -915,7 +924,7 @@ func (cc *CustomLengthFieldProtocol) Decode(c gnet.Conn) ([]byte, error) {
return nil, errors.New("not normal protocol")
}
// parse payload
dataLen := int(dataLength) //max int32 can contain 210MB payload
dataLen := int(dataLength) // max int32 can contain 210MB payload
protocolLen := headerLen + dataLen
if dataSize, data := c.ReadN(protocolLen); dataSize == protocolLen {
c.ShiftN(protocolLen)
Expand All @@ -931,10 +940,10 @@ func (cc *CustomLengthFieldProtocol) Decode(c gnet.Conn) ([]byte, error) {
```

**Client/Server:**
[Check out the source code](https://github.com/panjf2000/gnet/tree/master/examples/custom_codec).
[查看源码](https://github.com/gnet-io/gnet-examples/tree/master/examples/custom_codec).
</details>

**更详细的代码在这里: [gnet 示例](https://github.com/panjf2000/gnet/tree/master/examples)**
**更详细的代码在这里: [全部 gnet 示例](https://github.com/gnet-io/gnet-examples)**

## I/O 事件

Expand Down
55 changes: 0 additions & 55 deletions examples/codec/client/client.go

This file was deleted.

76 changes: 0 additions & 76 deletions examples/codec/server/server.go

This file was deleted.

Loading

0 comments on commit a704e06

Please sign in to comment.