Skip to content

Commit c7c8806

Browse files
Base off of third party VAT package we currently use (#2)
* Update from https://github.com/dannyvankooten/vat * Fix github actions I hope * Some github action changes * Do not include linter as dependency. Only run for github actions * Bah, just use golangci-lint's own github action * Test github lint action to see if it's working * Fix linter issue * Uh oh, IE VAT numbers are not working... * Change some test error messages * Change VAT number to a different one I found online * Update README.md to user Ireland example Co-authored-by: Chris Twomey <[email protected]> * Mock VIES call in tests * Make linter happy * Mixed up vat number and country code in the tests * use strconv to format boolean --------- Co-authored-by: Chris Twomey <[email protected]>
1 parent 0282b39 commit c7c8806

27 files changed

+1000
-844
lines changed

.github/workflows/build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: build
2+
on: [ push, pull_request ]
3+
jobs:
4+
5+
build:
6+
name: Build
7+
runs-on: ubuntu-latest
8+
steps:
9+
10+
- name: Set up Go
11+
uses: actions/setup-go@v4
12+
with:
13+
go-version: 1.21
14+
15+
- name: Check out code into the Go module directory
16+
uses: actions/checkout@v4
17+
18+
- name: Get dependencies
19+
run: |
20+
go get -v -t -d ./...
21+
22+
- name: Build
23+
run: go build .
24+
25+
- name: Lint
26+
uses: golangci/[email protected]
27+
28+
- name: Test
29+
run: ./bin/test
30+
31+
- name: Coverage
32+
run: ./bin/coverage

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/vendor
1+
vendor
2+
c.out

.golangci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
run:
2+
skip-dirs:
3+
- testdata
4+
deadline: 240s
5+
tests: true
6+
7+
linters:
8+
disable-all: true
9+
enable:
10+
- govet
11+
- revive
12+
- unused
13+
- errcheck
14+
- staticcheck
15+
- ineffassign
16+
- unconvert
17+
- goimports
18+
- misspell
19+
- lll
20+
- nakedret
21+
- gocritic
22+
23+
linters-settings:
24+
lll:
25+
line-length: 120
26+
issues:
27+
exclude-use-default: false

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

Gopkg.lock

Lines changed: 0 additions & 15 deletions
This file was deleted.

Gopkg.toml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,77 @@
1-
[![Build Status](https://travis-ci.com/Teamwork/vat.svg?branch=master)](https://travis-ci.com/Teamwork/vat)
1+
Package vat
2+
===
23

3-
# vat
4-
VAT matching and validation in Go
4+
![Build](https://github.com/Teamwork/vat/actions/workflows/build.yml/badge.svg)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/Teamwork/vat)](https://goreportcard.com/report/github.com/Teamwork/vat)
6+
[![GoDoc](https://godoc.org/github.com/Teamwork/vat?status.svg)](https://godoc.org/github.com/Teamwork/vat)
7+
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/teamwork/vat/master/LICENSE)
8+
9+
Package for validating VAT numbers & retrieving VAT rates (from [ibericode/vat-rates](https://github.com/ibericode/vat-rates)) in Go.
10+
11+
Based on https://github.com/dannyvankooten/vat
12+
13+
## Installation
14+
15+
Use go get.
16+
17+
```
18+
go get github.com/teamwork/vat
19+
```
20+
21+
Then import the package into your own code.
22+
23+
```
24+
import "github.com/teamwork/vat"
25+
```
526

627
## Usage
728

8-
See http://godoc.org/github.com/Teamwork/vat for usage and examples
29+
### Validating VAT numbers
30+
31+
VAT numbers can be validated by format, existence or both. VAT numbers are looked up using the [VIES VAT validation API](http://ec.europa.eu/taxation_customs/vies/).
32+
33+
```go
34+
package main
35+
36+
import "github.com/teamwork/vat"
37+
38+
func main() {
39+
// Validate number by format + existence
40+
validity, err := vat.ValidateNumber("NL123456789B01")
41+
42+
// Validate number format
43+
validity, err := vat.ValidateNumberFormat("NL123456789B01")
44+
45+
// Validate number existence
46+
validity, err := vat.ValidateNumberExistence("NL123456789B01")
47+
}
48+
```
49+
50+
### Retrieving VAT rates
51+
52+
> This package relies on a [community maintained repository of vat rates](https://github.com/ibericode/vat-rates). We invite you to toggle notifications for that repository and contribute changes to VAT rates in your country once they are announced.
53+
54+
To get VAT rate periods for a country, first get a CountryRates struct using the country's ISO-3166-1-alpha2 code.
55+
56+
You can get the rate that is currently in effect using the `GetRate` function.
57+
58+
```go
59+
package main
60+
61+
import (
62+
"fmt"
63+
"github.com/teamwork/vat"
64+
)
65+
66+
func main() {
67+
c, err := vat.GetCountryRates("IE")
68+
r, err := c.GetRate("standard")
69+
70+
fmt.Printf("Standard VAT rate for IE is %.2f", r)
71+
// Output: Standard VAT rate for IE is 23.00
72+
}
73+
```
74+
75+
## License
76+
77+
MIT licensed. See the LICENSE file for details.

bin/coverage

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
11
#!/bin/bash
22

3-
usage="Run coverage analyses and send it to Codecov."
4-
53
# Setup
64
#######
75
set -euC
86
root="$(cd "$(dirname "$0")/.." && pwd)"
9-
. "$root/bin/start"
7+
# shellcheck source=load-settings
8+
. "$root/bin/load-settings"
109

1110
# Run action
1211
############
1312

14-
# Only test packages with actual test files.
15-
test_pkgs=$(find -name "*_test.go" |
16-
grep -v /vendor/ |
17-
xargs dirname |
18-
sort -u |
19-
sed -e "s#^\.#$pkgname#")
20-
21-
# Pass all packages to -coverpkg to list coverage for all packages, even those
22-
# without tests.
23-
allpkg=$(go list -tags="$test_tags" ./... |
24-
grep -v /vendor/ |
25-
tr '\n' , |
26-
sed -e 's/,$//')
27-
28-
# Cache
29-
go test -i -covermode=count -tags="$test_tags" $(go list ./... | grep -v /vendor/)
30-
31-
$pre_test_func
32-
33-
echo 'mode: count' >| coverage.txt
34-
for pkg in $test_pkgs; do
35-
go test \
36-
-tags="$test_tags" \
37-
-covermode=count \
38-
-coverprofile=profile.out \
39-
-coverpkg=$allpkg \
40-
$pkg 2>&1 | grep -v 'warning: no packages being tested depend on '
41-
42-
if [ -f profile.out ]; then
43-
tail -n+2 profile.out >> coverage.txt
44-
rm profile.out
13+
extract_tags() {
14+
local tags=""
15+
16+
while :; do
17+
[ $# = 0 ] && break
18+
19+
# -tags foo
20+
# -tags 'foo bar'
21+
if [ "$1" = "-tags" ]; then
22+
shift
23+
tags="$tags $1"
24+
# -tags=foo
25+
# -tags='foo bar'
26+
elif echo "$1" | grep -q '^-tags='; then
27+
tags="$tags $(echo "$1" | cut -d= -f2-)"
28+
fi
29+
30+
shift
31+
done
32+
33+
echo $tags
34+
}
35+
tags=$(extract_tags "$@")
36+
[ -z "$tags" ] || tags="-tags $tags"
37+
38+
echo 'mode: atomic' >| c.out
39+
40+
IFS=$'\n'
41+
for dir in $(go list -f '{{.Dir}} {{.ImportPath}}' $($tags) ./... | grep -v cmd);
42+
do
43+
IFS=' '
44+
read -a dirParts <<< "$dir"
45+
path="${dirParts[0]}"
46+
pkg="${dirParts[1]}"
47+
48+
"$root/bin/test" \
49+
-coverprofile=$path/c.out.tmp \
50+
-coverpkg=./... \
51+
"$@" $pkg
52+
if [ -f $path/c.out.tmp ]
53+
then
54+
cat $path/c.out.tmp | tail -n +2 >> c.out
55+
rm $path/c.out.tmp
4556
fi
4657
done
4758

48-
# The token is optional for public repos.
49-
[ -n "${codecov_token:-}" ] && codecov_token="-t $codecov_token"
50-
51-
if [ -n ${TRAVIS} ]; then
52-
bash <(curl -s https://codecov.io/bash) $codecov_token
53-
else
54-
bash <(curl -s https://codecov.io/bash) \
55-
$codecov_token \
56-
-B $(git rev-parse --abbrev-ref HEAD) \
57-
-C $(git rev-parse HEAD)
58-
fi
59+
go tool cover -func c.out | grep '^total'

0 commit comments

Comments
 (0)