mirror of
https://github.com/thegeeklab/url-parser.git
synced 2024-09-28 10:18:20 +00:00
Compare commits
117 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
75a3f7dc4a | ||
|
7732914f1a | ||
|
776e809c52 | ||
|
4a02590ff2 | ||
|
8b66ceb9c4 | ||
9238878382 | |||
|
ae0cbaa654 | ||
|
9047fa86a4 | ||
|
441a10a33d | ||
|
3c053eef7d | ||
|
cf3d105310 | ||
|
70f0d4e5b3 | ||
9ff6cd2e6a | |||
|
d36d95846e | ||
|
5c8b9d9cd5 | ||
|
77d3c11da1 | ||
|
df1cb658f3 | ||
|
659ddcee44 | ||
7d4e9651f5 | |||
|
c6b5c9d03d | ||
|
656f744c52 | ||
b01ea54ae9 | |||
6c04899a49 | |||
|
edbced6e5b | ||
|
8f8506617a | ||
|
7cbec15ac2 | ||
5f80b2a7f3 | |||
8c4de70ec4 | |||
b5214bd5df | |||
|
697fdd8bbe | ||
872985ac58 | |||
930e1aac89 | |||
|
590a1c2373 | ||
|
9c841c24cd | ||
49348198db | |||
8fbc353b9b | |||
|
a6c765e1ae | ||
63a38bd033 | |||
f246b1d280 | |||
48bead3372 | |||
|
ff7cdd0857 | ||
6bf5fa8754 | |||
ae1fc2e698 | |||
8c8961bc8e | |||
c0724d12f2 | |||
2a55822632 | |||
90072d2d43 | |||
|
19af4c5c47 | ||
8457c57394 | |||
0af993f5b1 | |||
|
db299322bc | ||
3875ad7a2c | |||
|
3a220af100 | ||
|
c35952c307 | ||
|
183d422439 | ||
|
96db2914ca | ||
|
1c77303641 | ||
|
2f99efb570 | ||
65184f6fc9 | |||
|
ffd126bf10 | ||
|
cf8701ad2f | ||
|
f8585dd93b | ||
|
364ccf7c84 | ||
13171987d8 | |||
ddd51bf1c6 | |||
|
870aef309e | ||
|
067b1bf449 | ||
887fbb90e1 | |||
5c61c96e14 | |||
|
98277d747e | ||
|
8a8c51409c | ||
f32e067fbe | |||
|
fd7629faf3 | ||
|
5a6af40cd7 | ||
|
2738dd3870 | ||
|
ba386afbb5 | ||
|
8ec0eb29be | ||
ea23877b4a | |||
|
255fd776c6 | ||
|
181777004f | ||
b1f139a722 | |||
8d68b98c88 | |||
|
37baf6f8ae | ||
|
9e1a6398b9 | ||
|
c2ace14781 | ||
|
24124e44ae | ||
|
d29e6e23b9 | ||
7326a7c73d | |||
|
4668b2512a | ||
|
02e19acd42 | ||
2404e7aeab | |||
2bd123697f | |||
|
fc011b7533 | ||
|
47d5dc9525 | ||
1f5e3782c3 | |||
7ed2af9aa2 | |||
9503936548 | |||
|
155a70faa3 | ||
ed8f1b16e1 | |||
|
4cd1483c51 | ||
20573ef04f | |||
a2768d6c39 | |||
da22381307 | |||
d797a814c4 | |||
|
4dbc8a9d75 | ||
c15c34ea99 | |||
d09d5d748d | |||
c7a5cbb700 | |||
|
ce913f83b9 | ||
|
2e07f924ca | ||
|
b6eb4148cd | ||
f5a648799c | |||
41cccb5b52 | |||
80b9b2cfa6 | |||
dadba92857 | |||
f67ddfdbd5 | |||
5d0e6e7eb6 |
4
.dictionary
Normal file
4
.dictionary
Normal file
@ -0,0 +1,4 @@
|
||||
url-parser
|
||||
herloct
|
||||
multiarch
|
||||
(P|p)rebuilt
|
193
.drone.jsonnet
193
.drone.jsonnet
@ -1,193 +0,0 @@
|
||||
local PipelineTest = {
|
||||
kind: 'pipeline',
|
||||
image_pull_secrets: ['docker_config'],
|
||||
name: 'test',
|
||||
platform: {
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'staticcheck',
|
||||
image: 'golang:1.15',
|
||||
commands: [
|
||||
'go run honnef.co/go/tools/cmd/staticcheck ./...',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'lint',
|
||||
image: 'golang:1.15',
|
||||
commands: [
|
||||
'go run golang.org/x/lint/golint -set_exit_status ./...',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'vet',
|
||||
image: 'golang:1.15',
|
||||
commands: [
|
||||
'go vet ./...',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'test',
|
||||
image: 'golang:1.15',
|
||||
commands: [
|
||||
'go test -race -coverprofile=coverage.txt -covermode=atomic ./...',
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
path: '/go',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'coverage',
|
||||
image: 'plugins/codecov',
|
||||
settings: {
|
||||
token: {
|
||||
from_secret: 'codecov_token',
|
||||
},
|
||||
files: [
|
||||
'coverage.txt',
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
volumes: [
|
||||
{
|
||||
name: 'gopath',
|
||||
temp: {},
|
||||
},
|
||||
],
|
||||
trigger: {
|
||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
local PipelineBuildBinaries = {
|
||||
kind: 'pipeline',
|
||||
image_pull_secrets: ['docker_config'],
|
||||
name: 'build-binaries',
|
||||
platform: {
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'build',
|
||||
image: 'techknowlogick/xgo:go-1.15.x',
|
||||
commands: [
|
||||
'[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}',
|
||||
'mkdir -p release/',
|
||||
"cd cmd/url-parser && xgo -ldflags \"-s -w -X main.version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out url-parser .",
|
||||
'mv /build/* /drone/src/release/',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'executable',
|
||||
image: 'alpine',
|
||||
commands: [
|
||||
'$(find release/ -executable -type f | grep url-parser-linux-amd64) --help',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'compress',
|
||||
image: 'alpine',
|
||||
commands: [
|
||||
'apk add upx',
|
||||
'find release/ -maxdepth 1 -executable -type f -exec upx {} \\;',
|
||||
'ls -lh release/',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'checksum',
|
||||
image: 'alpine',
|
||||
commands: [
|
||||
'cd release/ && sha256sum * > sha256sum.txt',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'publish',
|
||||
image: 'plugins/github-release',
|
||||
settings: {
|
||||
overwrite: true,
|
||||
api_key: {
|
||||
from_secret: 'github_token',
|
||||
},
|
||||
files: ['release/*'],
|
||||
title: '${DRONE_TAG}',
|
||||
note: 'CHANGELOG.md',
|
||||
},
|
||||
when: {
|
||||
ref: [
|
||||
'refs/tags/**',
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
depends_on: [
|
||||
'test',
|
||||
],
|
||||
trigger: {
|
||||
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
||||
},
|
||||
};
|
||||
|
||||
local PipelineNotifications = {
|
||||
kind: 'pipeline',
|
||||
image_pull_secrets: ['docker_config'],
|
||||
name: 'notifications',
|
||||
platform: {
|
||||
os: 'linux',
|
||||
arch: 'amd64',
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: 'matrix',
|
||||
image: 'plugins/matrix',
|
||||
settings: {
|
||||
homeserver: { from_secret: 'matrix_homeserver' },
|
||||
roomid: { from_secret: 'matrix_roomid' },
|
||||
template: 'Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}',
|
||||
username: { from_secret: 'matrix_username' },
|
||||
password: { from_secret: 'matrix_password' },
|
||||
},
|
||||
when: {
|
||||
status: ['success', 'failure'],
|
||||
},
|
||||
},
|
||||
],
|
||||
depends_on: [
|
||||
'build-binaries',
|
||||
],
|
||||
trigger: {
|
||||
ref: ['refs/heads/main', 'refs/tags/**'],
|
||||
status: ['success', 'failure'],
|
||||
},
|
||||
};
|
||||
|
||||
[
|
||||
PipelineTest,
|
||||
PipelineBuildBinaries,
|
||||
PipelineNotifications,
|
||||
]
|
167
.drone.yml
167
.drone.yml
@ -1,167 +0,0 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: test
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: staticcheck
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- go run honnef.co/go/tools/cmd/staticcheck ./...
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: lint
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- go run golang.org/x/lint/golint -set_exit_status ./...
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: vet
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- go vet ./...
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: test
|
||||
image: golang:1.15
|
||||
commands:
|
||||
- go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||
volumes:
|
||||
- name: gopath
|
||||
path: /go
|
||||
|
||||
- name: coverage
|
||||
image: plugins/codecov
|
||||
settings:
|
||||
files:
|
||||
- coverage.txt
|
||||
token:
|
||||
from_secret: codecov_token
|
||||
|
||||
volumes:
|
||||
- name: gopath
|
||||
temp: {}
|
||||
|
||||
image_pull_secrets:
|
||||
- docker_config
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/main
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: build-binaries
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: techknowlogick/xgo:go-1.15.x
|
||||
commands:
|
||||
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
|
||||
- mkdir -p release/
|
||||
- cd cmd/url-parser && xgo -ldflags "-s -w -X main.version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm64' -out url-parser .
|
||||
- mv /build/* /drone/src/release/
|
||||
|
||||
- name: executable
|
||||
image: alpine
|
||||
commands:
|
||||
- $(find release/ -executable -type f | grep url-parser-linux-amd64) --help
|
||||
|
||||
- name: compress
|
||||
image: alpine
|
||||
commands:
|
||||
- apk add upx
|
||||
- find release/ -maxdepth 1 -executable -type f -exec upx {} \;
|
||||
- ls -lh release/
|
||||
|
||||
- name: checksum
|
||||
image: alpine
|
||||
commands:
|
||||
- cd release/ && sha256sum * > sha256sum.txt
|
||||
|
||||
- name: publish
|
||||
image: plugins/github-release
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: github_token
|
||||
files:
|
||||
- release/*
|
||||
note: CHANGELOG.md
|
||||
overwrite: true
|
||||
title: ${DRONE_TAG}
|
||||
when:
|
||||
ref:
|
||||
- refs/tags/**
|
||||
|
||||
image_pull_secrets:
|
||||
- docker_config
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/main
|
||||
- refs/tags/**
|
||||
- refs/pull/**
|
||||
|
||||
depends_on:
|
||||
- test
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: notifications
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: matrix
|
||||
image: plugins/matrix
|
||||
settings:
|
||||
homeserver:
|
||||
from_secret: matrix_homeserver
|
||||
password:
|
||||
from_secret: matrix_password
|
||||
roomid:
|
||||
from_secret: matrix_roomid
|
||||
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
|
||||
username:
|
||||
from_secret: matrix_username
|
||||
when:
|
||||
status:
|
||||
- success
|
||||
- failure
|
||||
|
||||
image_pull_secrets:
|
||||
- docker_config
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/main
|
||||
- refs/tags/**
|
||||
status:
|
||||
- success
|
||||
- failure
|
||||
|
||||
depends_on:
|
||||
- build-binaries
|
||||
|
||||
---
|
||||
kind: signature
|
||||
hmac: cb861ef547d389365c74e52d97940109686394d848bda333b77eaa1b50a59c5a
|
||||
|
||||
...
|
9
.github/settings.yml
vendored
9
.github/settings.yml
vendored
@ -48,8 +48,11 @@ branches:
|
||||
protection:
|
||||
required_pull_request_reviews: null
|
||||
required_status_checks:
|
||||
strict: true
|
||||
strict: false
|
||||
contexts:
|
||||
- continuous-integration/drone/pr
|
||||
enforce_admins: null
|
||||
- ci/woodpecker/pr/test
|
||||
- ci/woodpecker/pr/build-package
|
||||
- ci/woodpecker/pr/docs
|
||||
enforce_admins: false
|
||||
required_linear_history: true
|
||||
restrictions: null
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
/release/
|
||||
/dist
|
||||
/release
|
||||
/url-parser*
|
||||
|
||||
coverage.out
|
||||
CHANGELOG.md
|
||||
|
47
.gitsv/config.yml
Normal file
47
.gitsv/config.yml
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
version: "1.1"
|
||||
|
||||
versioning:
|
||||
update-major: []
|
||||
update-minor: [feat]
|
||||
update-patch: [fix, perf, refactor, chore, test, ci, docs]
|
||||
|
||||
tag:
|
||||
pattern: "v%d.%d.%d"
|
||||
|
||||
release-notes:
|
||||
sections:
|
||||
- name: Features
|
||||
commit-types: [feat]
|
||||
section-type: commits
|
||||
- name: Bug Fixes
|
||||
commit-types: [fix]
|
||||
section-type: commits
|
||||
- name: Performance Improvements
|
||||
commit-types: [perf]
|
||||
section-type: commits
|
||||
- name: Code Refactoring
|
||||
commit-types: [refactor]
|
||||
section-type: commits
|
||||
- name: Others
|
||||
commit-types: [chore]
|
||||
section-type: commits
|
||||
- name: Testing
|
||||
commit-types: [test]
|
||||
section-type: commits
|
||||
- name: CI Pipeline
|
||||
commit-types: [ci]
|
||||
section-type: commits
|
||||
- name: Documentation
|
||||
commit-types: [docs]
|
||||
section-type: commits
|
||||
- name: BREAKING CHANGES
|
||||
section-type: breaking-changes
|
||||
|
||||
commit-message:
|
||||
footer:
|
||||
issue:
|
||||
key: issue
|
||||
add-value-prefix: "#"
|
||||
issue:
|
||||
regex: "#?[0-9]+"
|
96
.golangci.yml
Normal file
96
.golangci.yml
Normal file
@ -0,0 +1,96 @@
|
||||
linters:
|
||||
enable-all: false
|
||||
disable-all: true
|
||||
enable:
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- typecheck
|
||||
- unused
|
||||
- asasalint
|
||||
- asciicheck
|
||||
- bidichk
|
||||
- bodyclose
|
||||
- containedctx
|
||||
- contextcheck
|
||||
- decorder
|
||||
- dogsled
|
||||
- dupl
|
||||
- dupword
|
||||
- durationcheck
|
||||
- errchkjson
|
||||
- errname
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- forcetypeassert
|
||||
- ginkgolinter
|
||||
- gocheckcompilerdirectives
|
||||
- gochecknoglobals
|
||||
- gochecknoinits
|
||||
- gocognit
|
||||
- goconst
|
||||
- gocritic
|
||||
- gocyclo
|
||||
- godot
|
||||
- godox
|
||||
- err113
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goheader
|
||||
- goimports
|
||||
- mnd
|
||||
- gomoddirectives
|
||||
- gomodguard
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- grouper
|
||||
- importas
|
||||
- interfacebloat
|
||||
- ireturn
|
||||
- lll
|
||||
- loggercheck
|
||||
- maintidx
|
||||
- makezero
|
||||
- misspell
|
||||
- musttag
|
||||
- nakedret
|
||||
- nestif
|
||||
- nilerr
|
||||
- nilnil
|
||||
- nlreturn
|
||||
- noctx
|
||||
- nolintlint
|
||||
- nonamedreturns
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
# - rowserrcheck
|
||||
# - sqlclosecheck
|
||||
# - structcheck
|
||||
- stylecheck
|
||||
- tagliatelle
|
||||
- tenv
|
||||
- testableexamples
|
||||
- thelper
|
||||
- tparallel
|
||||
- unconvert
|
||||
- unparam
|
||||
- usestdlibvars
|
||||
# - wastedassign
|
||||
- whitespace
|
||||
- wsl
|
||||
- zerologlint
|
||||
fast: false
|
||||
|
||||
run:
|
||||
timeout: 3m
|
||||
|
||||
linters-settings:
|
||||
gofumpt:
|
||||
extra-rules: true
|
6
.markdownlint.yml
Normal file
6
.markdownlint.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
default: True
|
||||
MD013: False
|
||||
MD041: False
|
||||
MD004:
|
||||
style: dash
|
2
.prettierignore
Normal file
2
.prettierignore
Normal file
@ -0,0 +1,2 @@
|
||||
*.tpl.md
|
||||
LICENSE
|
41
.woodpecker/build-package.yml
Normal file
41
.woodpecker/build-package.yml
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
when:
|
||||
- event: [pull_request, tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: docker.io/techknowlogick/xgo:go-1.22.x
|
||||
commands:
|
||||
- ln -s $(pwd) /source
|
||||
- make release
|
||||
|
||||
- name: executable
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
commands:
|
||||
- $(find dist/ -executable -type f -iname ${CI_REPO_NAME}-linux-amd64) --help
|
||||
|
||||
- name: changelog
|
||||
image: quay.io/thegeeklab/git-sv
|
||||
commands:
|
||||
- git sv current-version
|
||||
- git sv release-notes -t ${CI_COMMIT_TAG:-next} -o CHANGELOG.md
|
||||
- cat CHANGELOG.md
|
||||
|
||||
- name: publish-github
|
||||
image: docker.io/plugins/github-release
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: github_token
|
||||
files:
|
||||
- dist/*
|
||||
note: CHANGELOG.md
|
||||
overwrite: true
|
||||
title: ${CI_COMMIT_TAG}
|
||||
when:
|
||||
- event: [tag]
|
||||
|
||||
depends_on:
|
||||
- test
|
22
.woodpecker/docs.yml
Normal file
22
.woodpecker/docs.yml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
when:
|
||||
- event: [pull_request, tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
- name: markdownlint
|
||||
image: quay.io/thegeeklab/markdownlint-cli
|
||||
commands:
|
||||
- markdownlint 'README.md' 'CONTRIBUTING.md'
|
||||
|
||||
- name: spellcheck
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
commands:
|
||||
- spellchecker --files 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
|
||||
environment:
|
||||
FORCE_COLOR: "true"
|
||||
|
||||
depends_on:
|
||||
- build-package
|
26
.woodpecker/notify.yml
Normal file
26
.woodpecker/notify.yml
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
when:
|
||||
- event: [tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
runs_on: [success, failure]
|
||||
|
||||
steps:
|
||||
- name: matrix
|
||||
image: quay.io/thegeeklab/wp-matrix
|
||||
settings:
|
||||
homeserver:
|
||||
from_secret: matrix_homeserver
|
||||
room_id:
|
||||
from_secret: matrix_room_id
|
||||
user_id:
|
||||
from_secret: matrix_user_id
|
||||
access_token:
|
||||
from_secret: matrix_access_token
|
||||
when:
|
||||
- status: [success, failure]
|
||||
|
||||
depends_on:
|
||||
- docs
|
17
.woodpecker/test.yml
Normal file
17
.woodpecker/test.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
when:
|
||||
- event: [pull_request, tag]
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
- name: lint
|
||||
image: docker.io/library/golang:1.23
|
||||
commands:
|
||||
- make lint
|
||||
|
||||
- name: test
|
||||
image: docker.io/library/golang:1.23
|
||||
commands:
|
||||
- make test
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,13 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## v0.2.1 (2021-01-04)
|
||||
|
||||
### Docs
|
||||
|
||||
- add contributing information
|
||||
|
||||
### Others
|
||||
|
||||
- replace master by main as default branch
|
||||
- **deps**: update dependencies
|
||||
- use renovate preset config
|
@ -3,7 +3,7 @@
|
||||
## Security
|
||||
|
||||
If you think you have found a **security issue**, please do not mention it in this repository.
|
||||
Instead, send an email to security@thegeeklab.de with as many details as possible so it can be handled confidential.
|
||||
Instead, send an email to `security@thegeeklab.de` with as many details as possible so it can be handled confidential.
|
||||
|
||||
## Bug Reports and Feature Requests
|
||||
|
||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Robert Kaussow <mail@thegeeklab.de>
|
||||
Copyright (c) 2022 Robert Kaussow <mail@thegeeklab.de>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
103
Makefile
Normal file
103
Makefile
Normal file
@ -0,0 +1,103 @@
|
||||
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
||||
GOFUMPT_PACKAGE_VERSION := v0.7.0
|
||||
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.61.0
|
||||
|
||||
EXECUTABLE := url-parser
|
||||
|
||||
DIST := dist
|
||||
DIST_DIRS := $(DIST)
|
||||
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
|
||||
|
||||
GO ?= go
|
||||
CWD ?= $(shell pwd)
|
||||
PACKAGES ?= $(shell go list ./...)
|
||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
|
||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
||||
|
||||
GENERATE ?=
|
||||
XGO_VERSION := go-1.22.x
|
||||
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
|
||||
|
||||
TARGETOS ?= linux
|
||||
TARGETARCH ?= amd64
|
||||
ifneq ("$(TARGETVARIANT)","")
|
||||
GOARM ?= $(subst v,,$(TARGETVARIANT))
|
||||
endif
|
||||
TAGS ?= netgo
|
||||
|
||||
ifndef VERSION
|
||||
ifneq ($(CI_COMMIT_TAG),)
|
||||
VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
|
||||
else
|
||||
VERSION ?= $(shell git rev-parse --short HEAD)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifndef DATE
|
||||
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
|
||||
endif
|
||||
|
||||
LDFLAGS += -s -w -X "main.BuildVersion=$(VERSION)" -X "main.BuildDate=$(DATE)"
|
||||
|
||||
.PHONY: all
|
||||
all: clean build
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(GO) clean -i ./...
|
||||
rm -rf $(DIST_DIRS)
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
$(GO) run $(GOFUMPT_PACKAGE) -extra -w $(SOURCES)
|
||||
|
||||
.PHONY: golangci-lint
|
||||
golangci-lint:
|
||||
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
|
||||
|
||||
.PHONY: lint
|
||||
lint: golangci-lint
|
||||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
$(GO) generate $(GENERATE)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
||||
|
||||
.PHONY: build
|
||||
build: $(DIST)/$(EXECUTABLE)
|
||||
|
||||
$(DIST)/$(EXECUTABLE): $(SOURCES)
|
||||
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
|
||||
|
||||
$(DIST_DIRS):
|
||||
mkdir -p $(DIST_DIRS)
|
||||
|
||||
.PHONY: xgo
|
||||
xgo: | $(DIST_DIRS)
|
||||
$(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
|
||||
cp /build/* $(CWD)/$(DIST)
|
||||
ls -l $(CWD)/$(DIST)
|
||||
|
||||
.PHONY: checksum
|
||||
checksum:
|
||||
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
||||
ls -l $(CWD)/$(DIST)
|
||||
|
||||
.PHONY: release
|
||||
release: xgo checksum
|
||||
|
||||
.PHONY: deps
|
||||
deps:
|
||||
$(GO) mod download
|
||||
$(GO) install $(GOFUMPT_PACKAGE)
|
||||
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
||||
$(GO) install $(XGO_PACKAGE)
|
||||
$(GO) install $(GOTESTSUM_PACKAGE)
|
43
README.md
43
README.md
@ -1,21 +1,29 @@
|
||||
# url-parser
|
||||
|
||||
[![Build Status](https://img.shields.io/drone/build/thegeeklab/url-parser?logo=drone)](https://cloud.drone.io/thegeeklab/url-parser)
|
||||
Simple command-line URL parser
|
||||
|
||||
[![Build Status](https://ci.thegeeklab.de/api/badges/thegeeklab/url-parser/status.svg)](https://ci.thegeeklab.de/repos/thegeeklab/url-parser)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/url-parser)](https://goreportcard.com/report/github.com/thegeeklab/url-parser)
|
||||
[![Codecov](https://img.shields.io/codecov/c/github/thegeeklab/url-parser)](https://codecov.io/gh/thegeeklab/url-parser)
|
||||
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/url-parser)](https://github.com/thegeeklab/url-parser/graphs/contributors)
|
||||
[![License: MIT](https://img.shields.io/github/license/thegeeklab/url-parser)](https://github.com/thegeeklab/url-parser/blob/main/LICENSE)
|
||||
|
||||
Inspired by [herloct/url-parser](https://github.com/herloct/url-parser), a simple command-line utility for parsing URLs.
|
||||
|
||||
## Instalation
|
||||
## Installation
|
||||
|
||||
Prebuild multiarch binaries are availabe for Linux only:
|
||||
Prebuilt multiarch binaries are available for Linux only.
|
||||
|
||||
```Shell
|
||||
curl -L https://github.com/thegeeklab/url-parser/releases/download/v0.1.0/url-parser-0.1.0-linux-amd64 > /usr/local/bin/url-parser
|
||||
curl -SsfL https://github.com/thegeeklab/url-parser/releases/latest/download/url-parser-linux-amd64 -o /usr/local/bin/url-parser
|
||||
chmod +x /usr/local/bin/url-parser
|
||||
url-parser --help
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Build the binary from source with the following command:
|
||||
|
||||
```Shell
|
||||
make build
|
||||
```
|
||||
|
||||
## Usage
|
||||
@ -45,36 +53,39 @@ COMMANDS:
|
||||
|
||||
GLOBAL OPTIONS:
|
||||
--url value source url to parse [$URL_PARSER_URL]
|
||||
--help, -h show help (default: false)
|
||||
--version, -v print the version (default: false)
|
||||
--help, -h show help
|
||||
--version, -v print the version
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```Shell
|
||||
$ url-parser host --url https://somedomain.com
|
||||
$ url-parser --url https://somedomain.com host
|
||||
somedomain.com
|
||||
|
||||
$ url-parser user --url https://herloct@somedomain.com
|
||||
$ url-parser --url https://herloct@somedomain.com user
|
||||
herloct
|
||||
|
||||
$ url-parser path --url https://somedomain.com/path/to
|
||||
$ url-parser --url https://somedomain.com/path/to path
|
||||
/path/to
|
||||
|
||||
$ url-parser path --path-index=1 --url https://somedomain.com/path/to
|
||||
$ url-parser --url https://somedomain.com/path/to path --path-index=1
|
||||
to
|
||||
|
||||
$ url-parser query --url https://somedomain.com/?some-key=somevalue
|
||||
$ url-parser --url https://somedomain.com/?some-key=somevalue query
|
||||
some-key=somevalue
|
||||
|
||||
$ url-parser query --query-field=some-key --url https://somedomain.com/?some-key=somevalue
|
||||
$ url-parser --url https://somedomain.com/?some-key=somevalue query --query-field=some-key
|
||||
somevalue
|
||||
|
||||
# It is also possible to read the URL from stdin
|
||||
$ echo "https://somedomain.com" | url-parser host
|
||||
somedomain.com
|
||||
```
|
||||
|
||||
## Contributors
|
||||
|
||||
Special thanks goes to all [contributors](https://github.com/thegeeklab/url-parser/graphs/contributors). If you would like to contribute,
|
||||
please see the [instructions](https://github.com/thegeeklab/url-parser/blob/main/CONTRIBUTING.md).
|
||||
Special thanks to all [contributors](https://github.com/thegeeklab/url-parser/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/url-parser/blob/main/CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
|
@ -1,84 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/thegeeklab/url-parser/internal/command"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func globalFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
Usage: "source url to parse",
|
||||
EnvVars: []string{"URL_PARSER_URL"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func configCommands() []*cli.Command {
|
||||
return []*cli.Command{
|
||||
{
|
||||
Name: "all",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "Get all parts from url",
|
||||
Action: command.Run,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
{
|
||||
Name: "scheme",
|
||||
Aliases: []string{"s"},
|
||||
Usage: "Get scheme from url",
|
||||
Action: command.Scheme,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
{
|
||||
Name: "user",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Get username from url",
|
||||
Action: command.User,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
{
|
||||
Name: "password",
|
||||
Aliases: []string{"pw"},
|
||||
Usage: "Get password from url",
|
||||
Action: command.Password,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
{
|
||||
Name: "path",
|
||||
Aliases: []string{"pt"},
|
||||
Usage: "Get path from url",
|
||||
Action: command.Path,
|
||||
Flags: append(globalFlags(), command.PathFlags()...),
|
||||
},
|
||||
{
|
||||
Name: "host",
|
||||
Aliases: []string{"h"},
|
||||
Usage: "Get hostname from url",
|
||||
Action: command.Host,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "Get port from url",
|
||||
Action: command.Port,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
{
|
||||
Name: "query",
|
||||
Aliases: []string{"q"},
|
||||
Usage: "Get query from url",
|
||||
Action: command.Query,
|
||||
Flags: append(globalFlags(), command.QueryFlags()...),
|
||||
},
|
||||
{
|
||||
Name: "fragment",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "Get fragment from url",
|
||||
Action: command.Fragment,
|
||||
Flags: globalFlags(),
|
||||
},
|
||||
}
|
||||
}
|
@ -1,26 +1,125 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/thegeeklab/url-parser/internal/command"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thegeeklab/url-parser/command"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Version of current build
|
||||
var Version = "devel"
|
||||
//nolint:gochecknoglobals
|
||||
var (
|
||||
BuildVersion = "devel"
|
||||
BuildDate = "00000000"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "url-parser"
|
||||
app.Usage = "Parse URL and shows the part of it."
|
||||
app.Version = Version
|
||||
app.Action = command.Run
|
||||
app.Flags = globalFlags()
|
||||
app.Commands = configCommands()
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
|
||||
cli.VersionPrinter = func(c *cli.Context) {
|
||||
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
||||
}
|
||||
|
||||
cfg := &config.Config{}
|
||||
|
||||
app := &cli.App{
|
||||
Name: "url-parser",
|
||||
Usage: "Parse URL and shows the part of it.",
|
||||
Version: BuildVersion,
|
||||
Action: command.Run(cfg),
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "url",
|
||||
Usage: "source url to parse",
|
||||
EnvVars: []string{"URL_PARSER_URL"},
|
||||
Destination: &cfg.URL,
|
||||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
Name: "all",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "Get all parts from url",
|
||||
Action: command.Run(cfg),
|
||||
},
|
||||
{
|
||||
Name: "scheme",
|
||||
Aliases: []string{"s"},
|
||||
Usage: "Get scheme from url",
|
||||
Action: command.Scheme(cfg),
|
||||
},
|
||||
{
|
||||
Name: "user",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Get username from url",
|
||||
Action: command.User(cfg),
|
||||
},
|
||||
{
|
||||
Name: "password",
|
||||
Aliases: []string{"pw"},
|
||||
Usage: "Get password from url",
|
||||
Action: command.Password(cfg),
|
||||
},
|
||||
{
|
||||
Name: "path",
|
||||
Aliases: []string{"pt"},
|
||||
Usage: "Get path from url",
|
||||
Action: command.Path(cfg),
|
||||
Flags: command.PathFlags(cfg),
|
||||
},
|
||||
{
|
||||
Name: "host",
|
||||
Aliases: []string{"ht"},
|
||||
Usage: "Get hostname from url",
|
||||
Action: command.Host(cfg),
|
||||
},
|
||||
{
|
||||
Name: "port",
|
||||
Aliases: []string{"p"},
|
||||
Usage: "Get port from url",
|
||||
Action: command.Port(cfg),
|
||||
},
|
||||
{
|
||||
Name: "query",
|
||||
Aliases: []string{"q"},
|
||||
Usage: "Get query from url",
|
||||
Action: command.Query(cfg),
|
||||
Flags: command.QueryFlags(cfg),
|
||||
},
|
||||
{
|
||||
Name: "fragment",
|
||||
Aliases: []string{"f"},
|
||||
Usage: "Get fragment from url",
|
||||
Action: command.Fragment(cfg),
|
||||
},
|
||||
},
|
||||
Before: func(_ *cli.Context) error {
|
||||
if cfg.URL == "" {
|
||||
stat, _ := os.Stdin.Stat()
|
||||
if (stat.Mode() & os.ModeCharDevice) == 0 {
|
||||
stdin, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error: %w: %w", config.ErrReadStdin, err)
|
||||
}
|
||||
cfg.URL = strings.TrimSuffix(string(stdin), "\n")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.URL == "" {
|
||||
return fmt.Errorf("error: %w", config.ErrEmptyURL)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal().Err(err).Msg("Execution error")
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
)
|
||||
|
||||
func parseURL(raw string) *url.URL {
|
||||
@ -12,7 +13,7 @@ func parseURL(raw string) *url.URL {
|
||||
|
||||
url, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal().Err(err).Msg(config.ErrParseURL.Error())
|
||||
}
|
||||
|
||||
return url
|
@ -1,18 +1,23 @@
|
||||
package command
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
)
|
||||
|
||||
type TestParseData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
func TestParseURL(t *testing.T) {
|
||||
//nolint:goconst
|
||||
urlString := "postgres://user:pass@host.com:5432/path/to?key=value&other=other%20value#some-fragment"
|
||||
|
||||
tables := []TestParseData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: urlString,
|
||||
},
|
||||
}
|
21
command/fragment.go
Normal file
21
command/fragment.go
Normal file
@ -0,0 +1,21 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Fragment prints out the fragment part from the url.
|
||||
func Fragment(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Fragment)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestFragmentData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestFragment(t *testing.T) {
|
||||
|
||||
tables := []TestFragmentData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "some-fragment",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Fragment(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Fragment(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL fragment `%v`, should be `%v`", result, table.expected)
|
21
command/host.go
Normal file
21
command/host.go
Normal file
@ -0,0 +1,21 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Host prints out the host part from the url.
|
||||
func Host(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Hostname())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestHostnameData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestHost(t *testing.T) {
|
||||
|
||||
tables := []TestHostnameData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "host.com",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Host(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Host(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL host `%v`, should be `%v`", result, table.expected)
|
24
command/password.go
Normal file
24
command/password.go
Normal file
@ -0,0 +1,24 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Password prints out the password part from url.
|
||||
func Password(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if parts.User != nil {
|
||||
pw, _ := parts.User.Password()
|
||||
if len(pw) > 0 {
|
||||
fmt.Println(pw)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestPasswordData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestPassword(t *testing.T) {
|
||||
|
||||
tables := []TestPasswordData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "pass",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Password(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Password(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL password `%v`, should be `%v`", result, table.expected)
|
44
command/path.go
Normal file
44
command/path.go
Normal file
@ -0,0 +1,44 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// PathFlags defines flags for path subcommand.
|
||||
func PathFlags(cfg *config.Config) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "path-index",
|
||||
Usage: "filter parsed path by index",
|
||||
EnvVars: []string{"URL_PARSER_PATH_INDEX"},
|
||||
Value: -1,
|
||||
Destination: &cfg.PathIndex,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Path prints out the path part from url.
|
||||
func Path(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
i := cfg.PathIndex
|
||||
|
||||
if len(parts.Path) > 0 {
|
||||
if i > -1 {
|
||||
path := strings.Split(parts.Path, "/")
|
||||
|
||||
if i++; i < len(path) {
|
||||
fmt.Println(path[i])
|
||||
}
|
||||
} else {
|
||||
fmt.Println(parts.Path)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
41
command/path_test.go
Normal file
41
command/path_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestPathData struct {
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
func TestPath(t *testing.T) {
|
||||
urlString := "postgres://user:pass@host.com:5432/path/to?key=value&other=other%20value#some-fragment"
|
||||
|
||||
tables := []TestPathData{
|
||||
{
|
||||
config: &config.Config{URL: urlString, PathIndex: -1},
|
||||
expected: "/path/to",
|
||||
},
|
||||
{
|
||||
config: &config.Config{URL: urlString, PathIndex: 0},
|
||||
expected: "path",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Path(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL path `%v`, should be `%v`", result, table.expected)
|
||||
}
|
||||
}
|
||||
}
|
21
command/port.go
Normal file
21
command/port.go
Normal file
@ -0,0 +1,21 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Port prints out the port from the url.
|
||||
func Port(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Port())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestPortData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestPort(t *testing.T) {
|
||||
|
||||
tables := []TestPortData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "5432",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Port(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Port(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL port `%v`, should be `%v`", result, table.expected)
|
40
command/query.go
Normal file
40
command/query.go
Normal file
@ -0,0 +1,40 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// QueryFlags defines flags for query subcommand.
|
||||
func QueryFlags(cfg *config.Config) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "query-field",
|
||||
Usage: "filter parsed query string by field name",
|
||||
EnvVars: []string{"URL_PARSER_QUERY_FIELD"},
|
||||
Destination: &cfg.QueryField,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Query prints out the query part from url.
|
||||
func Query(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
f := cfg.QueryField
|
||||
|
||||
if len(parts.RawQuery) > 0 {
|
||||
if f != "" {
|
||||
if result := parts.Query().Get(f); result != "" {
|
||||
fmt.Println(result)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(parts.RawQuery)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestQueryData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
QueryField string
|
||||
expected string
|
||||
}
|
||||
@ -20,24 +20,21 @@ func TestQuery(t *testing.T) {
|
||||
|
||||
tables := []TestQueryData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "key=value&other=other%20value",
|
||||
},
|
||||
{
|
||||
urlString: urlString,
|
||||
QueryField: "other",
|
||||
config: &config.Config{URL: urlString, QueryField: "other"},
|
||||
|
||||
expected: "other value",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
set.String("query-field", table.QueryField, "index")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Query(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Query(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL query `%v`, should be `%v`", result, table.expected)
|
21
command/run.go
Normal file
21
command/run.go
Normal file
@ -0,0 +1,21 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Run default command and print out full url.
|
||||
func Run(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if len(parts.String()) > 0 {
|
||||
fmt.Println(parts)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestRunData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestRun(t *testing.T) {
|
||||
|
||||
tables := []TestRunData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: urlString,
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Run(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Run(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL `%v`, should be `%v`", result, table.expected)
|
21
command/scheme.go
Normal file
21
command/scheme.go
Normal file
@ -0,0 +1,21 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Scheme prints out the scheme part from the url.
|
||||
func Scheme(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Scheme)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestSchemeData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestScheme(t *testing.T) {
|
||||
|
||||
tables := []TestSchemeData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "postgres",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Scheme(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = Scheme(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL scheme `%v`, should be `%v`", result, table.expected)
|
23
command/user.go
Normal file
23
command/user.go
Normal file
@ -0,0 +1,23 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// User prints out the user part from url.
|
||||
func User(cfg *config.Config) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
parts := parseURL(cfg.URL)
|
||||
|
||||
if parts.User != nil {
|
||||
if len(parts.User.Username()) > 0 {
|
||||
fmt.Println(parts.User.Username())
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/thegeeklab/url-parser/config"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/zenizh/go-capturer"
|
||||
)
|
||||
|
||||
type TestUserData struct {
|
||||
urlString string
|
||||
config *config.Config
|
||||
expected string
|
||||
}
|
||||
|
||||
@ -19,18 +19,16 @@ func TestUser(t *testing.T) {
|
||||
|
||||
tables := []TestUserData{
|
||||
{
|
||||
urlString: urlString,
|
||||
config: &config.Config{URL: urlString},
|
||||
expected: "user",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
ctx := cli.NewContext(app, nil, nil)
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { User(c) }))
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { _ = User(table.config)(ctx) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL user `%v`, should be `%v`", result, table.expected)
|
15
config/config.go
Normal file
15
config/config.go
Normal file
@ -0,0 +1,15 @@
|
||||
package config
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrEmptyURL = errors.New("no url provided either by \"url\" or \"stdin\"")
|
||||
ErrReadStdin = errors.New("failed to read \"stdin\"")
|
||||
ErrParseURL = errors.New("failed to parse url")
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
URL string
|
||||
QueryField string
|
||||
PathIndex int
|
||||
}
|
20
go.mod
20
go.mod
@ -1,12 +1,18 @@
|
||||
module github.com/thegeeklab/url-parser
|
||||
|
||||
go 1.13
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 // indirect
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/urfave/cli/v2 v2.27.4
|
||||
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||
golang.org/x/sys v0.12.0 // indirect
|
||||
)
|
||||
|
60
go.sum
60
go.sum
@ -1,39 +1,25 @@
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d h1:cVtBfNW5XTHiKQe7jDaDBSh/EVM4XLPutLAGboIXuM0=
|
||||
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
|
||||
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff h1:1CPUrky56AcgSpxz/KfgzQWzfG09u5YOL8MvPYBlrL8=
|
||||
golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014 h1:joucsQqXmyBVxViHCPFjG3hx8JzIFSaym3l3MM/Jsdg=
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8=
|
||||
github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
||||
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04 h1:qXafrlZL1WsJW5OokjraLLRURHiw0OzKHD/RNdspp4w=
|
||||
github.com/zenizh/go-capturer v0.0.0-20211219060012-52ea6c8fed04/go.mod h1:FiwNQxz6hGoNFBC4nIx+CxZhI3nne5RmIOlT/MXcSD4=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
@ -1,17 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Fragment prints out the fragment part from the url
|
||||
func Fragment(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Fragment)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Host prints out the host part from the url
|
||||
func Host(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Hostname())
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Password prints out the password part from url
|
||||
func Password(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if parts.User != nil {
|
||||
pw, _ := parts.User.Password()
|
||||
if len(pw) > 0 {
|
||||
fmt.Println(pw)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// PathFlags defines flags for path subcommand
|
||||
func PathFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "path-index",
|
||||
Usage: "filter parsed path by index",
|
||||
EnvVars: []string{"URL_PARSER_PATH_INDEX"},
|
||||
Value: -1,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Path prints out the path part from url
|
||||
func Path(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
i := ctx.Int("path-index")
|
||||
|
||||
if len(parts.Path) > 0 {
|
||||
if i > -1 {
|
||||
path := strings.Split(parts.Path, "/")
|
||||
|
||||
if i = i + 1; i < len(path) {
|
||||
fmt.Println(path[i])
|
||||
}
|
||||
} else {
|
||||
fmt.Println(parts.Path)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kami-zh/go-capturer"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
type TestPathData struct {
|
||||
urlString string
|
||||
pathIndex int
|
||||
expected string
|
||||
}
|
||||
|
||||
func TestPath(t *testing.T) {
|
||||
urlString := "postgres://user:pass@host.com:5432/path/to?key=value&other=other%20value#some-fragment"
|
||||
|
||||
tables := []TestPathData{
|
||||
{
|
||||
urlString: urlString,
|
||||
pathIndex: -1,
|
||||
expected: "/path/to",
|
||||
},
|
||||
{
|
||||
urlString: urlString,
|
||||
pathIndex: 0,
|
||||
expected: "path",
|
||||
},
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
app := cli.NewApp()
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String("url", table.urlString, "test url")
|
||||
set.Int("path-index", table.pathIndex, "index")
|
||||
|
||||
c := cli.NewContext(app, set, nil)
|
||||
result := strings.TrimSpace(capturer.CaptureStdout(func() { Path(c) }))
|
||||
|
||||
if result != table.expected {
|
||||
t.Fatalf("URL path `%v`, should be `%v`", result, table.expected)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Port prints out the port from the url
|
||||
func Port(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Port())
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// QueryFlags defines flags for query subcommand
|
||||
func QueryFlags() []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "query-field",
|
||||
Usage: "filter parsed query string by field name",
|
||||
EnvVars: []string{"URL_PARSER_QUERY_FIELD"},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Query prints out the query part from url
|
||||
func Query(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
f := ctx.String("query-field")
|
||||
|
||||
if len(parts.RawQuery) > 0 {
|
||||
if f != "" {
|
||||
if result := parts.Query().Get(f); result != "" {
|
||||
fmt.Println(result)
|
||||
}
|
||||
} else {
|
||||
fmt.Println(parts.RawQuery)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Run default command and print out full url
|
||||
func Run(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if len(parts.String()) > 0 {
|
||||
fmt.Println(parts)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// Scheme prints out the scheme part from the url
|
||||
func Scheme(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if len(parts.Scheme) > 0 {
|
||||
fmt.Println(parts.Scheme)
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// User prints out the user part from url
|
||||
func User(ctx *cli.Context) error {
|
||||
parts := parseURL(ctx.String("url"))
|
||||
|
||||
if parts.User != nil {
|
||||
if len(parts.User.Username()) > 0 {
|
||||
fmt.Println(parts.User.Username())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": ["github>thegeeklab/renovate-presets"]
|
||||
"extends": ["github>thegeeklab/renovate-presets:golang"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user