Documentation
¶
Index ¶
- Variables
- func IsValidUUID(id string) bool
- func NewUUID() string
- type InMemory
- func (s *InMemory) Close() error
- func (s *InMemory) CreateRequest(sessionUUID, clientAddr, method, uri string, content []byte, ...) (string, error)
- func (s *InMemory) CreateSession(content []byte, code uint16, contentType string, delay time.Duration, ...) (string, error)
- func (s *InMemory) DeleteRequest(sessionUUID, requestUUID string) (bool, error)
- func (s *InMemory) DeleteRequests(uuid string) (bool, error)
- func (s *InMemory) DeleteSession(uuid string) (bool, error)
- func (s *InMemory) GetAllRequests(sessionUUID string) ([]Request, error)
- func (s *InMemory) GetRequest(sessionUUID, requestUUID string) (Request, error)
- func (s *InMemory) GetSession(uuid string) (Session, error)
- type Redis
- func (s *Redis) CreateRequest(sessionUUID, clientAddr, method, uri string, content []byte, ...) (string, error)
- func (s *Redis) CreateSession(content []byte, code uint16, contentType string, delay time.Duration, ...) (string, error)
- func (s *Redis) DeleteRequest(sessionUUID, requestUUID string) (bool, error)
- func (s *Redis) DeleteRequests(sessionUUID string) (bool, error)
- func (s *Redis) DeleteSession(uuid string) (bool, error)
- func (s *Redis) GetAllRequests(sessionUUID string) ([]Request, error)
- func (s *Redis) GetRequest(sessionUUID, requestUUID string) (Request, error)
- func (s *Redis) GetSession(uuid string) (Session, error)
- type Request
- type Session
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("closed")
Functions ¶
func IsValidUUID ¶
IsValidUUID checks if passed string is valid UUID v4.
Types ¶
type InMemory ¶
type InMemory struct {
// contains filtered or unexported fields
}
func NewInMemory ¶
NewInMemory creates inmemory storage.
func (*InMemory) CreateRequest ¶
func (s *InMemory) CreateRequest(sessionUUID, clientAddr, method, uri string, content []byte, headers map[string]string) (string, error)
CreateRequest creates new request in storage using passed data and updates expiration time for session and all stored requests for the session.
func (*InMemory) CreateSession ¶
func (s *InMemory) CreateSession(content []byte, code uint16, contentType string, delay time.Duration, sessionUUID ...string) (string, error)
CreateSession creates new session in storage using passed data.
func (*InMemory) DeleteRequest ¶
DeleteRequest deletes stored request with passed session and request UUIDs.
func (*InMemory) DeleteRequests ¶
DeleteRequests deletes stored requests for session with passed UUID.
func (*InMemory) DeleteSession ¶
DeleteSession deletes session with passed UUID.
func (*InMemory) GetAllRequests ¶
GetAllRequests returns all request as a slice of structures.
func (*InMemory) GetRequest ¶
GetRequest returns request data.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis is redis storage implementation.
func NewRedis ¶
func NewRedis(ctx context.Context, rdb *redis.Client, sessionTTL time.Duration, maxRequests uint16) *Redis
NewRedis creates new redis storage instance.
func (*Redis) CreateRequest ¶
func (s *Redis) CreateRequest(sessionUUID, clientAddr, method, uri string, content []byte, headers map[string]string) (string, error)
CreateRequest creates new request in storage using passed data and updates expiration time for session and all stored requests for the session.
func (*Redis) CreateSession ¶
func (s *Redis) CreateSession(content []byte, code uint16, contentType string, delay time.Duration, sessionUUID ...string) (string, error)
CreateSession creates new session in storage using passed data.
func (*Redis) DeleteRequest ¶
DeleteRequest deletes stored request with passed session and request UUIDs.
func (*Redis) DeleteRequests ¶
DeleteRequests deletes stored requests for session with passed UUID.
func (*Redis) DeleteSession ¶
DeleteSession deletes session with passed UUID.
func (*Redis) GetAllRequests ¶
GetAllRequests returns all request as a slice of structures.
func (*Redis) GetRequest ¶
GetRequest returns request data.
type Request ¶
type Request interface { UUID() string // UUID returns unique request identifier. ClientAddr() string // ClientAddr returns client hostname or IP address (who sent this request). Method() string // Method returns HTTP method name (eg.: 'GET', 'POST'). Content() []byte // Content returns request body (payload). Headers() map[string]string // Headers returns HTTP request headers. URI() string // URI returns Uniform Resource Identifier. CreatedAt() time.Time // CreatedAt returns creation time (accuracy to seconds). }
Request describes recorded request and additional meta-data.
type Session ¶
type Session interface { UUID() string // UUID returns unique session identifier. Content() []byte // Content returns session server response content. Code() uint16 // Code returns default server response code. ContentType() string // ContentType returns response content type. Delay() time.Duration // Delay returns delay before response sending. CreatedAt() time.Time // CreatedAt returns creation time (accuracy to seconds). }
Session describes session settings (like response data and any additional information).
type Storage ¶
type Storage interface { // GetSession returns session data. // If session was not found - `nil, nil` will be returned. GetSession(uuid string) (Session, error) // CreateSession creates new session in storage using passed data. // Session UUID without error will be returned on success. CreateSession(content []byte, code uint16, contentType string, delay time.Duration, id ...string) (string, error) // DeleteSession deletes session with passed UUID. DeleteSession(uuid string) (bool, error) // DeleteRequests deletes stored requests for session with passed UUID. DeleteRequests(uuid string) (bool, error) // CreateRequest creates new request in storage using passed data and updates expiration time for session and all // stored requests for the session. // Session with passed UUID must exist. // Request UUID without error will be returned on success. CreateRequest(sessionUUID, clientAddr, method, uri string, content []byte, headers map[string]string) (string, error) // GetRequest returns request data. // If request was not found - `nil, nil` will be returned. GetRequest(sessionUUID, requestUUID string) (Request, error) // GetAllRequests returns all request as a slice of structures. // If requests was not found - `nil, nil` will be returned. GetAllRequests(sessionUUID string) ([]Request, error) // DeleteRequest deletes stored request with passed session and request UUIDs. DeleteRequest(sessionUUID, requestUUID string) (bool, error) }
Storage is a Session's and Request's storage.