Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: unnecessary use of fmt.Sprintf #15

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fcddcdd
[ultimate-go]
Dec 1, 2022
5f866ea
[diagnostics] up
Dec 5, 2022
e6bc8fa
[build-in-package] singleflight.go
Dec 11, 2022
811253b
[diagnotics] trace.go
Dec 11, 2022
bd515ad
[build-in-package] add ip2int and int2ip
Dec 11, 2022
a363cc6
[build-in-package] add simplehttpserver.go
Dec 11, 2022
cb272b6
[ultimate-go] add cli
Dec 11, 2022
6a2b85f
[ultimate-go] add cli
Dec 11, 2022
f41583d
[ultimate-go] up cli , add cli Flag and Flag Destination
Dec 11, 2022
46fa02d
[ultimate-go] up
Dec 12, 2022
208d707
[packr] config tmpl
Dec 12, 2022
bd92d98
[ultimate-go] packr init
Dec 12, 2022
a337df9
[ultimate-go] protoc , gogoproto , gen message, gen grpc ,gen gateway…
Dec 19, 2022
a0ee34a
[ultimate-go] protoc , gogoproto , gen message, gen grpc ,gen gateway…
Dec 19, 2022
a5310f9
[ultimate-go] up
Dec 20, 2022
d412f43
[ultimate-go] update
Dec 21, 2022
48cdfbe
[build-in-package] net tcp conn
Dec 21, 2022
d0a0fd2
[build-in-package] net tcp conn
Dec 21, 2022
18ffb18
[build-in-package] dns lookup
Dec 21, 2022
3f14f59
[encoding] update
Dec 21, 2022
3d5622e
[build-in-package] websocket echo
Dec 22, 2022
5c58bdc
update readme.md
Dec 22, 2022
77d8757
add gorilla websocket service and client
Dec 23, 2022
1788db9
gorilla-websocket, mv to chat
Dec 23, 2022
77618eb
[awesome-go] add consul register.go and register_test.go
Dec 25, 2022
4337ee1
grpc-go add consul register
Dec 25, 2022
4148891
grpc-go add register and grpc consul resolver
Dec 25, 2022
b02d3c6
format register_test.go
Dec 25, 2022
1ea4e78
consul init consul-resolver.go
Dec 25, 2022
6351e2d
grpc-go update version
Dec 25, 2022
5161087
update readme.md
Dec 25, 2022
20a2b4b
update readme.md
Dec 25, 2022
ae7da5a
kubernetes with istio
Dec 27, 2022
6d5a084
add configmaps
Dec 27, 2022
5c0839d
add configmaps
Dec 27, 2022
84d2aac
use istio ingress
Dec 28, 2022
285b36a
[build-in-package] sync pool
Dec 28, 2022
382d4b2
[build-in-package] timers retry by timer
Dec 29, 2022
7c15930
add docker test
betty200744 Dec 29, 2022
cba00e4
add sqlx
betty200744 Dec 29, 2022
2da5fdf
chore: unnecessary use of fmt.Sprintf
testwill Jul 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/build-in-package/http/keyboard.jpeg
/awesome-go/rpcx/registry/consul/server/server.go
/awesome-go/rpcx/registry/multiple/server/server.go
/.idea/codeStyles/codeStyleConfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"gobyexample/Language_Specification/errors"
"ultimate-go/Language_Specification/errors"
)

// panic, 立刻stops execution the current function, then unwinding the stack, then run deferred functions
Expand Down
24 changes: 0 additions & 24 deletions Language_Specification/build-in-type/flag.go

This file was deleted.

43 changes: 43 additions & 0 deletions Language_Specification/build-in-type/str/str.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package str

import (
"encoding/base64"
"fmt"
"strconv"
"strings"
)

func Base64Encode(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
func Base64Decode(s string) string {
b, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return ""
}
return string(b[:])
}
func IdsString2Slice(s string) []int64 {
if s == "" {
return []int64{}
}
arr := strings.Split(s, ",")
n := len(arr)
ids := make([]int64, 0, n)
for _, s2 := range arr {
i64, err := strconv.ParseInt(s2, 10, 64)
if err == nil {
ids = append(ids, i64)
}
}
return ids
}
func Slice2IdsString(ids []int64) string {
arr := make([]string, len(ids))
for i, id := range ids {
arr[i] = fmt.Sprintf("%d", id)
}
s := ""
s = strings.Join(arr, ",")
return s
}
106 changes: 106 additions & 0 deletions Language_Specification/build-in-type/str/str_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package str

import (
"reflect"
"testing"
)

func TestIdsString2Slice(t *testing.T) {
type args struct {
ids string
}
tests := []struct {
name string
args args
want []int64
}{
{
name: "IdsString2Slice",
args: args{ids: "1,2,3"},
want: []int64{1, 2, 3},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IdsString2Slice(tt.args.ids); !reflect.DeepEqual(got, tt.want) {
t.Errorf("String2SliceInt64() = %v, want %v", got, tt.want)
}
})
}
}

func TestSlice2IdsString(t *testing.T) {
type args struct {
ids []int64
}
tests := []struct {
name string
args args
want string
}{
{
name: "IdsString2Slice",
args: args{
ids: []int64{1, 2, 3},
},
want: "1,2,3",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Slice2IdsString(tt.args.ids); got != tt.want {
t.Errorf("Slice2IdsString() = %v, want %v", got, tt.want)
}
})
}
}

func TestBase64Encode(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Base64Encode",
args: args{s: "sss"},
want: "c3Nz",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Base64Encode(tt.args.s); got != tt.want {
t.Errorf("Base64Encode() = %v, want %v", got, tt.want)
}
})
}
}

func TestBase64Decode(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{
name: "Base64Decode",
args: args{
s: "c3Nz",
},
want: "sss",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Base64Decode(tt.args.s); got != tt.want {
t.Errorf("Base64Decode() = %v, want %v", got, tt.want)
}
})
}
}
8 changes: 0 additions & 8 deletions Language_Specification/build-in-type/string/string.go

This file was deleted.

26 changes: 0 additions & 26 deletions Language_Specification/build-in-type/string/string_cheat_sheet.go

This file was deleted.

8 changes: 4 additions & 4 deletions Language_Specification/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ package main
import "fmt"

const (
A1 = iota // 如同数据库里面的serial, 自增, iota默认Increment by 1
A1 = iota // like mysql serial, auto increment, iota default increment by 1
A2
A3
)
const (
B1 = iota + 2 // start by iot + 2,即2, Increment by iot, 即1
B1 = iota + 2 // start by iot + 2, that is 2, Increment by iot, that is 1
B2
B3
)
const (
C1 = iota * 2 // start iot*2, 即0, Increment by iot * 2, 即2
C1 = iota * 2 // start iot*2, that 0, Increment by iot * 2, that is 2
C2
C3
C4
)
const (
D1 = 1 << iota // start by 1 , Increment by iot * iot
D1 = 1 << 2 // start by 1 , left shift 1
D2
D3
D4
Expand Down
2 changes: 1 addition & 1 deletion Language_Specification/exporting/exporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"gobyexample/Language_Specification/exporting/codes"
"ultimate-go/Language_Specification/exporting/codes"
)

// -------------------
Expand Down
12 changes: 12 additions & 0 deletions Language_Specification/import/bar/bar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package bar

import (
"fmt"
)

type Bar struct {
}

func (b *Bar) Bar() {
fmt.Println("this bar")
}
25 changes: 25 additions & 0 deletions Language_Specification/import/bar/bar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package bar

import (
"fmt"
"testing"

"ultimate-go/Language_Specification/import/foo"
)

func TestBar_Bar(t *testing.T) {
tests := []struct {
name string
}{
{
name: "test",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &foo.Foo{}
b := &Bar{}
fmt.Println(b, f)
})
}
}
5 changes: 5 additions & 0 deletions Language_Specification/import/barer/barer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package barer

type Barer interface {
Bar()
}
15 changes: 15 additions & 0 deletions Language_Specification/import/foo/foo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package foo

import (
"fmt"

"ultimate-go/Language_Specification/import/barer"
)

type Foo struct {
b barer.Barer
}

func (b *Foo) Bar() {
fmt.Println("this bar")
}
2 changes: 1 addition & 1 deletion Language_Specification/packages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt" // import package
"gobyexample/Language_Specification/packages/app" // import nested package
"ultimate-go/Language_Specification/packages/app" // import nested package
)

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ type Address struct {
}

func main() {
type User struct{}
type User struct{ Name string }
type User1 User // new type User1
type User2 = User // User2 是User类型的别名
// Defining Name type, 相同结构不可=
type User2 = User // User2 is an alias of User
user0 := User{Name: "user0"}
user1 := User1{Name: "user1"}
user2 := User2{Name: "user2"}
fmt.Printf("user0 type: %T, value: %v\n", user0, user0)
fmt.Printf("user1 type: %T, value: %v\n", user1, user1)
fmt.Printf("user2 type: %T, value: %v\n", user2, user2)
// Defining Name type
type Shop struct {
Id string `json:"id"`
Name string `json:"name"`
Owner string `json:"owner"`
Order []string
Address Address `json:"address"`
}
// Defining Anonymous type, 相同结构可=
// Defining Anonymous type
shopAnonymous := struct {
Id string `json:"id"`
Name string `json:"name"`
Expand Down
4 changes: 2 additions & 2 deletions Language_Specification/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func main() {
// Short Variable Declare
aa := 10
bb := "hello"
cc := 3.145
co := 3.145
dd := true

fmt.Printf("aa : %T , value is : [%v] \n", aa, aa)
fmt.Printf("bb : %T , value is : [%v] \n", bb, bb)
fmt.Printf("cc : %T , value is : [%v] \n", cc, cc)
fmt.Printf("co : %T , value is : [%v] \n", co, co)
fmt.Printf("dd : %T , value is : [%v] \n", dd, dd)

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package multiplexing

import (
"fmt"
"gobyexample/LearnConcurrency/communicate_channel/ping_pong"
"testing"
"ultimate-go/LearnConcurrency/communicate_channel/ping_pong"
)

func TestFanIn(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion LearnConcurrency/user_concurrency/user_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"gobyexample/utils"
"ultimate-go/utils"
)

func TestDetailById(t *testing.T) {
Expand Down
Loading