proxy

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransactionInterceptor

func TransactionInterceptor(storage Storage) func(APITransaction)

TransactionInterceptor creates a function to intercept and store API transactions

Types

type APIInterceptor

type APIInterceptor func(APITransaction)

APIInterceptor is a function that processes API transactions

type APITransaction

type APITransaction struct {
	Request  RequestData
	Response ResponseData
}

APITransaction represents a complete API transaction (request + response)

type FileStorage

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

FileStorage stores API transactions as JSON files

func NewFileStorage

func NewFileStorage(baseDir string) (*FileStorage, error)

NewFileStorage creates a new file storage

func (*FileStorage) Clear

func (s *FileStorage) Clear() error

Clear removes all stored API transactions

func (*FileStorage) GetAll

func (s *FileStorage) GetAll() ([]APITransaction, error)

GetAll returns all stored API transactions

func (*FileStorage) Store

func (s *FileStorage) Store(transaction APITransaction) error

Store saves an API transaction to storage

type ProxyServer

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

ProxyServer is an HTTP proxy server that captures API traffic

func NewProxyServer

func NewProxyServer(port int, target string, interceptor APIInterceptor) (*ProxyServer, error)

NewProxyServer creates a new proxy server

func (*ProxyServer) Start

func (p *ProxyServer) Start() error

Start starts the proxy server

type RequestData

type RequestData struct {
	Method      string
	Path        string
	QueryParams url.Values
	Headers     http.Header
	Body        []byte
	Timestamp   time.Time
}

RequestData stores information about an HTTP request

type ResponseData

type ResponseData struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	Timestamp  time.Time
}

ResponseData stores information about an HTTP response

type Storage

type Storage interface {
	Store(transaction APITransaction) error
	GetAll() ([]APITransaction, error)
	Clear() error
}

Storage interface for storing API transactions

Jump to

Keyboard shortcuts

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