Merge pull request #1 from QuentinPerez/fix-race
🐛 fix race condition on ProtoHelpersFuncMap
This commit is contained in:
commit
d7c3d1a32b
13
encoder.go
13
encoder.go
@ -37,6 +37,12 @@ var ProtoHelpersFuncMap = template.FuncMap{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for k, v := range sprig.TxtFuncMap() {
|
||||||
|
ProtoHelpersFuncMap[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type GenericTemplateBasedEncoder struct {
|
type GenericTemplateBasedEncoder struct {
|
||||||
templateDir string
|
templateDir string
|
||||||
service *descriptor.ServiceDescriptorProto
|
service *descriptor.ServiceDescriptorProto
|
||||||
@ -125,9 +131,6 @@ func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, err
|
|||||||
Service: e.service,
|
Service: e.service,
|
||||||
}
|
}
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
for k, v := range sprig.TxtFuncMap() {
|
|
||||||
ProtoHelpersFuncMap[k] = v
|
|
||||||
}
|
|
||||||
tmpl, err := template.New("").Funcs(ProtoHelpersFuncMap).Parse(templateFilename)
|
tmpl, err := template.New("").Funcs(ProtoHelpersFuncMap).Parse(templateFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -143,9 +146,7 @@ func (e *GenericTemplateBasedEncoder) buildContent(templateFilename string) (str
|
|||||||
// initialize template engine
|
// initialize template engine
|
||||||
fullPath := filepath.Join(e.templateDir, templateFilename)
|
fullPath := filepath.Join(e.templateDir, templateFilename)
|
||||||
templateName := filepath.Base(fullPath)
|
templateName := filepath.Base(fullPath)
|
||||||
for k, v := range sprig.TxtFuncMap() {
|
|
||||||
ProtoHelpersFuncMap[k] = v
|
|
||||||
}
|
|
||||||
tmpl, err := template.New(templateName).Funcs(ProtoHelpersFuncMap).ParseFiles(fullPath)
|
tmpl, err := template.New(templateName).Funcs(ProtoHelpersFuncMap).ParseFiles(fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user