MM-26834 - Move opentracing into a separate package (#15011)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ef63afac21
Коммит
b15c0484c6
@@ -14,6 +14,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@@ -25,6 +26,8 @@ var (
|
||||
outputFile string
|
||||
inputFile string
|
||||
outputFileTemplate string
|
||||
basicTypes = map[string]bool{"int": true, "string": true, "float": true, "bool": true, "byte": true, "int64": true, "error": true}
|
||||
textRegexp = regexp.MustCompile(`\w+$`)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -77,6 +80,22 @@ type storeMetadata struct {
|
||||
Methods map[string]methodData
|
||||
}
|
||||
|
||||
func fixTypeName(t string) string {
|
||||
// don't want to dive into AST to parse this, add exception
|
||||
if t == "...func(*UploadFileTask)" {
|
||||
t = "...func(*app.UploadFileTask)"
|
||||
}
|
||||
if strings.Contains(t, ".") || strings.Contains(t, "{}") {
|
||||
return t
|
||||
}
|
||||
typeOnly := textRegexp.FindString(t)
|
||||
|
||||
if _, basicType := basicTypes[typeOnly]; !basicType {
|
||||
t = t[:len(t)-len(typeOnly)] + "app." + typeOnly
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func formatNode(src []byte, node ast.Expr) string {
|
||||
return string(src[node.Pos()-1 : node.End()-1])
|
||||
}
|
||||
@@ -100,7 +119,7 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
if e.Params != nil {
|
||||
for _, param := range e.Params.List {
|
||||
for _, paramName := range param.Names {
|
||||
paramType := (formatNode(src, param.Type))
|
||||
paramType := fixTypeName(formatNode(src, param.Type))
|
||||
params = append(params, methodParam{Name: paramName.Name, Type: paramType})
|
||||
}
|
||||
}
|
||||
@@ -108,7 +127,8 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
|
||||
if e.Results != nil {
|
||||
for _, r := range e.Results.List {
|
||||
typeStr := formatNode(src, r.Type)
|
||||
typeStr := fixTypeName(formatNode(src, r.Type))
|
||||
|
||||
if len(r.Names) > 0 {
|
||||
for _, k := range r.Names {
|
||||
results = append(results, fmt.Sprintf("%s %s", k.Name, typeStr))
|
||||
|
||||
@@ -4,22 +4,23 @@
|
||||
// Code generated by "make app-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package app
|
||||
package opentracing
|
||||
|
||||
import (
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
spanlog "github.com/opentracing/opentracing-go/log"
|
||||
goi18n "github.com/mattermost/go-i18n/i18n"
|
||||
)
|
||||
|
||||
type {{.Name}} struct {
|
||||
app AppIface
|
||||
app app.AppIface
|
||||
|
||||
srv *Server
|
||||
srv *app.Server
|
||||
|
||||
log *mlog.Logger
|
||||
notificationsLog *mlog.Logger
|
||||
|
||||
t goi18n.TranslateFunc
|
||||
t i18n.TranslateFunc
|
||||
session model.Session
|
||||
requestId string
|
||||
ipAddress string
|
||||
@@ -53,9 +54,9 @@ func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$ele
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
{{range $paramIdx, $param := $element.Params}}
|
||||
{{ shouldTrace $element.ParamsToTrace $param.Name }}
|
||||
@@ -70,12 +71,12 @@ func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$ele
|
||||
span.LogFields(spanlog.Error({{$element.Results | errorVar}}))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
return {{$element.Results | genResultsVars -}}
|
||||
{{end}}}
|
||||
{{end}}
|
||||
|
||||
func NewOpenTracingAppLayer(childApp AppIface, ctx context.Context) *{{.Name}} {
|
||||
func NewOpenTracingAppLayer(childApp app.AppIface, ctx context.Context) *{{.Name}} {
|
||||
newApp := {{.Name}}{
|
||||
app: childApp,
|
||||
ctx: ctx,
|
||||
@@ -112,7 +113,7 @@ func NewOpenTracingAppLayer(childApp AppIface, ctx context.Context) *{{.Name}} {
|
||||
}
|
||||
|
||||
|
||||
func (a *{{.Name}}) Srv() *Server {
|
||||
func (a *{{.Name}}) Srv() *app.Server {
|
||||
return a.srv
|
||||
}
|
||||
func (a *{{.Name}}) Log() *mlog.Logger {
|
||||
@@ -184,7 +185,7 @@ func (a *{{.Name}}) Context() context.Context {
|
||||
func (a *{{.Name}}) SetSession(sess *model.Session) {
|
||||
a.session = *sess
|
||||
}
|
||||
func (a *{{.Name}}) SetT(t goi18n.TranslateFunc){
|
||||
func (a *{{.Name}}) SetT(t i18n.TranslateFunc){
|
||||
a.t = t
|
||||
}
|
||||
func (a *{{.Name}}) SetRequestId(str string){
|
||||
@@ -205,9 +206,9 @@ func (a *{{.Name}}) SetPath(str string){
|
||||
func (a *{{.Name}}) SetContext(c context.Context){
|
||||
a.context = c
|
||||
}
|
||||
func (a *{{.Name}}) SetServer(srv *Server) {
|
||||
func (a *{{.Name}}) SetServer(srv *app.Server) {
|
||||
a.srv = srv
|
||||
}
|
||||
func (a *{{.Name}}) GetT() goi18n.TranslateFunc {
|
||||
func (a *{{.Name}}) GetT() i18n.TranslateFunc {
|
||||
return a.t
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user