Skip to content

Commit ff61a73

Browse files
committed
feat(project): add first version
0 parents  commit ff61a73

File tree

11 files changed

+758
-0
lines changed

11 files changed

+758
-0
lines changed

.editorconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = LF
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[Makefile]
12+
indent_style = tab
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[*.go]
18+
indent_style = tab
19+
20+
[*.yml]
21+
indent_size = 2
22+
23+
[*.yaml]
24+
indent_size = 2
25+
26+
[*.yml.dist]
27+
indent_size = 2

.github/workflows/go.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ^1.17
20+
id: go
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v2
24+
25+
- name: Build
26+
run: go build -race -v ./...
27+
28+
- name: Test
29+
run: go test -race -cover -coverprofile ./coverage.out ./...
30+
31+
- name: Coverage
32+
id: coverage
33+
run: |
34+
go tool cover -func ./coverage.out | tee -a coverage.txt
35+
echo "COVERAGE_CONTENT<<EOF" >> $GITHUB_ENV
36+
cat coverage.txt >> $GITHUB_ENV
37+
echo "EOF" >> $GITHUB_ENV
38+
39+
40+
- uses: actions/github-script@v4
41+
if: github.event_name == 'pull_request'
42+
env:
43+
COVERAGE_CONTENT: "${{ env.COVERAGE_CONTENT }}"
44+
with:
45+
github-token: ${{ secrets.GITHUB_TOKEN }}
46+
script: |
47+
const output = `Code Coverage\n
48+
\`\`\`\n
49+
${process.env.COVERAGE_CONTENT}
50+
\`\`\`
51+
52+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
53+
54+
const response = await github.issues.listComments({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
issue_number: context.issue.number,
58+
});
59+
60+
var comments = response.data;
61+
62+
console.log(comments);
63+
64+
if (comments.length > 0) {
65+
comments = comments.filter(comment => comment.body.includes('Code Coverage') && comment.user.type === 'Bot');
66+
}
67+
68+
if (comments.length > 0) {
69+
const comment = comments.shift();
70+
71+
github.issues.updateComment({
72+
issue_number: context.issue.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
comment_id: comment.id,
76+
body: output
77+
})
78+
} else {
79+
github.issues.createComment({
80+
issue_number: context.issue.number,
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
body: output
84+
})
85+
}
86+
87+
- name: Run golangci-lint
88+
uses: golangci/golangci-lint-action@v2
89+
with:
90+
version: v1.41.1
91+
skip-pkg-cache: true
92+
93+
- name: Coveralls
94+
uses: shogo82148/actions-goveralls@v1
95+
with:
96+
path-to-profile: coverage.out

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.out
3+
4+
vendor/
5+
6+
*.swp

.golangci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
run:
2+
concurrency: 4
3+
deadline: 1m
4+
issues-exit-code: 1
5+
tests: false
6+
skip-files:
7+
- ".*_mock\\.go"
8+
- "mock_.*\\.go"
9+
- ".*/pkg/mod/.*$"
10+
11+
output:
12+
format: colored-line-number
13+
print-issued-lines: true
14+
print-linter-name: true
15+
16+
linters-settings:
17+
errcheck:
18+
check-type-assertions: false
19+
check-blank: false
20+
govet:
21+
check-shadowing: false
22+
revive:
23+
ignore-generated-header: true
24+
severity: warning
25+
gofmt:
26+
simplify: true
27+
gocyclo:
28+
min-complexity: 18
29+
maligned:
30+
suggest-new: true
31+
dupl:
32+
threshold: 80
33+
goconst:
34+
min-len: 4
35+
min-occurrences: 3
36+
depguard:
37+
list-type: blacklist
38+
include-go-root: false
39+
packages:
40+
- github.com/davecgh/go-spew/spew
41+
misspell:
42+
locale: US
43+
ignore-words:
44+
- cancelled
45+
goimports:
46+
local-prefixes: go.opentelemetry.io
47+
48+
49+
linters:
50+
disable-all: true
51+
enable:
52+
- deadcode
53+
- depguard
54+
- errcheck
55+
- gas
56+
- goconst
57+
- gocyclo
58+
- gofmt
59+
- revive
60+
- govet
61+
- ineffassign
62+
- megacheck
63+
- misspell
64+
- structcheck
65+
- typecheck
66+
- unconvert
67+
- varcheck
68+
- gosimple
69+
- staticcheck
70+
- unused
71+
- asciicheck
72+
- bodyclose
73+
- dogsled
74+
- dupl
75+
- durationcheck
76+
- errorlint
77+
- exhaustive
78+
- exportloopref
79+
- forbidigo
80+
- forcetypeassert
81+
- gocritic
82+
- godot
83+
- gosec
84+
- ifshort
85+
- nestif
86+
- nilerr
87+
- nlreturn
88+
- noctx
89+
- prealloc
90+
- predeclared
91+
- sqlclosecheck
92+
- tagliatelle
93+
- whitespace
94+
- wsl
95+
fast: false

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Axel Etcheverry
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.PHONY: all clean test cover travis lint
2+
3+
release:
4+
@echo "Release v$(version)"
5+
@git pull
6+
@git checkout master
7+
@git pull
8+
@git checkout develop
9+
@git flow release start $(version)
10+
@git flow release finish $(version) -p -m "Release v$(version)"
11+
@git checkout develop
12+
@echo "Release v$(version) finished."
13+
14+
all: test
15+
16+
clean:
17+
@go clean -i ./...
18+
19+
coverage.out: $(shell find . -type f -print | grep -v vendor | grep "\.go")
20+
@go test -race -cover -coverprofile ./coverage.out.tmp ./...
21+
@cat ./coverage.out.tmp | grep -v '.pb.go' | grep -v 'mock_' > ./coverage.out
22+
@rm ./coverage.out.tmp
23+
24+
test: coverage.out
25+
26+
lint:
27+
@golangci-lint run
28+
29+
cover: coverage.out
30+
@echo ""
31+
@go tool cover -func ./coverage.out
32+

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Hyperscale InputFilter [![Last release](https://img.shields.io/github/release/hyperscale-stack/inputfilter.svg)](https://github.com/hyperscale-stack/inputfilter/releases/latest) [![Documentation](https://godoc.org/github.com/hyperscale-stack/inputfilter?status.svg)](https://godoc.org/github.com/hyperscale-stack/inputfilter)
2+
====================
3+
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/hyperscale-stack/inputfilter)](https://goreportcard.com/report/github.com/hyperscale-stack/inputfilter)
5+
6+
| Branch | Status | Coverage |
7+
|---------|--------|----------|
8+
| master | [![Build Status](https://github.com/hyperscale-stack/inputfilter/workflows/Go/badge.svg?branch=master)](https://github.com/hyperscale-stack/inputfilter/actions?query=workflow%3AGo) | [![Coveralls](https://img.shields.io/coveralls/hyperscale-stack/inputfilter/master.svg)](https://coveralls.io/github/hyperscale-stack/inputfilter?branch=master) |
9+
10+
The Hyperscale InputFilter library provides a simple inputfilter chaining mechanism by which multiple filters and validator may be applied to a single datum in a user-defined order.
11+
12+
## Example
13+
14+
Filter by `map[string]interface{}`
15+
16+
```go
17+
package main
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/hyperscale-stack/filter"
23+
"github.com/hyperscale-stack/validator"
24+
"github.com/hyperscale-stack/inputfilter"
25+
)
26+
27+
func main() {
28+
i := New(map[string]InputDefinition{
29+
"*": {
30+
Filters: []filter.Filter{
31+
filter.NewStringToLowerFilter(),
32+
},
33+
},
34+
"url": {
35+
Filters: []filter.Filter{
36+
filter.NewURLFilter(),
37+
},
38+
},
39+
"id": {
40+
Validators: []validator.Validator{
41+
validator.NewUUIDValidator(),
42+
},
43+
},
44+
})
45+
46+
data, errs := i.FilterMap(map[string]interface{}{
47+
"id": "9D2C8507-5F9D-4CB0-A098-2E307B39DC91",
48+
"url": "HTTPS://google.COM",
49+
})
50+
// return
51+
// map[string]interface{}{
52+
// "id": "9d2c8507-5f9d-4cb0-a098-2e307b39dc91",
53+
// "url": "https://google.com",
54+
// }
55+
}
56+
57+
```
58+
59+
60+
Filter by `url.Values`
61+
62+
```go
63+
package main
64+
65+
import (
66+
"fmt"
67+
68+
"github.com/hyperscale-stack/filter"
69+
"github.com/hyperscale-stack/validator"
70+
"github.com/hyperscale-stack/inputfilter"
71+
)
72+
73+
func main() {
74+
i := New(map[string]InputDefinition{
75+
"*": {
76+
Filters: []filter.Filter{
77+
filter.NewStringToLowerFilter(),
78+
},
79+
},
80+
"url": {
81+
Filters: []filter.Filter{
82+
filter.NewURLFilter(),
83+
},
84+
},
85+
"id": {
86+
Validators: []validator.Validator{
87+
validator.NewUUIDValidator(),
88+
},
89+
},
90+
})
91+
92+
values := url.Values{}
93+
values.Set("id", "9D2C8507-5F9D-4CB0-A098-2E307B39DC91")
94+
values.Set("url", "HTTPS://google.COM")
95+
96+
data, errs := i.FilterValues(values)
97+
// return
98+
// url.Values{
99+
// "id": []string{"9d2c8507-5f9d-4cb0-a098-2e307b39dc91"},
100+
// "url": []string{"https://google.com"},
101+
// }
102+
}
103+
104+
```
105+
106+
107+
## License
108+
109+
Hyperscale Filter is licensed under [the MIT license](LICENSE.md).

0 commit comments

Comments
 (0)