Skip to content

shimohq/go-url-join

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-url-join

Like path.Join() but for a URL. Inspired by proper-url-join.

Installation

go get github.com/shimohq/go-url-join

Example

package main

import (
  "github.com/shimohq/go-url-join"
)

func main() {
    urljoin.Join("foo", "bar") // "/foo/bar"
    urljoin.Join("//wikipedia.org", "foo") // "//wikipedia.org/foo"
    urljoin.Join("https://wikipedia.org", "foo") // "https://wikipedia.org/foo"

    urljoin.JoinWithConfig(
        urljoin.Config{TrailingSlash: true},
        "foo", "bar",
    ) // "/foo/bar"

    urljoin.JoinWithConfig(
        urljoin.Config{LeadingSlash: false, KeepLeadingSlash: false},
        "/foo", "bar",
    ) // "foo/bar"

    urljoin.JoinWithConfig(
        urljoin.Config{LeadingSlash: false, KeepLeadingSlash: true},
        "/foo", "bar",
    ) // "/foo/bar"
}

About

Like `path.Join()` but for a URL.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages