@@ -100,6 +100,8 @@ func (p *GoParser) newVar(mod string, pkg string, name string, isConst bool) *Va
100100 IsConst : isConst ,
101101 IsExported : isUpperCase (name [0 ]),
102102 }
103+ p .repoMu .Lock ()
104+ defer p .repoMu .Unlock ()
103105 return p .repo .SetVar (ret .Identity , ret )
104106}
105107
@@ -276,12 +278,16 @@ func (p *GoParser) newFunc(mod, pkg, name string) *Function {
276278 }
277279
278280 ret := & Function {Identity : NewIdentity (mod , pkg , name ), Exported : exported }
281+ p .repoMu .Lock ()
282+ defer p .repoMu .Unlock ()
279283 return p .repo .SetFunction (ret .Identity , ret )
280284}
281285
282286// newType allocate a struct in the repo
283287func (p * GoParser ) newType (mod , pkg , name string ) * Type {
284288 ret := & Type {Identity : NewIdentity (mod , pkg , name ), Exported : isUpperCase (name [0 ])}
289+ p .repoMu .Lock ()
290+ defer p .repoMu .Unlock ()
285291 return p .repo .SetType (ret .Identity , ret )
286292}
287293
@@ -619,7 +625,9 @@ func (p *GoParser) parseType(ctx *fileContext, typDecl *ast.TypeSpec, doc *ast.C
619625 // check if it implements any parser.interfaces
620626 if obj , ok := ctx .pkgTypeInfo .Defs [typDecl .Name ]; ok {
621627 if t := obj .Type (); t != nil {
628+ p .typesMu .Lock ()
622629 p .types [t ] = st .Identity
630+ p .typesMu .Unlock ()
623631 }
624632 }
625633 }
@@ -661,7 +669,9 @@ func (p *GoParser) parseStruct(ctx *fileContext, struName string, name *ast.Iden
661669 st .SubStruct = InsertDependency (st .InlineStruct , dep )
662670 }
663671 // remove the anonymous struct from the repo
672+ p .repoMu .Lock ()
664673 delete (p .repo .GetPackage (as .ModPath , as .PkgPath ).Types , as .Name )
674+ p .repoMu .Unlock ()
665675 } else {
666676 p .collectTypes (ctx , fieldDecl .Type , st , inlined )
667677 }
@@ -671,7 +681,9 @@ func (p *GoParser) parseStruct(ctx *fileContext, struName string, name *ast.Iden
671681 // check if it implements any parser.interfaces
672682 if obj , ok := ctx .pkgTypeInfo .Defs [name ]; ok {
673683 if t := obj .Type (); t != nil {
684+ p .typesMu .Lock ()
674685 p .types [t ] = st .Identity
686+ p .typesMu .Unlock ()
675687 }
676688 }
677689 }
@@ -734,7 +746,9 @@ func (p *GoParser) parseInterface(ctx *fileContext, name *ast.Ident, decl *ast.I
734746 iface := named .Underlying ().(* types.Interface )
735747 // exclude empty interface
736748 if ! iface .Empty () {
749+ p .typesMu .Lock ()
737750 p .interfaces [iface ] = st .Identity
751+ p .typesMu .Unlock ()
738752 }
739753 }
740754 }
0 commit comments