Skip to content

Commit

Permalink
IDubboContext
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzeyi committed Feb 9, 2023
1 parent 873f4b7 commit 0f13718
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 20 deletions.
9 changes: 9 additions & 0 deletions eocontext/dubbo-context/chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dubbo_context

import "github.com/eolinker/eosc/eocontext"

func Assert(ctx eocontext.EoContext) (IDubboContext, error) {
var dubboContext IDubboContext
err := ctx.Assert(&dubboContext)
return dubboContext, err
}
62 changes: 62 additions & 0 deletions eocontext/dubbo-context/context.go
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
package dubbo_context

import (
"github.com/eolinker/eosc/eocontext"
"time"
)

type IRequestReader interface {
Header() IHeaderReader
Service() IServiceReader
Body() interface{}
Attachments() map[string]interface{}
Attachment(string) (interface{}, bool)
}

type IServiceReader interface {
Path() string
Interface() string
Group() string
Version() string
Method() string //固定值:$invoke
Timeout() time.Duration //request timeout
}

type IHeaderReader interface {
ID() int64
SerialID() byte
// Type PackageType
Type() int
BodyLen() int
ResponseStatus() byte
}

type IDubboContext interface {
eocontext.EoContext
HeaderReader() IRequestReader // 读取原始请求
Proxy() IProxy // 读写转发请求
SendTo(address string, timeout time.Duration) error
}

type IProxy interface {
Header() IHeaderWriter
Service() IServiceWriter
SetBody(interface{})
}

type IServiceWriter interface {
IServiceReader
SetPath(string)
SetInterface(string)
SetGroup(string)
SetVersion(string)
SetMethod(string) //固定值:$invoke
SetTimeout(duration time.Duration) //request timeout
}

type IHeaderWriter interface {
IHeaderReader
SetID(int64)
SetSerialID(byte)
SetType(int)
SetBodyLen(int)
}
25 changes: 25 additions & 0 deletions eocontext/dubbo-context/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dubbo_context

import (
"github.com/eolinker/eosc/eocontext"
"github.com/eolinker/eosc/utils/config"
)

var (
FilterSkillName = config.TypeNameOf((*DubboFilter)(nil))
)

type DubboFilter interface {
DoDubboFilter(ctx IDubboContext, next eocontext.IChain) (err error)
}

func DoDubboFilter(httpFilter DubboFilter, ctx eocontext.EoContext, next eocontext.IChain) (err error) {
httpContext, err := Assert(ctx)
if err == nil {
return httpFilter.DoDubboFilter(httpContext, next)
}
if next != nil {
return next.DoChain(ctx)
}
return err
}
6 changes: 0 additions & 6 deletions eocontext/http-context/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ func WebsocketAssert(ctx eocontext.EoContext) (IWebsocketContext, error) {
err := ctx.Assert(&websocketContext)
return websocketContext, err
}

func DubboAssert(ctx eocontext.EoContext) (IDubboContext, error) {
var dubboContext IDubboContext
err := ctx.Assert(&dubboContext)
return dubboContext, err
}
14 changes: 0 additions & 14 deletions eocontext/http-context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ type IWebsocketContext interface {
IsWebsocket() bool
}

type IDubboContext interface {
IHttpContext
// MethodName 方法名
MethodName() string
// Interface 服务接口名 cn.org.api.UserService
Interface() string
// Serialization 序列化方式 hessian2、fastjson、gson、jdk、kryo、protobuf、avro
Serialization() string
// SetAttachment 类似http headers中的键值对,用于处理RPC请求和响应过程中需要但又不属于具体业务的信息
SetAttachment(key string, value interface{})
Attachments() map[string]interface{}
Attachment(string) (interface{}, bool)
}

type IHttpContext interface {
eocontext.EoContext
Request() IRequestReader // 读取原始请求
Expand Down

0 comments on commit 0f13718

Please sign in to comment.