mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
refactor (#920)
This commit is contained in:
parent
7c842f22d0
commit
9c1ee50497
@ -2,5 +2,6 @@ package trace
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
TraceIdKey = "X-Trace-ID"
|
TraceIdKey = "X-Trace-ID"
|
||||||
|
|
||||||
spanIdKey = "X-Span-ID"
|
spanIdKey = "X-Span-ID"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ func TracingHandler(next http.Handler) http.Handler {
|
|||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
// Conveniently track error messages
|
// conveniently tracking error messages
|
||||||
w.Header().Set(trace.TraceIdKey, span.TraceId())
|
w.Header().Set(trace.TraceIdKey, span.TraceId())
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tal-tech/go-zero/core/stringx"
|
|
||||||
"github.com/tal-tech/go-zero/core/trace"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/tal-tech/go-zero/core/stringx"
|
||||||
|
"github.com/tal-tech/go-zero/core/trace"
|
||||||
"github.com/tal-tech/go-zero/core/trace/tracespec"
|
"github.com/tal-tech/go-zero/core/trace/tracespec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -109,7 +109,8 @@ func (g *DefaultGenerator) GenCall(ctx DirContext, proto parser.Proto, cfg *conf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMessageName(msg proto.Message) string {
|
func getMessageName(msg proto.Message) string {
|
||||||
var list = []string{msg.Name}
|
list := []string{msg.Name}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
parent := msg.Parent
|
parent := msg.Parent
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
@ -125,11 +126,13 @@ func getMessageName(msg proto.Message) string {
|
|||||||
list = append(tmp, list...)
|
list = append(tmp, list...)
|
||||||
msg = *parentMsg
|
msg = *parentMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.Join(list, "_")
|
return strings.Join(list, "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *DefaultGenerator) genFunction(goPackage string, service parser.Service) ([]string, error) {
|
func (g *DefaultGenerator) genFunction(goPackage string, service parser.Service) ([]string, error) {
|
||||||
functions := make([]string, 0)
|
functions := make([]string, 0)
|
||||||
|
|
||||||
for _, rpc := range service.RPC {
|
for _, rpc := range service.RPC {
|
||||||
text, err := util.LoadTemplate(category, callFunctionTemplateFile, callFunctionTemplate)
|
text, err := util.LoadTemplate(category, callFunctionTemplateFile, callFunctionTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -157,6 +160,7 @@ func (g *DefaultGenerator) genFunction(goPackage string, service parser.Service)
|
|||||||
|
|
||||||
functions = append(functions, buffer.String())
|
functions = append(functions, buffer.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return functions, nil
|
return functions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user