Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 2.1 KB

README.md

File metadata and controls

60 lines (43 loc) · 2.1 KB

urlegit

URLegit is a library for validating URLs.

Build Status codecov.io Go Report Card Apache V2 License GitHub Release GoDoc

Summary

URL validation is complex and very specific to the task at hand. This library's goal is to provide a toolkit for making pre-flight checks against a URL easier.

Usage

package main

import (
	"fmt"

	"github.com/xmidt-org/urlegit"
)

func main() {
	c, err := urlegit.New(
		urlegit.OnlyScheme("https"),
		urlegit.ForbidSpecialUseDomains(),
	)

	if err != nil {
		panic(err)
	}

	url := "https://github.com"
	fmt.Printf("Is %q allowed? %t\n", url, c.Legit(url))

	// Output:
	// Is "https://github.com" allowed? true
}

Go Playground

Resources

Footnotes

This library originally started of in xmidt-org/ancla as webhook URL validation code. Here is a perma link to that code.