reg_uri

package
v0.0.0-...-ae88a46 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package reg_uri

@author: xwc1125

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DomainMatch

func DomainMatch(d1 string, d2 string) bool

func GlobMatch

func GlobMatch(key1 string, key2 string) (bool, error)

GlobMatch determines whether key1 matches the pattern of key2 using glob pattern

func GlobMatchFunc

func GlobMatchFunc(args ...interface{}) (interface{}, error)

GlobMatchFunc is the wrapper for GlobMatch.

func IPMatch

func IPMatch(ip1 string, ip2 string) bool

IPMatch determines whether IP address ip1 matches the pattern of IP address ip2, ip2 can be an IP address or a CIDR pattern. For example, "192.168.2.123" matches "192.168.2.0/24"

func IPMatchFunc

func IPMatchFunc(args ...interface{}) (interface{}, error)

IPMatchFunc is the wrapper for IPMatch.

func KeyGet

func KeyGet(key1, key2 string) string

KeyGet returns the matched part For example, "/foo/bar/foo" matches "/foo/*" "bar/foo" will been returned

func KeyGet2

func KeyGet2(key1, key2 string, pathVar string) string

KeyGet2 returns value matched pattern For example, "/resource1" matches "/:resource" if the pathVar == "resource", then "resource1" will be returned

func KeyGet2Func

func KeyGet2Func(args ...interface{}) (interface{}, error)

KeyGet2Func is the wrapper for KeyGet2

func KeyGet3

func KeyGet3(key1, key2 string, pathVar string) string

KeyGet3 returns value matched pattern For example, "project/proj_project1_admin/" matches "project/proj_{project}_admin/" if the pathVar == "project", then "project1" will be returned

func KeyGet3Func

func KeyGet3Func(args ...interface{}) (interface{}, error)

KeyGet3Func is the wrapper for KeyGet3

func KeyGetFunc

func KeyGetFunc(args ...interface{}) (interface{}, error)

KeyGetFunc is the wrapper for KeyGet

func KeyMatch

func KeyMatch(key1 string, key2 string) bool

KeyMatch determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. For example, "/foo/bar" matches "/foo/*"

func KeyMatch2

func KeyMatch2(key1 string, key2 string) bool

KeyMatch2 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. For example, "/foo/bar" matches "/foo/*", "/resource1" matches "/:resource"

func KeyMatch2Func

func KeyMatch2Func(args ...interface{}) (interface{}, error)

KeyMatch2Func is the wrapper for KeyMatch2.

func KeyMatch3

func KeyMatch3(key1 string, key2 string) bool

KeyMatch3 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. For example, "/foo/bar" matches "/foo/*", "/resource1" matches "/{resource}"

func KeyMatch3Func

func KeyMatch3Func(args ...interface{}) (interface{}, error)

KeyMatch3Func is the wrapper for KeyMatch3.

func KeyMatch4

func KeyMatch4(key1 string, key2 string) bool

KeyMatch4 determines whether key1 matches the pattern of key2 (similar to RESTful path), key2 can contain a *. Besides what KeyMatch3 does, KeyMatch4 can also match repeated patterns: "/parent/123/child/123" matches "/parent/{id}/child/{id}" "/parent/123/child/456" does not match "/parent/{id}/child/{id}" But KeyMatch3 will match both.

func KeyMatch4Func

func KeyMatch4Func(args ...interface{}) (interface{}, error)

KeyMatch4Func is the wrapper for KeyMatch4.

func KeyMatch5

func KeyMatch5(key1 string, key2 string) bool

KeyMatch determines whether key1 matches the pattern of key2 and ignores the parameters in key2. For example, "/foo/bar?status=1&type=2" matches "/foo/bar"

func KeyMatch5Func

func KeyMatch5Func(args ...interface{}) (interface{}, error)

KeyMatch5Func is the wrapper for KeyMatch5.

func KeyMatchFunc

func KeyMatchFunc(args ...interface{}) (interface{}, error)

KeyMatchFunc is the wrapper for KeyMatch.

func RegexMatch

func RegexMatch(key1 string, key2 string) bool

RegexMatch determines whether key1 matches the pattern of key2 in regular expression.

func RegexMatchFunc

func RegexMatchFunc(args ...interface{}) (interface{}, error)

RegexMatchFunc is the wrapper for RegexMatch.

Types

type RewriteHandler

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

func NewHandler

func NewHandler(rules map[string]string) RewriteHandler

func (*RewriteHandler) ServeHTTP

func (h *RewriteHandler) ServeHTTP(res http.ResponseWriter, req *http.Request)

type Rule

type Rule struct {
	Pattern string
	To      string
	*regexp.Regexp
}

Rule uri的替换

注意 Pattern=/api/*和/api/(.*)有区别

Pattern=/api/*, To="/$1", URI="/api/anything/1" ==> /

Pattern=/api/(.*), To="/$1", URI="/api/anything/1" ==> /anything/1

func NewRule

func NewRule(pattern, to string) (*Rule, error)

func (*Rule) Replace

func (r *Rule) Replace(uri string) string

func (*Rule) ReplaceURL

func (r *Rule) ReplaceURL(u *url.URL) string

func (*Rule) Rewrite

func (r *Rule) Rewrite(req *http.Request) bool

Jump to

Keyboard shortcuts

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