https://github.com/shimohq/go-url-join
Like `path.Join()` but for a URL.
https://github.com/shimohq/go-url-join
Last synced: about 11 hours ago
JSON representation
Like `path.Join()` but for a URL.
- Host: GitHub
- URL: https://github.com/shimohq/go-url-join
- Owner: shimohq
- License: mit
- Created: 2020-05-06T09:00:45.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-06T09:06:53.000Z (over 5 years ago)
- Last Synced: 2025-04-09T14:08:44.938Z (6 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-url-join
Like `path.Join()` but for a URL. Inspired by [proper-url-join](https://github.com/moxystudio/js-proper-url-join).
## Installation
```
go get github.com/shimohq/go-url-join
```## Example
```go
package mainimport (
"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"
}
```