varsregex

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

Module vars_regex

{
    "name": "",
    "source": "",
    "pattern": "",
    "overwrite: false
}

Description


An HTTP middleware module that evaluates regular expressions using placeholders or given text.

The results are also expressed as placeholders for use elsewhere in your route.

Field List


name

A unique name for this expression that will be used to form the generated placeholder name(s)

source

A text string that is used as the evaluation source for the regex. Strings enclosed in braces {} will be expanded as placeholders (if placeholders with the given name exist)

pattern

The golang regular expression (as described here: https://golang.org/s/re2syntax)

overwrite

Is a boolean flag that defaults to true. If set it will overwrite placeholders values if they already exist.

Examples

route {

    # Expected results:
    #   {"http.vars_regex.url_element.capture_group1": "https://"}
    #   {"http.vars_regex.url_element.capture_group2": "github.com"}
    #   {"http.vars_regex.url_element.capture_group3": ":443"}
    #   {"http.vars_regex.url_element.match1": "https://github.com:443/amalto"}

    vars_regex {
        name url_element
        source "https://github.com:443/amalto"
  	    pattern "(https?:\/\/)([^:^\/]*)(:\d*[^\/])?(.*[^\/])?"
    }

    # Expected results:
    #   {"http.vars_regex.named_url_element.scheme": "https://"}
    #   {"http.vars_regex.named_url_element.host": "github.com"}
    #   {"http.vars_regex.named_url_element.port": ":443"}
    #   {"http.vars_regex.named_url_element.path": "/amalto"}
    #   {"http.vars_regex.named_url_element.match1": "https://github.com:443/amalto"}

    vars_regex {
        name named_url_element
        source "https://github.com:443/amalto"
  	    pattern "(?P<scheme>https?:\/\/)(?P<host>[^:^\/]*)(?P<port>:\d*[^\/])?(?P<path>.*[^\/])?"
    }

    # Expected results:
    #   {"http.vars_regex.word1.match1": "{one}"}
    #   {"http.vars_regex.word1.match2": "{two}"}
    #   {"http.vars_regex.word1.match3": "{three}"}

    vars_regex {
        name word1
        source "{one} {two} {three}"
        pattern "{[\w.-]+}"
    }

    # Expected results:
    #   {"http.vars_regex.word2.capture_group1": "one"}
    #   {"http.vars_regex.word2.match1": "{one}"}
    #   {"http.vars_regex.word2.match2": "{two}"}
    #   {"http.vars_regex.word2.match3": "{three}"}

    vars_regex {
        name word2
        source "{one} {two} {three}"
        pattern "{([\w.-]+)}"
    }

    # Expected results:
    #   {"http.vars_regex.aport.match1": "443"}
    #   {"http.vars_regex.aport.capture_group1": ""}

    vars_regex {
        name aport
        source {http.vars_regex.url_element.capture_group3}
        pattern "(\d*)?"
    }

    # Expected results:
    #   {"http.vars_regex.aport.match1": "443"}   <-- not changed as overwrite == false
    #   {"http.vars_regex.aport.capture_group1": ""}

    vars_regex {
        name aport
        source ":8443"
        pattern "(\d*)?"
        overwrite false
    }
  }
Build Instructions

The Makefile is used for all build operations. The file envfile is used for local environment customisations.

Please refer to https://caddyserver.com/docs/extending-caddy for details of configuring your environment and the use of xcaddy.


The current version of Caddy Server specified in the envfile is 2.3.0


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type VarsRegex

type VarsRegex struct {
	Name      string `json:"name,omitempty"`
	Source    string `json:"source,omitempty"`
	Pattern   string `json:"pattern,omitempty"`
	Overwrite bool   `json:"overwrite,omitempty"`
	// contains filtered or unexported fields
}

func (VarsRegex) CaddyModule

func (VarsRegex) CaddyModule() caddy.ModuleInfo

func (*VarsRegex) Provision

func (vrx *VarsRegex) Provision(ctx caddy.Context) error

func (VarsRegex) ServeHTTP

func (vrx VarsRegex) ServeHTTP(resp http.ResponseWriter, req *http.Request, next caddyhttp.Handler) error

Jump to

Keyboard shortcuts

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