Skip to content

Commit f24e36e

Browse files
authored
first version (#1)
1 parent c68c0f0 commit f24e36e

File tree

14 files changed

+433
-1
lines changed

14 files changed

+433
-1
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
16+
**Expected behavior**
17+
A clear and concise description of what you expected to happen.
18+
19+
**System (please complete the following information):**
20+
- OS:
21+
- Version / Commit:
22+
23+
**Additional context**
24+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/workflows/codecov.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: codecov
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
codecov:
11+
timeout-minutes: 15
12+
13+
name: Coverage
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: 1.19
20+
id: go
21+
22+
- name: Check out code into the Go module directory
23+
uses: actions/checkout@v2
24+
25+
- name: Get dependencies
26+
run: go mod download
27+
28+
- name: Run tests with coverage
29+
run: make test-coverage
30+
31+
- name: Upload coverage to Codecov
32+
uses: codecov/codecov-action@v2
33+
with:
34+
file: ./.testCoverage

.github/workflows/go.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
if: "!contains(github.event.commits[0].message, '[skip ci]')"
12+
timeout-minutes: 15
13+
14+
name: Build
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
go: [1.17, 1.18, 1.19]
19+
20+
steps:
21+
- name: Set up Go 1.x
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: ${{ matrix.go }}
25+
id: go
26+
27+
- name: Check out code into the Go module directory
28+
uses: actions/checkout@v2
29+
30+
- name: Install linters
31+
run: make install-linters
32+
33+
- name: Get dependencies
34+
run: go mod download
35+
36+
- name: Run tests
37+
run: make test
38+
39+
- name: Run linter
40+
run: make lint

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.exe
2+
.idea
3+
.vscode
4+
*.iml
5+
*.local
6+
/*.log
7+
*.out
8+
*.prof
9+
*.test
10+
.DS_Store
11+
*.dmp
12+
*.db
13+
14+
.testCoverage

.golangci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
run:
2+
deadline: 5m
3+
4+
linters:
5+
enable:
6+
- asasalint # check for pass []any as any in variadic func(...any)
7+
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
8+
- bidichk # Checks for dangerous unicode character sequences
9+
- containedctx # detects struct contained context.Context field
10+
- contextcheck # check the function whether use a non-inherited context
11+
- cyclop # checks function and package cyclomatic complexity
12+
- decorder # check declaration order and count of types, constants, variables and functions
13+
- depguard # Go linter that checks if package imports are in a list of acceptable packages
14+
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
15+
- durationcheck # check for two durations multiplied together
16+
- errcheck # checking for unchecked errors
17+
- errname # Checks that errors are prefixed with the `Err` and error types are suffixed with the `Error`
18+
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
19+
- exportloopref # checks for pointers to enclosing loop variables
20+
- funlen # Tool for detection of long functions
21+
- gci # controls golang package import order and makes it always deterministic
22+
- gocognit # Computes and checks the cognitive complexity of functions
23+
- gocritic # Provides diagnostics that check for bugs, performance and style issues
24+
- gocyclo # Computes and checks the cyclomatic complexity of functions
25+
- godot # Check if comments end in a period
26+
- goerr113 # Golang linter to check the errors handling expressions
27+
- gosimple # Linter for Go source code that specializes in simplifying a code
28+
- govet # reports suspicious constructs, such as Printf calls with wrong arguments
29+
- ineffassign # Detects when assignments to existing variables are not used
30+
- maintidx # measures the maintainability index of each function
31+
- makezero # Finds slice declarations with non-zero initial length
32+
- misspell # Finds commonly misspelled English words in comments
33+
- nakedret # Finds naked returns in functions
34+
- nestif # Reports deeply nested if statements
35+
- nilerr # Finds the code that returns nil even if it checks that the error is not nil
36+
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value
37+
- prealloc # Finds slice declarations that could potentially be preallocated
38+
- predeclared # find code that shadows one of Go's predeclared identifiers
39+
- revive # drop-in replacement of golint
40+
- staticcheck # drop-in replacement of go vet
41+
- stylecheck # Stylecheck is a replacement for golint
42+
- tenv # detects using os.Setenv instead of t.Setenv
43+
- thelper # checks the consistency of test helpers
44+
- tparallel # detects inappropriate usage of t.Parallel()
45+
- typecheck # parses and type-checks Go code
46+
- unconvert # Remove unnecessary type conversions
47+
- unparam # Reports unused function parameters
48+
- unused # Checks Go code for unused constants, variables, functions and types
49+
- usestdlibvars # detect the possibility to use variables/constants from the Go standard library
50+
- wastedassign # finds wasted assignment statements
51+
- whitespace # detects leading and trailing whitespace
52+
53+
issues:
54+
exclude-use-default: false
55+
exclude-rules:
56+
- linters:
57+
- goerr113
58+
text: "do not define dynamic errors"

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
help: ## show help, shown by default if no target is specified
2+
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
3+
4+
lint: ## run code linters
5+
golangci-lint run
6+
7+
test: ## run tests
8+
go test -race ./...
9+
10+
test-coverage: ## run unit tests and create test coverage
11+
go test ./... -coverprofile .testCoverage -covermode=atomic -coverpkg=./...
12+
13+
test-coverage-web: test-coverage ## run unit tests and show test coverage in browser
14+
go tool cover -func .testCoverage | grep total | awk '{print "Total coverage: "$$3}'
15+
go tool cover -html=.testCoverage
16+
17+
install-linters: ## install all used linters
18+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.49.0

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,27 @@
1-
# orderedmap
1+
# orderedmap
2+
3+
[![Build status](https://github.com/cornelk/orderedmap/actions/workflows/go.yaml/badge.svg?branch=main)](https://github.com/cornelk/orderedmap/actions)
4+
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/cornelk/orderedmap)
5+
[![Go Report Card](https://goreportcard.com/badge/github.com/cornelk/orderedmap)](https://goreportcard.com/report/github.com/cornelk/orderedmap)
6+
[![codecov](https://codecov.io/gh/cornelk/orderedmap/branch/main/graph/badge.svg?token=NS5UY28V3A)](https://codecov.io/gh/cornelk/orderedmap)
7+
8+
## Overview
9+
10+
A Golang Map that keeps track of the insert order of items.
11+
12+
The current version can be used as a replacement for `map[string]interface{}` and allows JSON unmarshalling into it.
13+
No manual adding of items is currently possible.
14+
15+
## Usage
16+
17+
Unmarshall and marshall JSON:
18+
19+
```
20+
var m Map
21+
input := `{"423":"abc","231":"dbh","152":"xyz"}`
22+
23+
m.UnmarshalJSON([]byte(input))
24+
25+
output, _ := m.MarshalJSON()
26+
# unlike the standard Golang map, the output will be exact the same and not in random key order
27+
```

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/cornelk/orderedmap
2+
3+
go 1.17

go.sum

Whitespace-only changes.

0 commit comments

Comments
 (0)