forked from eolinker/eosc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangzeyi
committed
Feb 9, 2023
1 parent
873f4b7
commit 0f13718
Showing
5 changed files
with
96 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters