From 65064c3b2b42e4fe77b85f79c7ba76497cd44d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 25 Jul 2022 09:55:59 +0800 Subject: [PATCH] - update --- .circleci/config.yml | 42 ---------------------------------- .drone.yml | 10 ++++++-- .github/workflows/coverage.yml | 38 ------------------------------ .github/workflows/go.yml | 27 ---------------------- .gitignore | 2 +- .travis.yml | 7 ------ LICENSE | 2 +- README.md | 22 ++++++------------ go.mod | 2 +- gomod.sh | 3 --- gostring.go | 9 ++++---- gostring_test.go | 24 +++++++++++++++++++ version.go | 3 +++ 13 files changed, 50 insertions(+), 141 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100644 .github/workflows/coverage.yml delete mode 100644 .github/workflows/go.yml delete mode 100644 .travis.yml delete mode 100644 gomod.sh create mode 100644 version.go diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index b02a38e..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,42 +0,0 @@ -# Use the latest 2.1 version of CircleCI pipeline process engine. -# See: https://circleci.com/docs/2.0/configuration-reference -version: 2.1 - -# Define a job to be invoked later in a workflow. -# See: https://circleci.com/docs/2.0/configuration-reference/#jobs -jobs: - build: - working_directory: ~/repo - # Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub. - # See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor - docker: - - image: circleci/golang:1.18 - # Add steps to the job - # See: https://circleci.com/docs/2.0/configuration-reference/#steps - steps: - - checkout - - restore_cache: - keys: - - go-mod-v4-{{ checksum "go.sum" }} - - run: - name: Install Dependencies - command: go mod download - - save_cache: - key: go-mod-v4-{{ checksum "go.sum" }} - paths: - - "/go/pkg/mod" - - run: - name: Run tests - command: | - mkdir -p /tmp/test-reports - gotestsum --junitfile /tmp/test-reports/unit-tests.xml - - store_test_results: - path: /tmp/test-reports - -# Invoke jobs via workflows -# See: https://circleci.com/docs/2.0/configuration-reference/#workflows -workflows: - sample: # This is the name of the workflow, feel free to change it to better match your workflow. - # Inside the workflow, you define the jobs you want to run. - jobs: - - build \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index 511f0fc..c56c479 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,9 +3,15 @@ type: docker name: clone steps: - - name: test-golang + - name: Test image: golang:1.18 commands: - go env -w GO111MODULE=on - go env -w GOPROXY=https://goproxy.cn,direct - - go test -v ./... \ No newline at end of file + - go test -v ./... + - name: Benchmark + image: golang:1.18 + commands: + - go env -w GO111MODULE=on + - go env -w GOPROXY=https://goproxy.cn,direct + - go test -bench=. -benchmem \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 1d4bb34..0000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: coverage - -on: - push: - branches: [ master ] - paths-ignore: - - '**.md' - pull_request: - branches: [ master ] - paths-ignore: - - '**.md' - -jobs: - test: - name: Test with Coverage - runs-on: ubuntu-latest - steps: - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Check out code - uses: actions/checkout@v2 - - - name: Install dependencies - run: | - go mod download - - name: Run Unit tests - run: | - go test -race -covermode atomic -coverprofile=covprofile ./... - - name: Install goveralls - run: go install github.com/mattn/goveralls@latest - - - name: Send coverage - env: - COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: goveralls -coverprofile=covprofile -service=github \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index cc923fb..0000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Go - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: 1.18 - - - name: Test - run: go test -v ./... - - - name: Test - run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic - - - name: Coverage - run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2b895f4..8f33b64 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ .idea .vscode *.log -gitmod.sh \ No newline at end of file +gomod.sh \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 688142c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: go - -go: - - master - -script: - - go test -v ./... \ No newline at end of file diff --git a/LICENSE b/LICENSE index a0d0e5b..ff84bbf 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 茂名聚合科技有限公司 +Copyright (c) 2018 李光春 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 3d74699..130ca32 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,16 @@ Golang String -📦 Golang 字符串组件 +📦 Golang 字符串 [comment]: <> (go) -[![godoc](https://pkg.go.dev/badge/go.dtapp.net/gostring?status.svg)](https://pkg.go.dev/go.dtapp.net/gostring) -[![goproxy.cn](https://goproxy.cn/stats/go.dtapp.net/gostring/badges/download-count.svg)](https://goproxy.cn/stats/go.dtapp.net/gostring) -[![goreportcard.com](https://goreportcard.com/badge/go.dtapp.net/gostring)](https://goreportcard.com/report/go.dtapp.net/gostring) -[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/go.dtapp.net/gostring) +[![godoc](https://pkg.go.dev/badge/github.com/dtapps/gostring?status.svg)](https://pkg.go.dev/github.com/dtapps/gostring) +[![goproxy.cn](https://goproxy.cn/stats/github.com/dtapps/gostring/badges/download-count.svg)](https://goproxy.cn/stats/github.com/dtapps/gostring) +[![goreportcard.com](https://goreportcard.com/badge/github.com/dtapps/gostring)](https://goreportcard.com/report/github.com/dtapps/gostring) +[![deps.dev](https://img.shields.io/badge/deps-go-red.svg)](https://deps.dev/go/github.com%2Fdtapps%2Fgostring) -#### 安装使用 +#### 安装 ```go -go get -v -u go.dtapp.net/gostring +go get -v -u github.com/dtapps/gostring ``` - -#### 导入 - -```go -import ( - "go.dtapp.net/gostring" -) -``` \ No newline at end of file diff --git a/go.mod b/go.mod index c789877..8d5cd0c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module go.dtapp.net/gostring +module github.com/dtapps/gostring go 1.18 diff --git a/gomod.sh b/gomod.sh deleted file mode 100644 index c03f9f0..0000000 --- a/gomod.sh +++ /dev/null @@ -1,3 +0,0 @@ -go get -u && go mod tidy -go get -u all -go mod vendor \ No newline at end of file diff --git a/gostring.go b/gostring.go index c489f7d..0929b2f 100644 --- a/gostring.go +++ b/gostring.go @@ -10,8 +10,6 @@ import ( "unicode/utf8" ) -const Version = "1.0.3" - // ToString 转换成string func ToString(value interface{}) string { if value == nil { @@ -96,12 +94,15 @@ func TrimLastChar(s string) string { // Split 字符串分隔 func Split(s string, sep string) []string { + if len(s) <= 0 { + return []string{} + } return strings.Split(s, sep) } // Contains 判断字符串是否包含某个字符 -func Contains(s, substr string) bool { - return strings.Contains(s, substr) +func Contains(s, sep string) bool { + return strings.Contains(s, sep) } func NumericalToString(value interface{}) (string, bool) { diff --git a/gostring_test.go b/gostring_test.go index e10069a..fe76f25 100644 --- a/gostring_test.go +++ b/gostring_test.go @@ -2,6 +2,7 @@ package gostring import ( "fmt" + "log" "strings" "testing" ) @@ -34,9 +35,32 @@ func TestString(t *testing.T) { func TestSplit(t *testing.T) { t.Log(Split("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20", ",")) + t.Log(Split(",10,", ",")) + t.Log(len(Split(",10,", ","))) + t.Log(Split(",10,", ",")[1 : len(Split(",1,", ","))-1]) + t.Log(len(Split(",10,", ",")[1 : len(Split(",1,", ","))-1])) + t.Log(Contains("", ",")) + t.Log(len([]string{})) + t.Log(Split("/pages/preferential_recharge/goods_details?goods_id=G02022062517457120", "=")) } func TestContains(t *testing.T) { t.Log(Contains("1", ",")) t.Log(Contains("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20", ",")) } + +func TestToFloat64(t *testing.T) { + t.Log(ToFloat64("120")) + t.Log(ToFloat64("120.9")) + t.Log(ToFloat64("100.100.100")) + if "100.100.100" > "111.111.111" { + log.Println("1") + } else { + log.Println("2") + } +} + +func TestReplace(t *testing.T) { + t.Log(Replace("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20", ",", "|")) + t.Log(Replace("/v1/a/{agent_user_id}/d/g", "{agent_user_id}", "A102DFB78FADE96F1E")) +} diff --git a/version.go b/version.go new file mode 100644 index 0000000..e191091 --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package gostring + +const Version = "1.0.4"