Skip to content

Commit b5770a0

Browse files
committed
Initial commit
0 parents  commit b5770a0

15 files changed

+1182
-0
lines changed

.github/workflows/release.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags: [ 'v*.*.*' ]
9+
10+
workflow_dispatch:
11+
inputs:
12+
releaseTag:
13+
description: 'Existing git tag to be released (i.e. v1.0.0)'
14+
required: true
15+
16+
jobs:
17+
18+
test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Setup Go environment
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: '1.17'
25+
26+
- name: Checkout code
27+
uses: actions/checkout@v2
28+
with:
29+
# https://github.com/actions/checkout/issues/100
30+
fetch-depth: 0
31+
32+
- name: Install test tools
33+
run: |
34+
make test-tools
35+
36+
- name: Run Tests
37+
run: |
38+
make test
39+
40+
release:
41+
runs-on: ubuntu-latest
42+
needs: test
43+
outputs:
44+
RELEASE_TAG: ${{ steps.env.outputs.RELEASE_TAG }}
45+
steps:
46+
- name: Setup ENV
47+
id: env
48+
run: |
49+
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
50+
RELEASE_TAG=${{ github.event.inputs.releaseTag }}
51+
elif [[ "${GITHUB_REF}" == refs/tags/v*.*.* ]]; then
52+
RELEASE_TAG=${GITHUB_REF/refs\/tags\//}
53+
fi
54+
if [[ "${RELEASE_TAG}" != v*.*.* ]]; then
55+
echo "invalid release tag (${RELEASE_TAG} - ${GITHUB_REF}), only semver is allowed (i.e v*.*.*)"
56+
exit 1
57+
fi
58+
echo "::set-output name=RELEASE_TAG::${RELEASE_TAG}"
59+
60+
- name: Checkout code
61+
uses: actions/checkout@v2
62+
63+
- name: Release
64+
uses: softprops/[email protected]
65+
with:
66+
tag_name: ${{ steps.env.outputs.RELEASE_TAG }}

.github/workflows/test.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
tags-ignore: [ '*' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
workflow_dispatch:
11+
inputs:
12+
logLevel:
13+
description: 'Log level'
14+
default: 'info'
15+
type: choice
16+
options:
17+
- debug
18+
- error
19+
- fatal
20+
- info
21+
- panic
22+
- warning
23+
24+
jobs:
25+
26+
test:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Setup Go environment
30+
uses: actions/setup-go@v2
31+
with:
32+
go-version: '1.17'
33+
34+
- name: Checkout code
35+
uses: actions/checkout@v2
36+
with:
37+
# https://github.com/actions/checkout/issues/100
38+
fetch-depth: 0
39+
40+
- name: Install test tools
41+
run: |
42+
make test-tools
43+
44+
- name: Run Tests
45+
run: |
46+
make test

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.DS_Store
2+
.vscode
3+
.vs
4+
Thumbs.db
5+
6+
*.exe
7+
*.log
8+
*.out
9+
*.prof
10+
*.so
11+
12+
logs/
13+
node_modules/
14+
reports/
15+
releases/
16+
tmp/
17+
vendor/

CONTRIBUTING.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Contributing
2+
3+
- Code contributions must be through pull requests.
4+
- Run tests, linting and formatting before make a pull request.
5+
- Pull requests can not be merged without being reviewed.
6+
- Use "Issues" for bug reports, feature requests, discussions and typos.
7+
- Do not refactor existing code without a discussion.
8+
- Do not add a new third party dependency without a discussion.
9+
- Use semantic versioning and git tags for versioning.

LICENSE.txt

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

Makefile

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Init vars.
2+
MAKEFILE := $(lastword $(MAKEFILE_LIST))
3+
BASENAME := $(shell basename "$(PWD)")
4+
5+
.PHONY: help
6+
all: help
7+
help: Makefile
8+
@echo
9+
@echo " Commands:"
10+
@echo
11+
@sed -n 's/^##//p' $< | sed -e 's/^/ /' | sort
12+
@echo
13+
14+
## test Run gofmt, golint, staticcheck, go vet and go test.
15+
test:
16+
$(eval FMT=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs gofmt -l | wc -l | tr -d ' '))
17+
@if [ "$(FMT)" != "0" ]; then \
18+
echo "some files are not formatted, run 'make fmt'"; \
19+
exit 1; \
20+
fi
21+
22+
$(eval LINT=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs golint | wc -l | tr -d ' '))
23+
@if [ "$(LINT)" != "0" ]; then \
24+
echo "some files have linting errors, run 'make lint'"; \
25+
exit 1; \
26+
fi
27+
28+
$(eval STATICCHECK=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs staticcheck | wc -l | tr -d ' '))
29+
@if [ "$(STATICCHECK)" != "0" ]; then \
30+
echo "some files have staticcheck errors, run 'make staticcheck'"; \
31+
exit 1; \
32+
fi
33+
34+
$(eval GOVET=$(shell find . -type f -name '*.go' | grep -v -E '^./vendor' | xargs -L1 dirname | uniq | xargs go vet 2>&1 | wc -l | tr -d ' '))
35+
@if [ "$(GOVET)" != "0" ]; then \
36+
echo "some files have vetting errors, run 'make vet'"; \
37+
exit 1; \
38+
fi
39+
40+
@$(MAKE) -f $(MAKEFILE) test-go
41+
42+
## test-go Run go test
43+
test-go:
44+
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs go test -v -race
45+
46+
## test-benchmarks Run go benchmarks
47+
test-benchmarks:
48+
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs go test -benchmem -bench
49+
50+
## test-ui Launch test UI
51+
test-ui:
52+
$(eval GOCONVEY_PATH=$(shell which goconvey))
53+
@if [ -z "$(GOCONVEY_PATH)" ]; then \
54+
GO111MODULE=off go get github.com/smartystreets/goconvey; \
55+
fi
56+
goconvey -port 8088 -excludedDirs vendor,node_modules,assets
57+
58+
## test-clean Clean test cache
59+
test-clean:
60+
@go clean -testcache
61+
62+
## test-tools Install test tools
63+
test-tools:
64+
$(eval GOLINT_PATH=$(shell which golint))
65+
@if [ -z "$(GOLINT_PATH)" ]; then \
66+
GO111MODULE=off go get golang.org/x/lint/golint; \
67+
fi
68+
$(eval STATICCHECK_PATH=$(shell which staticcheck))
69+
@if [ -z "$(STATICCHECK_PATH)" ]; then \
70+
GO111MODULE=off go get honnef.co/go/tools/cmd/staticcheck; \
71+
fi
72+
73+
## fmt Run formating
74+
fmt:
75+
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs gofmt -l
76+
77+
## lint Run linting
78+
lint:
79+
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs golint
80+
81+
## staticcheck Run staticcheck
82+
staticcheck:
83+
@find . -type f -name '*.go' | grep -v -E '^./vendor|^./third_party' | xargs -L1 dirname | uniq | xargs staticcheck
84+
85+
## vet Run vetting
86+
vet:
87+
@find . -type f -name '*.go' | grep -v -E '^./vendor' | xargs -L1 dirname | uniq | xargs go vet 2>&1
88+
89+
## release Release a version
90+
release:
91+
@if [ "$(shell echo \$${GIT_TAG:0:1})" != "v" ]; then \
92+
echo "invalid GIT_TAG (${GIT_TAG}). Try something like 'make release GIT_TAG=v1.0.0'"; \
93+
exit 1; \
94+
fi
95+
git tag -a $(GIT_TAG) -m "$(GIT_TAG)"
96+
git push --follow-tags

README.md

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Byteman
2+
3+
[![Godoc][doc-image]][doc-url] [![Release][release-image]][release-url] [![Build][build-image]][build-url]
4+
5+
A Golang library that provides functions for bytes and bits.
6+
7+
## Usage
8+
9+
See [byteman_test.go](byteman_test.go), [numbers_test.go](numbers_test.go) and [strings_test.go](strings_test.go).
10+
11+
## Test
12+
13+
```shell
14+
# Test everything:
15+
make test
16+
17+
# For BDD development:
18+
# It will open a new browser window. Make sure:
19+
# 1. There is no errors on the terminal window.
20+
# 2. There is no other open GoConvey page.
21+
make test-ui
22+
23+
# Benchmarks
24+
make test-benchmarks
25+
```
26+
27+
## Release
28+
29+
```shell
30+
# Update and commit CHANGELOG.md first (i.e. git add CHANGELOG.md && git commit -m "v1.0.0").
31+
# Set GIT_TAG using semver (i.e. GIT_TAG=v1.0.0)
32+
make release GIT_TAG=
33+
```
34+
35+
## Contributing
36+
37+
See [CONTRIBUTING.md](CONTRIBUTING.md)
38+
39+
## License
40+
41+
Licensed under The MIT License (MIT)
42+
For the full copyright and license information, please view the LICENSE.txt file.
43+
44+
[doc-url]: https://pkg.go.dev/github.com/devfacet/byteman
45+
[doc-image]: https://pkg.go.dev/badge/github.com/devfacet/byteman
46+
47+
[release-url]: https://github.com/devfacet/byteman/releases/latest
48+
[release-image]: https://img.shields.io/github/release/devfacet/byteman.svg?style=flat-square
49+
50+
[build-url]: https://github.com/devfacet/byteman/actions/workflows/test.yaml
51+
[build-image]: https://github.com/devfacet/byteman/actions/workflows/test.yaml/badge.svg

byteman.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Byteman
2+
// For the full copyright and license information, please view the LICENSE.txt file.
3+
4+
// Package byteman provides functions for bytes and bits.
5+
package byteman
6+
7+
// Combine combines the given byte slices.
8+
func Combine(bs ...[]byte) []byte {
9+
b := []byte{}
10+
for _, v := range bs {
11+
b = append(b, v...)
12+
}
13+
return b
14+
}
15+
16+
// Resize resizes the given byte slice.
17+
func Resize(b []byte, size int) []byte {
18+
if size == 0 {
19+
size = len(b)
20+
} else if size < 0 {
21+
if ns := len(b) + size; ns > 0 {
22+
size = ns
23+
} else {
24+
size = 0
25+
}
26+
}
27+
nb := make([]byte, size)
28+
if b != nil {
29+
copy(nb, b)
30+
}
31+
return nb
32+
}

0 commit comments

Comments
 (0)