From 69fe76665dc3d4ddb5a008e9cdb79686670319c9 Mon Sep 17 00:00:00 2001 From: Deng Ming Date: Sun, 12 Jun 2022 12:27:26 +0800 Subject: [PATCH] ekit: add ToPtr function --- .CHANGELOG.md | 3 ++- .deepsource.toml | 6 +----- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/ISSUE_TEMPLATE/question.md | 2 +- .github/linters/.golangci.yml | 4 ++-- .github/workflows/changelog.yml | 1 + .github/workflows/go.yml | 4 ++-- .github/workflows/license.yml | 1 + .licenserc.json | 2 +- Makefile | 2 +- README.md | 4 ++-- go.mod | 2 +- pool/pool_test.go | 2 +- ptr.go | 19 +++++++++++++++++ ptr_test.go | 26 +++++++++++++++++++++++ 16 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 ptr.go create mode 100644 ptr_test.go diff --git a/.CHANGELOG.md b/.CHANGELOG.md index 78df33e9..3232ad6e 100644 --- a/.CHANGELOG.md +++ b/.CHANGELOG.md @@ -1 +1,2 @@ -# 开发中 \ No newline at end of file +# 开发中 +[ekit: add ToPtr function](https://github.com/gotomicro/ekit/pull/6) \ No newline at end of file diff --git a/.deepsource.toml b/.deepsource.toml index 28d321eb..2e9127ae 100644 --- a/.deepsource.toml +++ b/.deepsource.toml @@ -19,14 +19,10 @@ name = "go" enabled = true [analyzers.meta] - import_root = "github.com/gotomicro/ego-kit" + import_root = "github.com/gotomicro/ekit" dependencies_vendored = false [[analyzers]] name = "test-coverage" enabled = true -[[analyzers]] -name = "sql" -enabled = true - diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 369e6c96..b36b608b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -28,7 +28,7 @@ assignees: '' ### 你排查的结果,或者你觉得可行的修复方案 > 可选。我们希望你能够尽量先排查问题,帮助我们减轻维护负担。这对于你个人能力提升同样是有帮助的。 -### 你使用的是 ego-kit 哪个版本? +### 你使用的是 ekit 哪个版本? ### 你设置的的 Go 环境? > 上传 `go env` 的结果 \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 51b95bda..86d29f2c 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -20,7 +20,7 @@ assignees: '' ### 其它 > 任何你觉得有利于解决问题的补充说明 -### 你使用的是 ego-kit 哪个版本? +### 你使用的是 ekit 哪个版本? ### 你设置的的 Go 环境? > 上传 `go env` 的结果 diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index b91e17c7..65d8e070 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -16,7 +16,7 @@ labels: question ### 你的问题 -### 你使用的是 ego-kit 哪个版本? +### 你使用的是 ekit 哪个版本? ### 你设置的的 Go 环境? > 上传 `go env` 的结果 diff --git a/.github/linters/.golangci.yml b/.github/linters/.golangci.yml index 513d535a..df364cb5 100644 --- a/.github/linters/.golangci.yml +++ b/.github/linters/.golangci.yml @@ -53,6 +53,6 @@ linters: linters-settings: gci: - local-prefixes: github.com/gotomicro/ego-kit + local-prefixes: github.com/gotomicro/ekit goimports: - local-prefixes: github.com/gotomicro/ego-kit + local-prefixes: github.com/gotomicro/ekit diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 0a8130cb..431f0731 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -20,6 +20,7 @@ on: branches: - develop - main + - dev jobs: changelog: diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 572814dc..4cba044a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,9 +16,9 @@ name: Go on: push: - branches: [ main ] + branches: [ dev ] pull_request: - branches: [ main ] + branches: [ dev ] jobs: build: diff --git a/.github/workflows/license.yml b/.github/workflows/license.yml index 8110d5b5..24ca3167 100644 --- a/.github/workflows/license.yml +++ b/.github/workflows/license.yml @@ -19,6 +19,7 @@ on: branches: - develop - main + - dev jobs: check-license-lines: runs-on: ubuntu-latest diff --git a/.licenserc.json b/.licenserc.json index 688e5a13..a9304749 100644 --- a/.licenserc.json +++ b/.licenserc.json @@ -1,5 +1,5 @@ { "**/*.go": "// Copyright 2021 gotomicro", - "**/*.{yml,toml}": "# Copyright 2021 gotomicro" + "**/*.{yml,toml}": "# Copyright 2021 gotomicro", "**/*.sh": "# Copyright 2021 gotomicro" } \ No newline at end of file diff --git a/Makefile b/Makefile index af4cc89e..8e3cfff7 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ bench: @go test -bench=. -benchmem ./... -test: +ut: @go test -race ./... setup: diff --git a/README.md b/README.md index 8f9ff031..42453185 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# ego-kit -Stream API, Collection and ... +# ekit +泛型工具库 diff --git a/go.mod b/go.mod index 92d46dd2..2b86b347 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gotomicro/ego-kit +module github.com/gotomicro/ekit go 1.18 diff --git a/pool/pool_test.go b/pool/pool_test.go index 22cb4576..1f2cc8f9 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -51,7 +51,7 @@ func ExampleNew() { // goos: linux // goarch: amd64 -// pkg: github.com/gotomicro/ego-kit/pkg/pool +// pkg: github.com/gotomicro/ekit/pkg/pool // cpu: Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz // BenchmarkPool_Get/Pool-12 9190246 130.0 ns/op 0 B/op 0 allocs/op // BenchmarkPool_Get/sync.Pool-12 9102818 128.6 ns/op 0 B/op 0 allocs/op diff --git a/ptr.go b/ptr.go new file mode 100644 index 00000000..1b487800 --- /dev/null +++ b/ptr.go @@ -0,0 +1,19 @@ +// 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 ekit + +func ToPtr[T any](t T) *T { + return &t +} diff --git a/ptr_test.go b/ptr_test.go new file mode 100644 index 00000000..e848ccf8 --- /dev/null +++ b/ptr_test.go @@ -0,0 +1,26 @@ +// 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 ekit + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestToPtr(t *testing.T) { + i := 12 + res := ToPtr[int](i) + assert.Equal(t, &i, res) +}