-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from gotomicro/dev
Release v0.0.4
- Loading branch information
Showing
31 changed files
with
1,816 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2021 gotomicro | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
coverage: | ||
status: | ||
project: | ||
default: | ||
# basic | ||
target: 95% | ||
threshold: 0.5% | ||
# advanced settings | ||
branches: | ||
- main | ||
- dev | ||
if_ci_failed: error #success, failure, error, ignore | ||
informational: false | ||
only_pulls: false | ||
patch: | ||
default: | ||
# basic | ||
target: 95% | ||
threshold: 0.5% | ||
branches: | ||
- main | ||
- dev | ||
if_ci_failed: error #success, failure, error, ignore | ||
informational: false | ||
only_pulls: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.idea | ||
.idea | ||
|
||
**/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# ekit | ||
泛型工具库 | ||
泛型工具库。 | ||
|
||
- [文档](https://ekit.gocn.vip/ekit/develop/guide/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2021 gotomicro | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package slice | ||
|
||
import "github.com/gotomicro/ekit/internal/errs" | ||
|
||
func Delete[T any](src []T, index int) ([]T, T, error) { | ||
length := len(src) | ||
if index < 0 || index >= length { | ||
var zero T | ||
return nil, zero, errs.NewErrIndexOutOfRange(length, index) | ||
} | ||
j := 0 | ||
res := src[index] | ||
for i, v := range src { | ||
if i != index { | ||
src[j] = v | ||
j++ | ||
} | ||
} | ||
src = src[:j] | ||
return src, res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2021 gotomicro | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package slice | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gotomicro/ekit/internal/errs" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDelete(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
slice []int | ||
index int | ||
wantSlice []int | ||
wantVal int | ||
wantErr error | ||
}{ | ||
{ | ||
name: "index 0", | ||
slice: []int{123, 100}, | ||
index: 0, | ||
wantSlice: []int{100}, | ||
wantVal: 123, | ||
}, | ||
{ | ||
name: "index middle", | ||
slice: []int{123, 124, 125}, | ||
index: 1, | ||
wantSlice: []int{123, 125}, | ||
wantVal: 124, | ||
}, | ||
{ | ||
name: "index out of range", | ||
slice: []int{123, 100}, | ||
index: 12, | ||
wantErr: errs.NewErrIndexOutOfRange(2, 12), | ||
}, | ||
{ | ||
name: "index less than 0", | ||
slice: []int{123, 100}, | ||
index: -1, | ||
wantErr: errs.NewErrIndexOutOfRange(2, -1), | ||
}, | ||
{ | ||
name: "index last", | ||
slice: []int{123, 100, 101, 102, 102, 102}, | ||
index: 5, | ||
wantSlice: []int{123, 100, 101, 102, 102}, | ||
wantVal: 102, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
res, val, err := Delete(tc.slice, tc.index) | ||
assert.Equal(t, tc.wantErr, err) | ||
if err != nil { | ||
return | ||
} | ||
assert.Equal(t, tc.wantSlice, res) | ||
assert.Equal(t, tc.wantVal, val) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2021 gotomicro | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package slice 后续逐步把切片会在不同部分使用的公共方法挪过来这个内部包 | ||
package slice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.