replayer

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExactMatch = MatchStrategy(0) // 精确匹配
	BestMatch  = MatchStrategy(1) // 最佳匹配
)

Variables

This section is empty.

Functions

func BestQuery

func BestQuery(ctx context.Context, protocol, request string) (response string, ok bool, err error)

func GetSessionID

func GetSessionID(ctx context.Context) (string, error)

func Query

func Query(ctx context.Context, protocol, request string) (response string, ok bool, err error)

func ReplayMode

func ReplayMode() bool

ReplayMode 返回是否是回放模式。

func SetReplayAgent

func SetReplayAgent(agent Agent)

SetReplayAgent 设置本地还是远程回放。

func SetReplayMode

func SetReplayMode(enable bool)

SetReplayMode 打开或者关闭回放模式,仅用于单元测试。

func SetSessionID

func SetSessionID(ctx context.Context, sessionID string) error

Types

type Action

type Action struct {
	Protocol        string            `json:",omitempty"` // 协议名称
	Timestamp       int64             `json:",omitempty"` // 时间戳
	Request         string            `json:",omitempty"` // 请求内容
	Response        string            `json:",omitempty"` // 响应内容
	FlatRequest     map[string]string `json:",omitempty"`
	FlatResponse    map[string]string `json:",omitempty"`
	RecTimestamp    int64             `json:",omitempty"` // 时间戳
	RecRequest      string            `json:",omitempty"` // 请求内容
	RecResponse     string            `json:",omitempty"` // 响应内容
	RecFlatRequest  map[string]string `json:",omitempty"`
	RecFlatResponse map[string]string `json:",omitempty"`
}

func ToAction

func ToAction(action *recorder.RawAction) *Action

func (*Action) Flat

func (action *Action) Flat() error

func (*Action) Pretty

func (action *Action) Pretty() (string, error)

func (*Action) String

func (action *Action) String() (string, error)

type Agent

type Agent interface {
	QueryAction(ctx context.Context, protocol, request string, matchStrategy MatchStrategy) (response string, ok bool, err error)
}

type HttpTransport

type HttpTransport struct {
	Transport http.RoundTripper
}

func (*HttpTransport) RoundTrip

func (t *HttpTransport) RoundTrip(req *http.Request) (*http.Response, error)

type LocalAgent

type LocalAgent struct {
	// contains filtered or unexported fields
}

func NewLocalAgent

func NewLocalAgent() *LocalAgent

func (*LocalAgent) Delete

func (agent *LocalAgent) Delete(sessionID string) error

Delete 删除 sessionID 对应的回放数据。

func (*LocalAgent) QueryAction

func (agent *LocalAgent) QueryAction(ctx context.Context, protocol, request string, matchStrategy MatchStrategy) (response string, ok bool, err error)

func (*LocalAgent) Store

func (agent *LocalAgent) Store(str string) (*Session, error)

Store 存储 sessionID 对应的回放数据。

type MatchStrategy

type MatchStrategy int

type RemoteAgent

type RemoteAgent struct {
}

func (*RemoteAgent) QueryAction

func (agent *RemoteAgent) QueryAction(ctx context.Context, protocol, request string, matchStrategy MatchStrategy) (response string, ok bool, err error)

type Session

type Session struct {
	Session   string    `json:",omitempty"` // 会话 ID
	Timestamp int64     `json:",omitempty"` // 时间戳
	Inbound   *Action   `json:",omitempty"` // 上游数据
	Actions   []*Action `json:",omitempty"` // 动作数据
}

func ToSession

func ToSession(session *recorder.RawSession) (*Session, error)

func (*Session) Flat

func (session *Session) Flat() error

func (*Session) Pretty

func (session *Session) Pretty() (string, error)

func (*Session) String

func (session *Session) String() (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL