diff --git a/.github/workflows/codacy-coverage-reporter.yml b/.github/workflows/codacy-coverage-reporter.yml new file mode 100644 index 0000000..4d40556 --- /dev/null +++ b/.github/workflows/codacy-coverage-reporter.yml @@ -0,0 +1,63 @@ +name: codacy-coverage-reporter + +on: + push: + tags: + - '*' + pull_request: + +jobs: + codacy-coverage-reporter: + strategy: + matrix: + go-version: [1.17.x] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + # Setup Go + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Cache Go modules + uses: actions/cache@preview + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.OS }}-build-${{ env.cache-name }}- + ${{ runner.OS }}-build- + ${{ runner.OS }}- + + # Install all the dependencies + - name: Install dependencies + run: | + go version + go install github.com/axw/gocov/gocov@latest + go install github.com/AlekSi/gocov-xml@latest + go get -u github.com/jstemmer/go-junit-report + sudo apt-get update -y || true + + # Run build of the application + - name: Run build + run: | + go env -w GOFLAGS=-mod=mod + go mod tidy + go build -v . + + # Run Tests and Coverage + - name: Run Tests and Coverage + run: | + go test -v -coverprofile=coverage.out ./... | tee test.out + cat test.out | go-junit-report > coverage/${{ runner.OS }}-report.xml + gocov convert coverage.out | gocov-xml > coverage/${{ runner.OS }}-report.xml + + - name: Run codacy-coverage-reporter + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: coverage/${{ runner.OS }}-report.xml \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..a226191 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,84 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '38 4 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + go-version: [1.17.x] + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 + + - name: Checkout code + uses: actions/checkout@main + + - name: Run Codacy Analysis CLI + uses: codacy/codacy-analysis-cli-action@master + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + run-gosec: "true" + run-staticcheck: "true" + upload: true + max-allowed-issues: 2147483647 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b473041..d8c303d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,19 +1,15 @@ # This is a basic workflow -name: Go +name: CI -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch on: push: tags: - '*' + pull_request: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # The "build" workflow build: - # The type of runner that the job will run on strategy: matrix: go-version: [1.17] @@ -51,7 +47,10 @@ jobs: # Run build of the application - name: Run build - run: go build -v . + run: | + go env -w GOFLAGS=-mod=mod + go mod tidy + go build -v . # Run vet & lint on the code - name: Run vet & lint diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1e772..4066505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [v1.0.4](https://github.com/mr-pmillz/coinmon-go/tree/v1.0.4) (2021-10-16) + +[Full Changelog](https://github.com/mr-pmillz/coinmon-go/compare/v1.0.3...v1.0.4) + ## [v1.0.3](https://github.com/mr-pmillz/coinmon-go/tree/v1.0.3) (2021-10-16) [Full Changelog](https://github.com/mr-pmillz/coinmon-go/compare/v1.0.2...v1.0.3) diff --git a/README.md b/README.md index 9052c28..ed6684e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,40 @@ # Coinmon-go +[![Donate](https://img.shields.io/badge/Donate-PayPal-yellow.svg)](https://www.paypal.com/donate?business=YR6C4WB5CDZZL&no_recurring=0&item_name=contribute+to+open+source¤cy_code=USD) +[![Donate with Bitcoin](https://en.cryptobadges.io/badge/micro/3Cd54T1EB6WHRcechq1dRCGF6vY2HHhkdk)](https://en.cryptobadges.io/donate/3Cd54T1EB6WHRcechq1dRCGF6vY2HHhkdk) +[![Donate with Ethereum](https://en.cryptobadges.io/badge/micro/0x064AA753EF36e5641E2Ee3C9BbC117F6aFe35F62)](https://en.cryptobadges.io/donate/0x064AA753EF36e5641E2Ee3C9BbC117F6aFe35F62) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/12750b2a6fa44b429f8a3f64d3e7f1b6)](https://www.codacy.com/gh/mr-pmillz/coinmon-go/dashboard?utm_source=github.com&utm_medium=referral&utm_content=mr-pmillz/coinmon-go&utm_campaign=Badge_Grade) +[![Go Report Card](https://goreportcard.com/badge/github.com/mr-pmillz/coinmon-go)](https://goreportcard.com/report/github.com/mr-pmillz/coinmon-go) +![GitHub all releases](https://img.shields.io/github/downloads/mr-pmillz/coinmon-go/total?style=social) +![GitHub Workflow Status](https://img.shields.io/github/workflow/status/mr-pmillz/coinmon-go/CI?style=plastic) +![GitHub repo size](https://img.shields.io/github/repo-size/mr-pmillz/coinmon-go?style=plastic) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/mr-pmillz/coinmon-go?style=plastic) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/mr-pmillz/coinmon-go?style=plastic) +![GitHub commit activity](https://img.shields.io/github/commit-activity/m/mr-pmillz/coinmon-go?style=plastic) + +Table of Contents +================= + +* [Coinmon\-go](#coinmon-go) + * [Install](#install) + * [Usage](#usage) + Get live Crypto Currency prices in the terminal with the quickness ## Install +If you have a version of golang >= 16.X you can install with + +```shell +go install github.com/mr-pmillz/coinmon-go@latest +``` + +If using an older version of golang + +```shell +go get github.com/mr-pmillz/coinmon-go@latest +``` + ```bash go build ``` @@ -25,7 +56,7 @@ Options: ./coinmon-go -t 20 ``` - +![top20.png](https://github.com/mr-pmillz/coinmon-go/blob/master/img/top20.png?raw=true) - Get Specified Coins @@ -33,6 +64,6 @@ Options: ./coinmon-go --find bitcoin,ethereum,cardano,uniswap,dogecoin,chainlink,monero,filecoin,tron,bittorrent ``` - +![find.png](https://github.com/mr-pmillz/coinmon-go/blob/master/img/find.png?raw=true) - By default, `./coinmon-go` with no arguments will just return the top 10 coins by market cap \ No newline at end of file diff --git a/coverage/.gitkeep b/coverage/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod index 4d90b36..0ae0b9d 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,20 @@ -module coinmon-go +module github.com/mr-pmillz/coinmon-go -go 1.16 +go 1.17 require ( github.com/mkideal/cli v0.2.7 github.com/olekukonko/tablewriter v0.0.5 - golang.org/x/text v0.3.6 + golang.org/x/text v0.3.7 +) + +require ( + github.com/labstack/gommon v0.3.0 // indirect + github.com/mattn/go-colorable v0.1.7 // indirect + github.com/mattn/go-isatty v0.0.12 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mkideal/expr v0.1.0 // indirect + golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect + golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 // indirect ) diff --git a/go.sum b/go.sum index 141c915..9b29f82 100644 --- a/go.sum +++ b/go.sum @@ -43,8 +43,8 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 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= diff --git a/main.go b/main.go index 1e9c1ea..b6be27a 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,9 @@ package main import ( - "coinmon-go/utils" "encoding/json" "fmt" + "github.com/mr-pmillz/coinmon-go/utils" "net/http" "os" "strconv" @@ -36,10 +36,10 @@ type Data struct { Rank string `json:"rank"` Symbol string `json:"symbol"` Name string `json:"name"` - Supply string `json:"supply"` + Supply string `json:"supply,omitempty"` MaxSupply string `json:"maxSupply,omitempty"` - MarketCapUSD string `json:"marketCapUsd"` - VolumeUSD24Hr string `json:"volumeUsd24Hr"` + MarketCapUSD string `json:"marketCapUsd,omitempty"` + VolumeUSD24Hr string `json:"volumeUsd24Hr,omitempty"` PriceUSD string `json:"priceUsd"` ChangePercent24Hr string `json:"changePercent24Hr"` Vwap24Hr string `json:"vwap24Hr"` diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..cd5d011 --- /dev/null +++ b/main_test.go @@ -0,0 +1,110 @@ +package main + +import "testing" + +func Test_getJSON(t *testing.T) { + type args struct { + url string + target interface{} + } + coinData := new(CoinData) + tests := []struct { + name string + args args + wantErr bool + }{ + {name: "Test_getJSON 1", args: args{ + url: "https://api.coincap.io/v2/assets?limit=10", + target: coinData, + }, wantErr: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := getJSON(tt.args.url, tt.args.target); (err != nil) != tt.wantErr { + t.Errorf("getJSON() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +//func Test_prettyFloatString(t *testing.T) { +// type args struct { +// num string +// percent bool +// nearestThousandFMT bool +// prec4 bool +// } +// tests := []struct { +// name string +// args args +// want string +// wantErr bool +// }{ +// // TODO: Add test cases. +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// got, err := prettyFloatString(tt.args.num, tt.args.percent, tt.args.nearestThousandFMT, tt.args.prec4) +// if (err != nil) != tt.wantErr { +// t.Errorf("prettyFloatString() error = %v, wantErr %v", err, tt.wantErr) +// return +// } +// if got != tt.want { +// t.Errorf("prettyFloatString() = %v, want %v", got, tt.want) +// } +// }) +// } +//} +// +//func Test_printTable(t *testing.T) { +// type args struct { +// coinData *CoinData +// } +// tests := []struct { +// name string +// args args +// wantErr bool +// }{ +// // TODO: Add test cases. +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// if err := printTable(tt.args.coinData); (err != nil) != tt.wantErr { +// t.Errorf("printTable() error = %v, wantErr %v", err, tt.wantErr) +// } +// }) +// } +//} +// +//func Test_printTotalMarketCap(t *testing.T) { +// type args struct { +// coinData *CoinData +// } +// tests := []struct { +// name string +// args args +// wantErr bool +// }{ +// // TODO: Add test cases. +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// if err := printTotalMarketCap(tt.args.coinData); (err != nil) != tt.wantErr { +// t.Errorf("printTotalMarketCap() error = %v, wantErr %v", err, tt.wantErr) +// } +// }) +// } +//} +// +//func Test_main(t *testing.T) { +// tests := []struct { +// name string +// }{ +// // TODO: Add test cases. +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// main() +// }) +// } +//}