commit
66b060dfd3
@ -0,0 +1,17 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: clone
|
||||
|
||||
steps:
|
||||
- name: Test
|
||||
image: golang:1.18
|
||||
commands:
|
||||
- go env -w GO111MODULE=on
|
||||
- go env -w GOPROXY=https://goproxy.cn,direct
|
||||
- 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
|
@ -0,0 +1,9 @@
|
||||
.env
|
||||
.git
|
||||
.svn
|
||||
.idea
|
||||
.vscode
|
||||
*.log
|
||||
goinit.sh
|
||||
gomod.sh
|
||||
/vendor/
|
@ -0,0 +1,7 @@
|
||||
module go.dtapp.net/gobase64
|
||||
|
||||
go 1.18
|
||||
|
||||
require go.dtapp.net/gophp v1.0.0
|
||||
|
||||
require go.dtapp.net/gostring v1.0.3 // indirect
|
@ -0,0 +1,4 @@
|
||||
go.dtapp.net/gophp v1.0.0 h1:bjAqT8GAI4gfIaBy7JTB41o0vt7nnFEvpcwKAFUDxLU=
|
||||
go.dtapp.net/gophp v1.0.0/go.mod h1:s78OSeHXbBKsTW3YF/JPSQ33wWE3wzplSUNxuwHOvN4=
|
||||
go.dtapp.net/gostring v1.0.3 h1:KSOq4D77/g5yZN/bqWfZ0kOOaPr/P1240vg03+XdENI=
|
||||
go.dtapp.net/gostring v1.0.3/go.mod h1:+ggrOvgQDQturi1QGsXEpyRN/ZPoRDaqhMujIk5lrgQ=
|
@ -0,0 +1,34 @@
|
||||
package gobase64
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"go.dtapp.net/gophp"
|
||||
)
|
||||
|
||||
// Encode base64编码
|
||||
func Encode(input string) string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(input))
|
||||
}
|
||||
|
||||
// Decode base64解码
|
||||
func Decode(input string) string {
|
||||
decodeString, err := base64.StdEncoding.DecodeString(input)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(decodeString)
|
||||
}
|
||||
|
||||
// EncodeUrl Base64安全URL编码
|
||||
func EncodeUrl(input string) string {
|
||||
return gophp.Rtrim(gophp.Strtr(base64.StdEncoding.EncodeToString([]byte(input)), "+/", "-_"), "=")
|
||||
}
|
||||
|
||||
// DecodeUrl Base64安全URL解码
|
||||
func DecodeUrl(input string) string {
|
||||
decodeString, err := base64.StdEncoding.DecodeString(gophp.StrPad(gophp.Strtr(input, "-_", "+/"), len(input)/4, "="))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(decodeString)
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package gobase64
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncode(t *testing.T) {
|
||||
t.Log(Encode("广东茂名"))
|
||||
}
|
||||
|
||||
func BenchmarkEncode(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.Log(Encode("广东茂名"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
t.Log(Decode("5bm/5Lic6IyC5ZCN"))
|
||||
}
|
||||
|
||||
func BenchmarkDecode(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.Log(Decode("5bm/5Lic6IyC5ZCN"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeUrl(t *testing.T) {
|
||||
t.Log(EncodeUrl("广东茂名"))
|
||||
}
|
||||
|
||||
func BenchmarkEncodeUrl(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.Log(EncodeUrl("广东茂名"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeUrl(t *testing.T) {
|
||||
t.Log(DecodeUrl("5bm_5Lic6IyC5ZCN"))
|
||||
}
|
||||
|
||||
func BenchmarkDecodeUrl(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.Log(DecodeUrl("5bm_5Lic6IyC5ZCN"))
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package gobase64
|
||||
|
||||
const Version = "1.0.0"
|
@ -0,0 +1,7 @@
|
||||
package gobase64
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
t.Log(Version)
|
||||
}
|
Loading…
Reference in new issue