This commit is contained in:
crusader 2017-10-26 21:37:28 +09:00
parent 0c7808f8e3
commit 168c78690c
5 changed files with 66 additions and 5 deletions

View File

@ -16,7 +16,7 @@ type FastHTTPAdapter struct {
// FastHTTPHandler
func (a *FastHTTPAdapter) FastHTTPHandler(ctx *fasthttp.RequestCtx) {
if !ctx.IsPost() {
WriteError(ctx, 405, "rpc: POST method required, received "+r.Method)
writeError(ctx, 405, "rpc: POST method required, received "+string(ctx.Method()))
return
}
@ -26,11 +26,11 @@ func (a *FastHTTPAdapter) FastHTTPHandler(ctx *fasthttp.RequestCtx) {
contentType = contentType[:idx]
}
err := a.registry.Invoke(contentType, ctx.PostBody(), ctx, beforeWrite, afterWrite)
// err := a.registry.Invoke(contentType, ctx.Request., ctx, beforeWrite, afterWrite)
if nil != err {
WriteError(w, 400, err.Error())
}
// if nil != err {
// writeError(ctx, 400, err.Error())
// }
}

13
adapter/ipc/adapter.go Normal file
View File

@ -0,0 +1,13 @@
package ipc
import "git.loafle.net/commons_go/rpc"
type IPCAdapter struct {
registry rpc.Registry
}
func NewAdapter(registry rpc.Registry) *IPCAdapter {
return &IPCAdapter{
registry: registry,
}
}

14
adapter/ipc/ipc.go Normal file
View File

@ -0,0 +1,14 @@
package ipc
import (
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/server"
)
func NewServer(addr string, registry rpc.Registry) server.Server {
sh := NewServerHandler(addr)
s := server.NewServer(sh)
return s
}

View File

@ -0,0 +1,32 @@
package ipc
import (
"io"
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/server"
"git.loafle.net/commons_go/server/ipc"
)
func NewServerHandler(addr string, registry rpc.Registry) ServerHandler {
sh := &ServerHandlers{
registry: registry,
}
sh.Addr = addr
return sh
}
type ServerHandler interface {
server.ServerHandler
}
type ServerHandlers struct {
ipc.ServerHandlers
registry rpc.Registry
}
func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) {
}

View File

@ -2,3 +2,5 @@ package: git.loafle.net/commons_go/rpc
import:
- package: github.com/valyala/fasthttp
version: v20160617
- package: git.loafle.net/commons_go/server
- package: gopkg.in/natefinch/npipe.v2