urlparser

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package urlparser extracts repository paths from git URLs. Works with any git hosting service, not just the major ones. Inspired by github.com/librariesio/librariesio-url-parser

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalURL

func CanonicalURL(rawURL string) string

CanonicalURL returns the canonical URL for known hosts, or empty string.

func Clean

func Clean(rawURL string) string

Clean removes common noise from git URLs: schemes, auth, brackets, anchors, etc. Returns just the host/path portion ready for further processing.

func ExtractHost

func ExtractHost(rawURL string) string

ExtractHost returns the host portion of the URL.

func ExtractOwnerRepo

func ExtractOwnerRepo(rawURL string) string

ExtractOwnerRepo returns just the owner/repo portion.

func ExtractPath

func ExtractPath(rawURL string) string

ExtractPath returns just the path portion after the domain.

func FirstRepoURL

func FirstRepoURL(urls ...string) string

FirstRepoURL returns the first URL from the list that parses as a repo.

func IsKnownHost

func IsKnownHost(rawURL string) bool

IsKnownHost returns true if the URL is from a recognized git hosting service.

func Normalize

func Normalize(rawURL string) string

Normalize cleans a git URL and ensures it has an https scheme.

func Parse

func Parse(rawURL string) string

Parse attempts to parse a URL and return a canonical form.

func ParseFromMap

func ParseFromMap(m map[string]string, priorityKeys ...string) string

ParseFromMap extracts a repository URL from common field names in a map.

func TryParseURL

func TryParseURL(rawURL string) *url.URL

TryParseURL attempts to parse a URL using Go's url.Parse.

Types

type RepoURL

type RepoURL struct {
	Host  string
	Owner string
	Repo  string
}

RepoURL represents a parsed repository URL.

func ParseURL

func ParseURL(rawURL string) *RepoURL

ParseURL is like Parse but returns structured data.

func (*RepoURL) OwnerRepo

func (r *RepoURL) OwnerRepo() string

OwnerRepo returns "owner/repo".

func (*RepoURL) String

func (r *RepoURL) String() string

String returns the canonical URL form.

Jump to

Keyboard shortcuts

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