From e5f4f912c5cc9ab736da06f0681e3749e9630aa7 Mon Sep 17 00:00:00 2001 From: Benjamin Morrison Date: Wed, 15 Dec 2021 10:32:00 -0500 Subject: [PATCH] Dependencies, go version update, and Makefile fixes (#44) * update all dependencies and require go1.16 * fixed Makefile: When the deps target was added in November 2020, it became the default make target. When make was called without arguments, it would install stuffbin and exit without building hopp-cli. Added an 'all' target as the default target that installs stuffbin and builds hopp-cli. Cleaned up all of the targets. Changed the deps target to use the idiomatic 'go install' instead of 'go get' to prevent mangling go.mod when installing stuffbin. Removed the 'update' target as it's redundant re: git pull. * updated travis build manifest to use go-1.16.x * changed go.mod path to reflect new repository location it still mentioned the old pwcli repo. also updated cli.go 'methods' import statement to reflect this. * update old references to ioutil package. ioutil is deprecated. ioutil.ReadAll() is deprecated in favor of io.ReadAll() ioutil.ReadFile() is deprecated in favor of os.ReadFile() * wrap errors when bubbling up * hoop.bin was in .gitignore instead of hopp.bin * only install bin dep stuffbin if it isn't already installed Authored by: @gbmor --- .gitignore | 2 +- .travis.yml | 2 +- Makefile | 53 +++++++++----------------- cli.go | 2 +- go.mod | 26 +++++++------ go.sum | 89 ++++++++++++++++++++++++------------------- methods/basic.go | 4 +- methods/fns.go | 8 ++-- methods/get.go | 4 +- methods/send.go | 19 +++++---- methods/validation.go | 8 ++-- 11 files changed, 108 insertions(+), 109 deletions(-) diff --git a/.gitignore b/.gitignore index 99e36be..8e622c1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ *.so *.dylib hopp-cli -hoop.bin +hopp.bin dist/ # Test binary, built with `go test -c` diff --git a/.travis.yml b/.travis.yml index 09d50f4..4a1ed35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: false language: go go: - - "1.13" + - "1.16.x" before_script: - go get -v - go build diff --git a/Makefile b/Makefile index ca5ea23..24adf76 100644 --- a/Makefile +++ b/Makefile @@ -1,56 +1,41 @@ BIN:=hopp.bin +BINSTUFFED:=hopp-cli PREFIX?=/usr/local BINDIR?=$(PREFIX)/bin VERSION?=$(shell git tag | grep ^v | sort -V | tail -n 1) STATIC := ./templates/index.html ./templates/template.md:/template.md +all: deps build + +.PHONY: deps deps: - go get -u github.com/knadh/stuffbin/... + @printf '%s\n' 'Checking binary dependencies...' + @if [ ! -f "$(shell go env GOPATH)/bin/stuffbin" ]; then printf '%s\n' 'Installing stuffbin to GOPATH' && go install github.com/knadh/stuffbin/stuffbin@latest; fi -build: cli.go go.mod go.sum - @echo - @echo Building hopp-cli. This may take a minute or two. - @echo - go build -o ${BIN} -ldflags="-s -w -X 'main.buildVersion=${VERSION}'" *.go - stuffbin -a stuff -in ${BIN} -out ${BIN} ${STATIC} - @echo - @echo ...Done\! +.PHONY: build +build: + @printf '%s\n' 'Building hopp-cli. This may take a minute or two.' + go build -o ${BIN} -ldflags="-s -w -X 'main.buildVersion=${VERSION}'" + $(shell go env GOPATH)/bin/stuffbin -a stuff -in ${BIN} -out ${BINSTUFFED} ${STATIC} + rm ${BIN} .PHONY: clean clean: - @echo - @echo Cleaning... - @echo - go clean - @echo - @echo ...Done\! - -.PHONY: update -update: - @echo - @echo Updating from upstream repository... - @echo - git pull --rebase origin master - @echo - @echo ...Done\! + @printf '%s\n' 'Cleaning...' + @go clean + @if [ -f 'hopp-cli' ]; then rm hopp-cli; fi + @if [ -f 'hopp.bin' ]; then rm hopp.bin; fi .PHONY: install install: - @echo - @echo Installing hopp-cli... - @echo + @printf '%s\n' 'Installing hopp-cli...' install -m755 hopp-cli $(BINDIR) - @echo - @echo ...Done\! .PHONY: uninstall uninstall: - @echo - @echo Uninstalling hopp-cli... - @echo + @printf '%s\n' 'Uninstalling hopp-cli...' rm -f $(BINDIR)/hopp-cli - @echo - @echo ...Done\! + .PHONY: pack-releases pack-releases: $(foreach var,$(RELEASE_BUILDS),stuffbin -a stuff -in ${var} -out ${var} ${STATIC};) \ No newline at end of file diff --git a/cli.go b/cli.go index db76f79..02e1b77 100644 --- a/cli.go +++ b/cli.go @@ -5,8 +5,8 @@ import ( "log" "os" - mets "github.com/athul/pwcli/methods" "github.com/fatih/color" + mets "github.com/hoppscotch/hopp-cli/methods" "github.com/urfave/cli" ) diff --git a/go.mod b/go.mod index 4a9b0aa..f5d3e5e 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,20 @@ -module github.com/athul/pwcli +module github.com/hoppscotch/hopp-cli -go 1.13 +go 1.16 require ( - github.com/fatih/color v1.9.0 + github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect + github.com/fatih/color v1.13.0 github.com/knadh/stuffbin v1.1.0 - github.com/olekukonko/tablewriter v0.0.4 - github.com/pkg/browser v0.0.0-20201112035734-206646e67786 - github.com/stretchr/testify v1.4.0 // indirect - github.com/tidwall/pretty v1.0.2 - github.com/urfave/cli v1.22.2 - github.com/yosssi/gohtml v0.0.0-20190915184251-7ff6f235ecaf - go.uber.org/multierr v1.6.0 - golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/olekukonko/tablewriter v0.0.5 + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 + github.com/tidwall/pretty v1.2.0 + github.com/urfave/cli v1.22.5 + github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.7.0 + golang.org/x/net v0.0.0-20211205041911-012df41ee64c // indirect + golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect ) diff --git a/go.sum b/go.sum index 9211597..8cc676b 100644 --- a/go.sum +++ b/go.sum @@ -1,55 +1,66 @@ -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 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/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/knadh/stuffbin v1.1.0 h1:f5S5BHzZALjuJEgTIOMC9NidEnBJM7Ze6Lu1GHR/lwU= github.com/knadh/stuffbin v1.1.0/go.mod h1:yVCFaWaKPubSNibBsTAJ939q2ABHudJQxRWZWV5yh+4= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8= -github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA= -github.com/pkg/browser v0.0.0-20201112035734-206646e67786 h1:4Gk0Dsp90g2YwfsxDOjvkEIgKGh+2R9FlvormRycveA= -github.com/pkg/browser v0.0.0-20201112035734-206646e67786/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= 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/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +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/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU= -github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/yosssi/gohtml v0.0.0-20190915184251-7ff6f235ecaf h1:VA200mPTYh9FWY8zKX5ctXCtNk78HUez8ecTdsQGhoo= -github.com/yosssi/gohtml v0.0.0-20190915184251-7ff6f235ecaf/go.mod h1:+ccdNT0xMY1dtc5XBxumbYfOUhmduiGudqaDgD2rVRE= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= +github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4 h1:0sw0nJM544SpsihWx1bkXdYLQDlzRflMgFJQ4Yih9ts= +github.com/yosssi/gohtml v0.0.0-20201013000340-ee4748c638f4/go.mod h1:+ccdNT0xMY1dtc5XBxumbYfOUhmduiGudqaDgD2rVRE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec= +go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +golang.org/x/net v0.0.0-20211205041911-012df41ee64c h1:7SfqwP5fxEtl/P02w5IhKc86ziJ+A25yFrkVgoy2FT8= +golang.org/x/net v0.0.0-20211205041911-012df41ee64c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/methods/basic.go b/methods/basic.go index e6dd207..f28e939 100644 --- a/methods/basic.go +++ b/methods/basic.go @@ -36,7 +36,7 @@ func BasicRequestWithBody(c *cli.Context, method string) (string, error) { req, err := http.NewRequest(method, url, bytes.NewBuffer(body)) if err != nil { - return "", fmt.Errorf("Error creating request: %s", err.Error()) + return "", fmt.Errorf("error creating request: %w", err) } req.Header.Set("Content-Type", Contenttypes[c.String("ctype")]) @@ -59,7 +59,7 @@ func BasicRequestWithBody(c *cli.Context, method string) (string, error) { client := getHTTPClient() resp, err := client.Do(req) if err != nil { - return "", fmt.Errorf("Error sending request: %s", err.Error()) + return "", fmt.Errorf("error sending request: %w", err) } defer resp.Body.Close() diff --git a/methods/fns.go b/methods/fns.go index 3d80fd8..836db29 100644 --- a/methods/fns.go +++ b/methods/fns.go @@ -3,7 +3,7 @@ package methods import ( "encoding/base64" "fmt" - "io/ioutil" + "io" "net/http" "strings" @@ -19,9 +19,9 @@ func formatresp(resp *http.Response) (string, error) { c := color.New(color.FgHiCyan) magenta := color.New(color.FgHiMagenta) - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { - return "", fmt.Errorf("Error reading response body: %s", err.Error()) + return "", fmt.Errorf("error reading response body: %w", err) } for key, value := range resp.Header { @@ -50,7 +50,7 @@ func basicAuth(username, password string) string { return base64.StdEncoding.EncodeToString([]byte(auth)) } -//Contenttypes are used in Place for ctypes for sending requests +// Contenttypes are used in Place for ctypes for sending requests var Contenttypes = map[string]string{ "html": "text/html", "js": "application/json", diff --git a/methods/get.go b/methods/get.go index 010ead6..df4a9e5 100644 --- a/methods/get.go +++ b/methods/get.go @@ -17,7 +17,7 @@ func Getbasic(c *cli.Context) (string, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { - return "", fmt.Errorf("Error creating request: %s", err.Error()) + return "", fmt.Errorf("error creating request: %w", err) } if c.String("token") != "" { @@ -38,7 +38,7 @@ func Getbasic(c *cli.Context) (string, error) { client := getHTTPClient() resp, err := client.Do(req) if err != nil { - return "", fmt.Errorf("Error sending request: %s", err.Error()) + return "", fmt.Errorf("error sending request: %w", err) } defer resp.Body.Close() diff --git a/methods/send.go b/methods/send.go index 48af85b..b6f50f1 100644 --- a/methods/send.go +++ b/methods/send.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "log" "net/http" "os" @@ -16,9 +15,9 @@ import ( "go.uber.org/multierr" ) -//ReadCollection reads the `hoppScotch-collection.json` File and returns a the Loaded Collection Struct +// ReadCollection reads the `hoppScotch-collection.json` File and returns a the Loaded Collection Struct func ReadCollection(filename string) ([]Collection, error) { - data, err := ioutil.ReadFile(filename) + data, err := os.ReadFile(filename) if string(data) == "" { return nil, errors.New("PATH is needed") } @@ -29,7 +28,7 @@ func ReadCollection(filename string) ([]Collection, error) { var jsonArr []Collection err = json.Unmarshal([]byte(data), &jsonArr) // Unmarshal JSON to Collection Type if err != nil { - return nil, fmt.Errorf("Error parsing JSON: %s", err.Error()) + return nil, fmt.Errorf("error parsing JSON: %w", err) } return jsonArr, nil } @@ -116,7 +115,7 @@ func (c *Collection) sendGET(req Requests) (string, string, string, error) { } } if err != nil { - return "", "", "", fmt.Errorf("Error creating request: %s", err.Error()) + return "", "", "", fmt.Errorf("error creating request: %w", err) } if req.Token != "" { @@ -133,7 +132,7 @@ func (c *Collection) sendGET(req Requests) (string, string, string, error) { client := getHTTPClient() resp, err := client.Do(reqHTTP) if err != nil { - return "", "", "", fmt.Errorf("Error sending request: %s", err.Error()) + return "", "", "", fmt.Errorf("error sending request: %w", err) } defer resp.Body.Close() // paramstr is suffixed with a `?` to append to the URL @@ -177,7 +176,7 @@ func (c *Collection) sendPOST(req Requests, method string) (string, string, erro finalBytes, err := json.RawMessage(jsonStr).MarshalJSON() // Marshal to JSON from strings if err != nil { - return "", "", fmt.Errorf("Error Marhsaling JSON: %s", err.Error()) + return "", "", fmt.Errorf("error Marhsaling JSON: %w", err) } reqHTTP, err := http.NewRequest(method, url, bytes.NewBuffer(finalBytes)) if len(req.Headers) > 0 { @@ -186,7 +185,7 @@ func (c *Collection) sendPOST(req Requests, method string) (string, string, erro } } if err != nil { - return "", "", fmt.Errorf("Error creating request: %s", err.Error()) + return "", "", fmt.Errorf("error creating request: %w", err) } reqHTTP.Header.Set("Content-Type", req.Ctype) // Set Content type to said Ctype in Collection @@ -203,7 +202,7 @@ func (c *Collection) sendPOST(req Requests, method string) (string, string, erro client := getHTTPClient() resp, err := client.Do(reqHTTP) if err != nil { - return "", "", fmt.Errorf("Error sending request: %s", err.Error()) + return "", "", fmt.Errorf("error sending request: %w", err) } defer resp.Body.Close() @@ -245,7 +244,7 @@ func (c *Collection) getDatafromFolders() error { return nil } -//genTables generate the output in Tabular Form +// genTables generate the output in Tabular Form func genTables(data [][]string) { table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Name", "URL", "Method", "Status", "Code"}) diff --git a/methods/validation.go b/methods/validation.go index 022932d..2dd0ded 100644 --- a/methods/validation.go +++ b/methods/validation.go @@ -1,23 +1,23 @@ package methods import ( - "fmt" + "errors" "net/url" "strings" ) func checkURL(urlStr string) (string, error) { if urlStr == "" { - return "", fmt.Errorf("URL is needed") + return "", errors.New("URL is needed") } prefixCheck := strings.HasPrefix(urlStr, "http://") || strings.HasPrefix(urlStr, "https://") if !prefixCheck { - return "", fmt.Errorf("URL missing protocol or contains invalid protocol") + return "", errors.New("URL missing protocol or contains invalid protocol") } if _, err := url.Parse(urlStr); err != nil { - return "", fmt.Errorf("URL is invalid") + return "", errors.New("URL is invalid") } return urlStr, nil