diff --git a/CHANGELOG.md b/CHANGELOG.md
index dcec5be..8a81e50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,25 @@
# go-utils
+
+## [v1.37.0] - 2024-03-06
+### New Features
+- add IsUniqueSliceItem
+
+
+
+## [v1.36.0] - 2024-01-18
+### New Features
+- add IsURLReachable ([#58](https://github.com/kumparan/kumnats/issues/58))
+
+
+
+## [v1.35.0] - 2023-10-09
+### New Features
+- add DoHTTPRequest generic method ([#57](https://github.com/kumparan/kumnats/issues/57))
+
+
-## [v1.34.0] - 2023-09-19
+## [v1.34.0] - 2023-09-20
### New Features
- add generate uuid functionality and update linter
@@ -112,9 +130,6 @@
- fix marshal issue on gorm.DeletedAt empty value ([#32](https://github.com/kumparan/kumnats/issues/32))
-
-## [v.1.20.0] - 2022-03-11
-
## [v1.20.0] - 2022-03-11
### New Features
@@ -214,11 +229,11 @@
- add money formatter for multiple currencies ([#13](https://github.com/kumparan/kumnats/issues/13))
-
-## [v1.8.0] - 2020-12-10
-
## [v1.7.1] - 2020-12-10
+
+
+## [v1.8.0] - 2020-12-10
### New Features
- add formatter for indonesian money and date
@@ -283,7 +298,10 @@
- init go-utils
-[Unreleased]: https://github.com/kumparan/kumnats/compare/v1.34.0...HEAD
+[Unreleased]: https://github.com/kumparan/kumnats/compare/v1.37.0...HEAD
+[v1.37.0]: https://github.com/kumparan/kumnats/compare/v1.36.0...v1.37.0
+[v1.36.0]: https://github.com/kumparan/kumnats/compare/v1.35.0...v1.36.0
+[v1.35.0]: https://github.com/kumparan/kumnats/compare/v1.34.0...v1.35.0
[v1.34.0]: https://github.com/kumparan/kumnats/compare/v1.33.0...v1.34.0
[v1.33.0]: https://github.com/kumparan/kumnats/compare/v1.32.1...v1.33.0
[v1.32.1]: https://github.com/kumparan/kumnats/compare/v1.32.0...v1.32.1
@@ -301,8 +319,7 @@
[v1.23.0]: https://github.com/kumparan/kumnats/compare/v1.22.0...v1.23.0
[v1.22.0]: https://github.com/kumparan/kumnats/compare/v1.21.0...v1.22.0
[v1.21.0]: https://github.com/kumparan/kumnats/compare/v1.20.1...v1.21.0
-[v1.20.1]: https://github.com/kumparan/kumnats/compare/v.1.20.0...v1.20.1
-[v.1.20.0]: https://github.com/kumparan/kumnats/compare/v1.20.0...v.1.20.0
+[v1.20.1]: https://github.com/kumparan/kumnats/compare/v1.20.0...v1.20.1
[v1.20.0]: https://github.com/kumparan/kumnats/compare/v1.19.3...v1.20.0
[v1.19.3]: https://github.com/kumparan/kumnats/compare/v1.19.2...v1.19.3
[v1.19.2]: https://github.com/kumparan/kumnats/compare/v1.19.1...v1.19.2
@@ -319,9 +336,9 @@
[v1.12.0]: https://github.com/kumparan/kumnats/compare/v1.11.0...v1.12.0
[v1.11.0]: https://github.com/kumparan/kumnats/compare/v1.10.0...v1.11.0
[v1.10.0]: https://github.com/kumparan/kumnats/compare/v1.9.0...v1.10.0
-[v1.9.0]: https://github.com/kumparan/kumnats/compare/v1.8.0...v1.9.0
-[v1.8.0]: https://github.com/kumparan/kumnats/compare/v1.7.1...v1.8.0
-[v1.7.1]: https://github.com/kumparan/kumnats/compare/v1.7.0...v1.7.1
+[v1.9.0]: https://github.com/kumparan/kumnats/compare/v1.7.1...v1.9.0
+[v1.7.1]: https://github.com/kumparan/kumnats/compare/v1.8.0...v1.7.1
+[v1.8.0]: https://github.com/kumparan/kumnats/compare/v1.7.0...v1.8.0
[v1.7.0]: https://github.com/kumparan/kumnats/compare/v1.6.0...v1.7.0
[v1.6.0]: https://github.com/kumparan/kumnats/compare/v1.5.0...v1.6.0
[v1.5.0]: https://github.com/kumparan/kumnats/compare/v1.4.0...v1.5.0
diff --git a/go.mod b/go.mod
index 4ede514..5d1c380 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module github.com/kumparan/go-utils
-go 1.18
+go 1.20
require (
github.com/99designs/gqlgen v0.14.0
diff --git a/slice.go b/slice.go
index 560b97c..0e5a580 100644
--- a/slice.go
+++ b/slice.go
@@ -184,3 +184,16 @@ func FindDifferencesFromSlices[T comparable](slices ...[]T) []T {
return result
}
+
+// IsUniqueSliceItem :nodoc:
+func IsUniqueSliceItem[T comparable](data []T) bool {
+ mapData := make(map[T]bool, len(data))
+ for _, d := range data {
+ if _, ok := mapData[d]; ok {
+ return false
+ }
+ mapData[d] = true
+ }
+
+ return true
+}
diff --git a/slice_test.go b/slice_test.go
index 049807a..bb29765 100644
--- a/slice_test.go
+++ b/slice_test.go
@@ -102,7 +102,7 @@ func Test_FindDifferencesFromSlices(t *testing.T) {
result []string
}
- var testCases = []tc{
+ testCases := []tc{
{
slices: [][]string{
{"a", "b", "c"},
@@ -138,7 +138,57 @@ func Test_FindDifferencesFromSlices(t *testing.T) {
res := FindDifferencesFromSlices(tc.slices...)
for _, it := range tc.result {
assert.Contains(t, res, it)
-
}
}
}
+
+func Test_IsUniqueSliceItem(t *testing.T) {
+ type tc[T comparable] struct {
+ slice []T
+ result bool
+ }
+
+ testCasesString := []tc[string]{
+ {
+ slice: []string{
+ "haha", "hehe",
+ },
+ result: true,
+ },
+ {
+ slice: []string{
+ "HAHA", "haha",
+ },
+ result: true,
+ },
+ {
+ slice: []string{
+ "haha", "haha",
+ },
+ result: false,
+ },
+ }
+
+ for _, tc := range testCasesString {
+ assert.Equal(t, tc.result, IsUniqueSliceItem(tc.slice))
+ }
+
+ testCasesInt := []tc[int]{
+ {
+ slice: []int{
+ 1, 2,
+ },
+ result: true,
+ },
+ {
+ slice: []int{
+ 1, 1,
+ },
+ result: false,
+ },
+ }
+
+ for _, tc := range testCasesInt {
+ assert.Equal(t, tc.result, IsUniqueSliceItem(tc.slice))
+ }
+}