github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/app/layer_generators/opentracing_layer.go.tmpl (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  // Code generated by "make app-layers"
     5  // DO NOT EDIT
     6  
     7  package opentracing
     8  
     9  import (
    10  	"github.com/opentracing/opentracing-go/ext"
    11  	spanlog "github.com/opentracing/opentracing-go/log"
    12  )
    13  
    14  type {{.Name}} struct {
    15  	app app.AppIface
    16  
    17  	srv *app.Server
    18  
    19  	log              *mlog.Logger
    20  	notificationsLog *mlog.Logger
    21  
    22  
    23  	accountMigration einterfaces.AccountMigrationInterface
    24  	cluster          einterfaces.ClusterInterface
    25  	compliance       einterfaces.ComplianceInterface
    26  	dataRetention    einterfaces.DataRetentionInterface
    27  	searchEngine     *searchengine.Broker
    28  	ldap             einterfaces.LdapInterface
    29  	messageExport    einterfaces.MessageExportInterface
    30  	metrics          einterfaces.MetricsInterface
    31  	notification     einterfaces.NotificationInterface
    32  	saml             einterfaces.SamlInterface
    33  
    34  	httpService httpservice.HTTPService
    35  	imageProxy  *imageproxy.ImageProxy
    36  	timezones   *timezones.Timezones
    37  
    38  
    39  	ctx context.Context
    40  }
    41  
    42  {{range $index, $element := .Methods}}
    43  func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$element.Results | joinResultsForSignature}} {
    44  	origCtx := a.ctx
    45  	span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.{{$index}}")
    46  
    47  	a.ctx = newCtx
    48  	a.app.Srv().Store.SetContext(newCtx)
    49  	defer func() {
    50  		a.app.Srv().Store.SetContext(origCtx)
    51  		a.ctx = origCtx
    52  	}()
    53  	{{range $paramIdx, $param := $element.Params}}
    54  		{{ shouldTrace $element.ParamsToTrace $param.Name }}
    55  	{{end}}
    56  	defer span.Finish()
    57  	{{- if $element.Results | len | eq 0}}
    58  		a.app.{{$index}}({{$element.Params | joinParams}})
    59  	{{else}}
    60  		{{$element.Results | genResultsVars}} := a.app.{{$index}}({{$element.Params | joinParams}})
    61  		{{if $element.Results | errorPresent}}
    62  			if {{$element.Results | errorVar}} != nil {
    63  				span.LogFields(spanlog.Error({{$element.Results | errorVar}}))
    64  				ext.Error.Set(span, true)
    65  			}
    66  		{{end}}
    67  		return {{$element.Results | genResultsVars -}}
    68  	{{end}}}
    69  {{end}}
    70  
    71  func NewOpenTracingAppLayer(childApp app.AppIface, ctx context.Context) *{{.Name}} {
    72  	newApp := {{.Name}}{
    73  		app: childApp,
    74  		ctx: ctx,
    75  	}
    76  
    77  	newApp.srv = childApp.Srv()
    78  	newApp.log = childApp.Log()
    79  	newApp.notificationsLog = childApp.NotificationsLog()
    80  
    81  	newApp.accountMigration = childApp.AccountMigration()
    82  	newApp.cluster = childApp.Cluster()
    83  	newApp.compliance = childApp.Compliance()
    84  	newApp.dataRetention = childApp.DataRetention()
    85  	newApp.searchEngine = childApp.SearchEngine()
    86  	newApp.ldap = childApp.Ldap()
    87  	newApp.messageExport = childApp.MessageExport()
    88  	newApp.metrics = childApp.Metrics()
    89  	newApp.notification = childApp.Notification()
    90  	newApp.saml = childApp.Saml()
    91  	newApp.httpService = childApp.HTTPService()
    92  	newApp.imageProxy = childApp.ImageProxy()
    93  	newApp.timezones = childApp.Timezones()
    94  
    95  
    96  	return &newApp
    97  }
    98  
    99  
   100  func (a *{{.Name}}) Srv() *app.Server {
   101  	return a.srv
   102  }
   103  func (a *{{.Name}}) Log() *mlog.Logger {
   104  	return a.log
   105  }
   106  func (a *{{.Name}}) NotificationsLog() *mlog.Logger {
   107  	return a.notificationsLog
   108  }
   109  
   110  func (a *{{.Name}}) AccountMigration() einterfaces.AccountMigrationInterface {
   111  	return a.accountMigration
   112  }
   113  func (a *{{.Name}}) Cluster() einterfaces.ClusterInterface {
   114  	return a.cluster
   115  }
   116  func (a *{{.Name}}) Compliance() einterfaces.ComplianceInterface {
   117  	return a.compliance
   118  }
   119  func (a *{{.Name}}) DataRetention() einterfaces.DataRetentionInterface {
   120  	return a.dataRetention
   121  }
   122  func (a *{{.Name}}) Ldap() einterfaces.LdapInterface {
   123  	return a.ldap
   124  }
   125  func (a *{{.Name}}) MessageExport() einterfaces.MessageExportInterface {
   126  	return a.messageExport
   127  }
   128  func (a *{{.Name}}) Metrics() einterfaces.MetricsInterface {
   129  	return a.metrics
   130  }
   131  func (a *{{.Name}}) Notification() einterfaces.NotificationInterface {
   132  	return a.notification
   133  }
   134  func (a *{{.Name}}) Saml() einterfaces.SamlInterface {
   135  	return a.saml
   136  }
   137  func (a *{{.Name}}) HTTPService() httpservice.HTTPService {
   138  	return a.httpService
   139  }
   140  func (a *{{.Name}}) ImageProxy() *imageproxy.ImageProxy {
   141  	return a.imageProxy
   142  }
   143  func (a *{{.Name}}) Timezones() *timezones.Timezones {
   144  	return a.timezones
   145  }
   146  
   147  func (a *{{.Name}}) SetServer(srv *app.Server) {
   148         a.srv = srv
   149  }