recorder

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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CACHE = "CACHE"
	HTTP  = "HTTP"
	SQL   = "SQL"
	REDIS = "REDIS"
)

Variables

This section is empty.

Functions

func DecodeCSV

func DecodeCSV(data string) ([]string, error)

DecodeCSV 将 CSV 格式的数据转换为字符串数组。

func DecodeTTY

func DecodeTTY(data string) ([]string, error)

DecodeTTY 将命令行格式的数据转换为字符串数组。

func EncodeCSV

func EncodeCSV(data ...interface{}) string

EncodeCSV 将数据转换为 CSV 格式,可用于 redis 结果格式化。

func EncodeTTY

func EncodeTTY(data ...interface{}) string

EncodeTTY 将数据转换为命令行格式,可用于 redis 参数格式化。

func FlatJSON

func FlatJSON(data interface{}) map[string]string

func Init

func Init()

Init 模块初始化,由于日志组件导致当前模块需要延迟初始化。

func RecordAction

func RecordAction(ctx context.Context, protocol string, action *SimpleAction)

RecordAction 录制 outbound 流量。

func RecordInbound

func RecordInbound(ctx context.Context, protocol string, inbound *SimpleAction)

RecordInbound 录制 inbound 流量。

func RecordMode

func RecordMode() bool

RecordMode 返回是否是录制模式。

func RegisterProtocol

func RegisterProtocol(name string, protocol Protocol)

func SetRecordMode

func SetRecordMode(mode bool)

SetRecordMode 打开或者关闭录制模式,仅用于单元测试。

func StartRecord

func StartRecord(ctx context.Context, fn func() (string, error))

StartRecord 开始流量录制

func ToJson

func ToJson(v interface{}) string

func ToJsonE

func ToJsonE(v interface{}) ([]byte, error)

func ToJsonValue

func ToJsonValue(v reflect.Value) string

func ToPrettyJson

func ToPrettyJson(v interface{}) string

func ToPrettyJsonE

func ToPrettyJsonE(v interface{}) ([]byte, error)

Types

type Action

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

type HttpTransport

type HttpTransport struct {
	Transport http.RoundTripper
}

func (*HttpTransport) RoundTrip

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

type Message

type Message func() string

func (Message) Data

func (f Message) Data() string

func (Message) MarshalJSON

func (f Message) MarshalJSON() ([]byte, error)

type Protocol

type Protocol interface {
	GetLabel(data string) string
	FlatRequest(data string) (map[string]string, error)
	FlatResponse(data string) (map[string]string, error)
}

func GetProtocol

func GetProtocol(name string) Protocol

type RawAction

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

type RawSession

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

func ToRawSession

func ToRawSession(data string) (*RawSession, error)

type Recorder

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

type Session

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

func StopRecord

func StopRecord(ctx context.Context) *Session

StopRecord 停止流量录制

type SimpleAction

type SimpleAction struct {
	Protocol  string        `json:",omitempty"` // 协议名称
	Timestamp int64         `json:",omitempty"` // 时间戳
	Request   func() string `json:",omitempty"` // 请求内容
	Response  func() string `json:",omitempty"` // 响应内容
}

Jump to

Keyboard shortcuts

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