in tools/go-agent/instrument/plugins/instrument.go [317:341]
func (i *Instrument) processPluginConfig(fileContent []byte) error {
configFile, err := decorator.ParseFile(nil, "config.go", fileContent, parser.ParseComments)
if err != nil {
return err
}
for _, decl := range configFile.Decls {
genDecl, ok := decl.(*dst.GenDecl)
// if not var declaration or not contains config directive, then ignore
if !ok || genDecl.Tok != token.VAR || !tools.ContainsDirective(genDecl, consts.DirectiveConfig) {
continue
}
for _, spec := range genDecl.Specs {
valueSpec, ok := spec.(*dst.ValueSpec)
if !ok {
return errors.New(fmt.Sprintf("invalid type of spec for config: %T", spec))
}
enhance, err := NewConfigEnhance(valueSpec, genDecl, i.realInst)
if err != nil {
return err
}
i.enhancements = append(i.enhancements, enhance)
}
}
return nil
}