Socket
Book a DemoInstallSign in
Socket

gopkg.in/nowk/urlp.v1

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gopkg.in/nowk/urlp.v1

v1.0.1
Go
Version published
Created
Source

urlp

Build Status GoDoc

URL pattern match

Install

go get gopkg.in/nowk/urlp.v1

Examples

v, ok := urlp.Match("/posts/:post_id/comments/:id", "/posts/123/comments/456")
if !ok {
  // handle
}

post_id := v.Get(":post_id")
id := v.Get(":id")
.:format

Adding .:format at the end of the pattern returns a special named param :_format which returns the given format.

v, ok := urlp.Match("/posts/:id.:format", "/posts/123.json")
if !ok {
  // handle
}

id := v.Get(":id")
format := v.Get(":_format")

With a .:format set the pattern will match paths with or without the extension.

v, ok := urlp.Match("/posts/:id.:format", "/posts/123.json")
// ok       => true
// :_format => "json"

v, ok := urlp.Match("/posts/:id.:format", "/posts/123")
// ok       => true
// :_format => ""

.:format must be at the end of the pattern, else it will be treated as any other named parameter.

Without .:format paths with a .ext will not be matched

License

MIT

FAQs

Package last updated on 04 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.