userinput

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package userinput handles detection and processing of user input variables in HTTP request URLs using the {{:paramName}} syntax.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

type Detector struct{}

Detector detects {{:paramName}} patterns in URLs.

func NewDetector

func NewDetector() *Detector

NewDetector creates a new user input pattern detector.

func (*Detector) Detect

func (d *Detector) Detect(content string) []Pattern

Detect finds all {{:paramName}} patterns in content and returns first occurrences per name ordered by appearance. If any occurrence of a parameter is marked !secret, the result inherits it.

func (*Detector) ExtractPatternNames

func (d *Detector) ExtractPatternNames(url string) []string

ExtractPatternNames returns a list of unique parameter names from a URL.

func (*Detector) FindAll added in v0.2.18

func (d *Detector) FindAll(content string) []Pattern

FindAll returns every {{:paramName}} match in the given content in scanning order (including duplicates).

func (*Detector) GenerateKey

func (d *Detector) GenerateKey(urlStr string) string

GenerateKey creates a session storage key from a URL pattern (host + path + query). Use Detector.GenerateRequestKey to include additional context like HTTP method.

func (*Detector) GenerateRequestKey added in v0.2.20

func (d *Detector) GenerateRequestKey(method, urlStr string) string

GenerateRequestKey extends GenerateKey by prefixing the HTTP method when provided.

func (*Detector) HasPatterns

func (d *Detector) HasPatterns(content string) bool

HasPatterns checks if the content contains any user input patterns.

func (*Detector) Replace

func (d *Detector) Replace(content string, values map[string]string) string

Replace substitutes {{:paramName}} patterns with provided values. Values are URL-encoded for safe inclusion in URLs and match both secret/non-secret variants.

func (*Detector) ReplaceRaw

func (d *Detector) ReplaceRaw(content string, values map[string]string) string

ReplaceRaw substitutes {{:paramName}} patterns with provided values without URL encoding.

type Pattern

type Pattern struct {
	Name     string // Canonical parameter name (e.g., "id")
	Original string // Original matched pattern (e.g., "{{:id!secret}}")
	Position int    // Position in content
	IsSecret bool   // Whether the pattern uses the !secret suffix
}

Pattern represents a detected user input pattern in a URL.

type ProcessResult

type ProcessResult struct {
	URL      string            // The processed URL with patterns replaced
	Values   map[string]string // The values used for replacement (in order of appearance)
	Patterns []Pattern         // The patterns that were found (preserves order)
	Prompted bool              // Whether the user was prompted for values
	Secrets  map[string]bool   // Which parameters are marked as secrets
}

ProcessResult contains the result of processing user input patterns.

type Prompter

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

Prompter handles prompting users for input values. Values are collected during a single request execution and not persisted.

func NewPrompter

func NewPrompter(_ interface{}, forcePrompt bool, useColors bool) *Prompter

NewPrompter creates a new prompter. The forcePrompt parameter is kept for API compatibility but is ignored since prompts always happen now (no session persistence).

func (*Prompter) GenerateKey

func (p *Prompter) GenerateKey(url string) string

GenerateKey creates a session storage key from a URL pattern. This method is kept for API compatibility but the key is not used for persistence.

func (*Prompter) HasPatterns

func (p *Prompter) HasPatterns(url string) bool

HasPatterns checks if the URL contains any user input patterns.

func (*Prompter) ProcessContent

func (p *Prompter) ProcessContent(content string, urlKey string) (string, error)

ProcessContent processes user input patterns in any content string. This can be used for headers, body, or other content. The urlKey parameter is kept for API compatibility but is ignored.

func (*Prompter) ProcessURL

func (p *Prompter) ProcessURL(url string) (*ProcessResult, error)

ProcessURL detects patterns, prompts if needed, and returns processed URL. Returns a ProcessResult containing the URL with all {{:paramName}} patterns replaced, the values used, and whether the user was prompted. If the user cancels the prompt, returns an error.

func (*Prompter) SetSecrets added in v0.2.20

func (p *Prompter) SetSecrets(secrets map[string]bool)

SetSecrets marks specific parameters as secrets.

func (*Prompter) SetValues added in v0.2.20

func (p *Prompter) SetValues(values map[string]string)

SetValues allows pre-setting values (useful for testing or programmatic use).

Jump to

Keyboard shortcuts

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