maplocal

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapLocal

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

MapLocal holds rules for serving local files instead of upstream responses.

func New

func New() *MapLocal

New creates an empty MapLocal.

func (*MapLocal) AddRule

func (ml *MapLocal) AddRule(r Rule)

AddRule adds a mapping rule.

func (*MapLocal) LoadFromFile

func (ml *MapLocal) LoadFromFile(path string) error

LoadFromFile loads rules from a JSON file (array of Rule objects).

func (*MapLocal) Match

func (ml *MapLocal) Match(host, path string) ([]byte, int, bool)

Match checks if a host+path matches any rule. Returns body, status, and whether matched. Falls through (returns false) if the local file doesn't exist.

func (*MapLocal) RemoveRule

func (ml *MapLocal) RemoveRule(index int)

RemoveRule removes the rule at the given index.

func (*MapLocal) RuleCount

func (ml *MapLocal) RuleCount() int

RuleCount returns the number of active rules.

func (*MapLocal) Rules

func (ml *MapLocal) Rules() []Rule

Rules returns a copy of all rules.

func (*MapLocal) SaveToFile

func (ml *MapLocal) SaveToFile(path string) error

SaveToFile persists current rules to a JSON file.

type Rule

type Rule struct {
	Pattern    string            `json:"pattern"`
	LocalPath  string            `json:"local_path"`
	StatusCode int               `json:"status_code,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
}

Rule maps a URL pattern to a local file.

Jump to

Keyboard shortcuts

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