httpclient

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateResponse

func ValidateResponse(actual, expected interface{}) error

ValidateResponse validates the response against expected values Returns nil if validation passes, error otherwise

func ValidateResponseEnhanced added in v0.7.0

func ValidateResponseEnhanced(actual, expected interface{}) error

ValidateResponseEnhanced provides enhanced validation with support for: - Range validation (min/max) - Pattern matching (regex) - Type checking - Approximate float comparison - Array validation - Object validation

Example YAML usage:

expected:
  # Simple value (backward compatible)
  status: "ok"

  # Range validation
  count:
    min: 1
    max: 10

  # Pattern validation
  user_id:
    pattern: "^user_\\d+$"

  # Type validation
  timestamp:
    type: "number"

  # Approximate float
  rate:
    approx: 0.75
    tolerance: 0.01

Types

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	RequestID  int
}

Client is a JSON-RPC 2.0 HTTP client

func NewClient

func NewClient(baseURL string, timeout time.Duration) *Client

NewClient creates a new JSON-RPC client

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, params interface{}) (*Response, error)

Call makes a JSON-RPC 2.0 call

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

Error represents a JSON-RPC 2.0 error

func (*Error) Error

func (e *Error) Error() string

type Request

type Request struct {
	JSONRPC string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
	ID      interface{} `json:"id"`
}

Request represents a JSON-RPC 2.0 request

type Response

type Response struct {
	JSONRPC string      `json:"jsonrpc"`
	Result  interface{} `json:"result,omitempty"`
	Error   *Error      `json:"error,omitempty"`
	ID      interface{} `json:"id"`
}

Response represents a JSON-RPC 2.0 response

type ValidatorConfig added in v0.7.0

type ValidatorConfig struct {
	// Range validation
	Min *float64 `json:"min,omitempty"`
	Max *float64 `json:"max,omitempty"`

	// Pattern validation (regex)
	Pattern *string `json:"pattern,omitempty"`

	// Type validation
	Type *string `json:"type,omitempty"`

	// Approximate float comparison
	Approx    *float64 `json:"approx,omitempty"`
	Tolerance *float64 `json:"tolerance,omitempty"`

	// Array validation
	Length    *int          `json:"length,omitempty"`
	MinLength *int          `json:"minLength,omitempty"`
	MaxLength *int          `json:"maxLength,omitempty"`
	Contains  []interface{} `json:"contains,omitempty"`

	// Object validation
	HasFields     []string `json:"hasFields,omitempty"`
	MissingFields []string `json:"missingFields,omitempty"`
}

ValidatorConfig represents extended validation configuration

Jump to

Keyboard shortcuts

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