fastdev

package
v1.1.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package fastdev 流量录制和回放,名称源自 didi fastdev 项目。

Index

Constants

View Source
const (
	HTTP  = "http"
	REDIS = "redis"
	APCU  = "apcu"
)
View Source
const RecordSessionIDKey = "RECORD-SESSION-ID"

RecordSessionIDKey 流量录制模式下存储会话 ID 使用的 Key 。

View Source
const ReplaySessionIDKey = "REPLAY-SESSION-ID"

ReplaySessionIDKey 流量回放模式下存储会话 ID 使用的 Key 。

Variables

This section is empty.

Functions

func Delete

func Delete(sessionID string)

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

func GetReplaySessionID

func GetReplaySessionID(ctx context.Context) string

GetReplaySessionID 获取绑定在 context.Context 对象上的 Session ID 。

func NewSessionID

func NewSessionID() string

NewSessionID 使用 uuid 算法生成新的 Session ID 。

func RecordAction

func RecordAction(ctx context.Context, action *Action)

RecordAction 录制一个动作,会话 ID 从 Context 对象中获取。

func RecordMode

func RecordMode() bool

RecordMode 返回是否是录制模式。

func ReplayAction

func ReplayAction(ctx context.Context, action *Action) (bool, error)

ReplayAction 根据 action 传入的匹配信息返回对应的响应数据。

func ReplayMode

func ReplayMode() bool

ReplayMode 返回是否是回放模式。

func SetAgentConfig

func SetAgentConfig(config AgentConfig)

SetAgentConfig 设置回放代理的配置。

func SetRecordMode

func SetRecordMode(mode bool)

SetRecordMode 打开或者关闭录制模式。

func SetReplayMode

func SetReplayMode(mode bool, agent bool)

SetReplayMode 打开或者关闭回放模式。

func Store

func Store(session *Session)

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

Types

type Action

type Action struct {
	Protocol  string      `json:"protocol,omitempty"` // 协议名称
	Request   interface{} `json:"request,omitempty"`  // 请求内容
	Response  interface{} `json:"response,omitempty"` // 响应内容
	Timestamp int64       `json:"timestamp"`          // 时间戳
}

Action 将上下游调用、缓存获取、文件写入等抽象为一个动作。

type AgentConfig

type AgentConfig struct {
	Port    int
	DataDir string
}

AgentConfig 回放代理的配置。

type RawMessageSlice

type RawMessageSlice []json.RawMessage

func (RawMessageSlice) Len

func (p RawMessageSlice) Len() int

func (RawMessageSlice) Less

func (p RawMessageSlice) Less(i, j int) bool

func (RawMessageSlice) Swap

func (p RawMessageSlice) Swap(i, j int)

type Session

type Session struct {
	Session string    `json:"session,omitempty"` // 会话 ID
	Inbound *Action   `json:"inbound,omitempty"` // 上游数据
	Actions []*Action `json:"actions,omitempty"` // 动作数据
}

Session 一次上游调用称为一个会话。

func RecordInbound

func RecordInbound(ctx context.Context, inbound *Action) *Session

RecordInbound 录制上游流量,会话 ID 从 Context 对象中获取。

func ToSession

func ToSession(data []byte, sorted bool) (*Session, error)

ToSession 反序列化 *Session 对象,列表项会进行排序。

func (*Session) ToJson

func (s *Session) ToJson() string

Directories

Path Synopsis
Package json implements encoding and decoding of JSON as defined in RFC 7159.
Package json implements encoding and decoding of JSON as defined in RFC 7159.

Jump to

Keyboard shortcuts

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