Skip to content

Commit 45e77dd

Browse files
committed
update doc
1 parent d74d450 commit 45e77dd

File tree

15 files changed

+55
-33
lines changed

15 files changed

+55
-33
lines changed

.github/RELEASE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## Change log
22

3-
- Fix template.
3+
- Support setting custom request id key name.
4+
- Add delayed queuing, publish-subscribe functionality to the pkg/rabbitmq library.
5+
- Add clustering, sentinel functionality to pkg/goredis.
6+
- Fix the discovered bugs.
47
- Update Documentation.

api/serverNameExample/v1/userExample.proto

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ service userExample {
183183
// (2) When using the protoc-gen-openapiv2 plugin, if the defined fields are snake case,
184184
// you must add annotations for snake case names, such as string foo_bar = 1 [json_name = "foo_bar"],
185185
// to ensure that the front end and back end JSON naming is consistent.
186-
// (3) If the declared route path includes a variable, such as /api/v1/userExample/{id},
187-
// the request parameter of the rpc method contains the route variable field and this field
188-
// must be annotated, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""]; If the get method is used,
189-
// the request parameters must be annotated with form, e.g. uint productID = 1 [(tagger.tags) = "form:\"productID\""].
186+
// (3) If the route contains the path parameter, such as /api/v1/userExample/{id}, the defined
187+
// message must contain the name of the path parameter and the name should be
188+
// added with a new tag, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""];
189+
// (4) If the request url is followed by a query parameter, such as /api/v1/getUserExample?name=Tom,
190+
// a form tag must be added when defining the query parameter in the message,
191+
// such as string name = 1 [(tagger.tags) = "form:\"name\""].
190192

191193

192194
enum GenderType {

api/types/types.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ message Params {
1313

1414
message Column {
1515
string name = 1; // column name
16-
string exp = 2; // expressions, which default to = when the value is null, have =, !=, >, >=, <, <=, like
16+
string exp = 2; // expressions, which default to = when the value is null, have =, !=, >, >=, <, <=, like, in
1717
string value = 3; // column value
1818
string logic = 4; // logical type, defaults to and when value is null, only &(and), ||(or)
1919
}

cmd/protoc-gen-go-gin/internal/generate/service/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func {{.LowerName}}Router(
139139
middleware.ContextRequestIDKey: middleware.GCtxRequestID(c), // request_id
140140
//middleware.HeaderAuthorizationKey: c.GetHeader(middleware.HeaderAuthorizationKey), // authorization
141141
})
142-
return metadata.NewOutgoingContext(c, md)
142+
return metadata.NewOutgoingContext(c.Request.Context(), md)
143143
}
144144
145145
serverNameExampleV1.Register{{.Name}}Router(

cmd/sponge/commands/patch/copy-proto.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,15 @@ func (c *protoCopier) copyProtoFile(srcProtoFile string, targetProtoFile string,
204204
// replace go_package
205205
pbContent, err := os.ReadFile(srcProtoFile)
206206
if err != nil {
207-
return fmt.Errorf("read file %s error, %v\n", srcProtoFile, err)
207+
return fmt.Errorf("read file %s error, %v", srcProtoFile, err)
208208
}
209209
pbContent = c.replacePackage(pbContent, isDependency)
210210

211211
tmpFile := os.TempDir() + gofile.GetPathDelimiter() + gofile.GetFilename(srcProtoFile)
212-
err = os.WriteFile(tmpFile, pbContent, 0644)
212+
err = os.WriteFile(tmpFile, pbContent, 0666)
213+
if err != nil {
214+
return err
215+
}
213216

214217
fmt.Printf("copy \"%s\" --> \"%s\"\n", srcProtoFile, targetProtoFile)
215218
_, err = gobash.Exec("mv", "-f", tmpFile, targetProtoFile)

configs/serverNameExample.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ mysql:
8080
# dsn format, <user>:<pass>@(127.0.0.1:3306)/<db>?[k=v& ......]
8181
dsn: "root:123456@(192.168.3.37:3306)/account?parseTime=true&loc=Local&charset=utf8,utf8mb4"
8282
enableLog: true # whether to turn on printing of all logs
83-
slowThreshold: 0 # if greater than 0, only print logs with a time greater than the threshold, with a higher priority than enableLog, in (ms)
8483
maxIdleConns: 3 # set the maximum number of connections in the idle connection pool
8584
maxOpenConns: 100 # set the maximum number of open database connections
8685
connMaxLifetime: 30 # sets the maximum time for which the connection can be reused, in minutes

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,6 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
569569
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
570570
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
571571
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
572-
github.com/rabbitmq/amqp091-go v1.8.1 h1:RejT1SBUim5doqcL6s7iN6SBmsQqyTgXb1xMlH0h1hA=
573-
github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
574572
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
575573
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
576574
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=

internal/routers/userExample_router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func userExampleServiceRouter(
3535
middleware.ContextRequestIDKey: middleware.GCtxRequestID(c), // request_id
3636
//middleware.HeaderAuthorizationKey: c.GetHeader(middleware.HeaderAuthorizationKey), // authorization
3737
})
38-
return metadata.NewOutgoingContext(c, md)
38+
return metadata.NewOutgoingContext(c.Request.Context(), md)
3939
}
4040

4141
serverNameExampleV1.RegisterUserExampleRouter(

pkg/gin/middleware/requstid.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,13 @@ func HeaderRequestIDField(c *gin.Context) zap.Field {
130130

131131
// -------------------------------------------------------------------------------------------
132132

133-
type metaData struct{}
133+
// RequestHeaderKey request header key
134+
var RequestHeaderKey = "request_header_key"
134135

135136
// WrapCtx wrap context, put the Keys and Header of gin.Context into context
136137
func WrapCtx(c *gin.Context) context.Context {
137-
return context.WithValue(c, metaData{}, c.Request.Header)
138+
ctx := context.WithValue(c.Request.Context(), ContextRequestIDKey, c.GetString(ContextRequestIDKey)) //nolint
139+
return context.WithValue(ctx, RequestHeaderKey, c.Request.Header) //nolint
138140
}
139141

140142
// GetFromCtx get value from context
@@ -158,7 +160,7 @@ func CtxRequestIDField(ctx context.Context) zap.Field {
158160

159161
// GetFromHeader get value from header
160162
func GetFromHeader(ctx context.Context, key string) string {
161-
header, ok := ctx.Value(metaData{}).(http.Header)
163+
header, ok := ctx.Value(RequestHeaderKey).(http.Header)
162164
if !ok {
163165
return ""
164166
}
@@ -167,7 +169,7 @@ func GetFromHeader(ctx context.Context, key string) string {
167169

168170
// GetFromHeaders get values from header
169171
func GetFromHeaders(ctx context.Context, key string) []string {
170-
header, ok := ctx.Value(metaData{}).(http.Header)
172+
header, ok := ctx.Value(RequestHeaderKey).(http.Header)
171173
if !ok {
172174
return []string{}
173175
}

pkg/grpc/interceptor/requstid.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ type CtxKeyString string
3434
// RequestIDKey request_id
3535
var RequestIDKey = CtxKeyString(ContextRequestIDKey)
3636

37+
// CtxRequestIDField get request id field from context.Context
38+
func CtxRequestIDField(ctx context.Context) zap.Field {
39+
return zap.String(ContextRequestIDKey, metautils.ExtractOutgoing(ctx).Get(ContextRequestIDKey))
40+
}
41+
3742
// ---------------------------------- client interceptor ----------------------------------
3843

3944
// ClientCtxRequestID get request id from rpc client context.Context

pkg/grpc/interceptor/requstid_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ func TestCtxRequestIDField(t *testing.T) {
559559
assert.NotNil(t, field)
560560
field = ServerCtxRequestIDField(context.Background())
561561
assert.NotNil(t, field)
562+
field = CtxRequestIDField(context.Background())
563+
assert.NotNil(t, field)
562564
}
563565

564566
func TestSetContextRequestIDKey(t *testing.T) {

pkg/prof/profile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ func (p *profile) checkTimeout() {
157157
ctx, _ := context.WithTimeout(context.Background(), time.Second*time.Duration(durationSecond)) //nolint
158158
select {
159159
case <-p.stopCh:
160-
fmt.Println("[profile] reason for stopping: manual")
160+
fmt.Println("[profile] stop collecting profiles: manual")
161161
return
162162
case <-ctx.Done():
163163
if isStop() {
164164
p.stopProfile()
165165
}
166-
fmt.Println("[profile] reason for stopping: timeout")
166+
fmt.Println("[profile] stop collecting profiles: time is up")
167167
}
168168
}
169169

pkg/shield/cpu/stat.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ type CPU interface {
2222
}
2323

2424
func init() {
25-
var (
26-
err error
27-
)
25+
var err error
2826
stats, err = newCgroupCPU()
2927
if err != nil {
30-
// fmt.Printf("cgroup cpu init failed(%v),switch to psutil cpu\n", err)
28+
errStr := err.Error()
3129
stats, err = newPsutilCPU(interval)
3230
if err != nil {
33-
panic(fmt.Sprintf("cgroup cpu init failed!err:=%v", err))
31+
errStr += " | " + err.Error()
32+
fmt.Printf(`
33+
[ERROR] cgroup cpu init and psutil cpu init are all failed, %s.
34+
the dependency library https://github.com/shirou/gopsutil does not support getting this CPU information.
35+
36+
[NOTE] After using the project code generated by sponge, please set "enableStat", "enableLimit" and "enableCircuitBreaker"
37+
in configs/xxx.yml to false, which will not affect the normal use of the application.
38+
39+
`, errStr)
40+
return
3441
}
3542
}
3643
go func() {

pkg/sql2code/parser/template.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,12 @@ service {{.TName}} {
370370
// (2) When using the protoc-gen-openapiv2 plugin, if the defined fields are snake case,
371371
// you must add annotations for snake case names, such as string foo_bar = 1 [json_name = "foo_bar"],
372372
// to ensure that the front end and back end JSON naming is consistent.
373-
// (3) If the declared route path includes a variable, such as /api/v1/userExample/{id},
374-
// the request parameter of the rpc method contains the route variable field and this field
375-
// must be annotated, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""]; If the get method is used,
376-
// the request parameters must be annotated with form, e.g. uint productID = 1 [(tagger.tags) = "form:\"productID\""].
373+
// (3) If the route contains the path parameter, such as /api/v1/userExample/{id}, the defined
374+
// message must contain the name of the path parameter and the name should be
375+
// added with a new tag, such as int64 id = 1 [(tagger.tags) = "uri:\"id\""];
376+
// (4) If the request url is followed by a query parameter, such as /api/v1/getUserExample?name=Tom,
377+
// a form tag must be added when defining the query parameter in the message,
378+
// such as string name = 1 [(tagger.tags) = "form:\"name\""];
377379
378380
379381
// protoMessageCreateCode

pkg/stat/cpu/cpu.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import (
55
"fmt"
66
"os"
77
"strconv"
8-
"time"
98

109
"github.com/shirou/gopsutil/v3/cpu"
1110
"github.com/shirou/gopsutil/v3/process"
1211
)
1312

1413
// System cpu information
1514
type System struct {
16-
UsagePercent float64 `json:"usage_percent"` // cpu usage, unit(%)
15+
UsagePercent float64 `json:"usage_percent"` // cpu usage, unit(%), current logical CPU usage, total usage is cores*UsagePercent
1716
CPUInfo []CPUInfo `json:"cpu_info"`
1817
}
1918

@@ -26,7 +25,7 @@ type CPUInfo struct {
2625

2726
// Process information
2827
type Process struct {
29-
UsagePercent float64 `json:"usage_percent"` // cpu usage, unit(%)
28+
UsagePercent float64 `json:"usage_percent"` // cpu usage, unit(%), current process occupies current logical CPU, total usage is cores*UsagePercent
3029

3130
RSS uint64 `json:"rss"` // use of physical memory, unit(M)
3231
VMS uint64 `json:"vms"` // use of virtual memory, unit(M)
@@ -35,12 +34,12 @@ type Process struct {
3534
// GetSystemCPU get system cpu info
3635
func GetSystemCPU() *System {
3736
sysUsagePercent := 0.0
38-
vs, err := cpu.Percent(time.Millisecond*10, false)
37+
vs, err := cpu.Percent(0, false) // total cpu Percent
3938
if err != nil {
4039
fmt.Printf("cpu.Percent error, %v\n", err)
4140
}
4241
if len(vs) == 1 {
43-
sysUsagePercent = vs[0]
42+
sysUsagePercent = vs[0] * 10
4443
}
4544

4645
var cpuInfos []CPUInfo

0 commit comments

Comments
 (0)