userinput

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: MIT Imports: 6 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(url string) []Pattern

Detect finds all {{:paramName}} patterns in a URL. Returns patterns in order of appearance, with duplicates removed. If the same parameter name appears multiple times, only the first occurrence is returned.

func (*Detector) ExtractPatternNames

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

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

func (*Detector) GenerateKey

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

GenerateKey creates a session storage key from a URL pattern. The key is created by normalizing the URL to include only the path and user input patterns, allowing different requests with the same pattern structure to share stored values.

func (*Detector) HasPatterns

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

HasPatterns checks if the URL contains any user input patterns.

func (*Detector) Replace

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

Replace substitutes {{:paramName}} patterns with provided values. Values are URL-encoded for safe inclusion in URLs. All occurrences of a parameter are replaced, even if it appears multiple times.

func (*Detector) ReplaceRaw

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

ReplaceRaw substitutes {{:paramName}} patterns with provided values without URL encoding. This is useful when the value is already encoded or when encoding is not desired.

type Pattern

type Pattern struct {
	Name     string // Parameter name (e.g., "id")
	Original string // Original pattern (e.g., "{{:id}}")
	Position int    // Position in URL
}

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
}

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 with session integration.

func NewPrompter

func NewPrompter(session *session.SessionManager, forcePrompt bool, useColors bool) *Prompter

NewPrompter creates a new prompter with session integration. If forcePrompt is true, the user will always be prompted even if values exist in session.

func (*Prompter) GenerateKey

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

GenerateKey creates a session storage key from a URL pattern.

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.

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.

Jump to

Keyboard shortcuts

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