feat: add tags feature

This commit is contained in:
Technofab 2022-12-04 20:25:41 +01:00
parent f394814c2e
commit 538ff9c6f6
No known key found for this signature in database
GPG key ID: A0AA746B951C8830
6 changed files with 28 additions and 20 deletions

View file

@ -26,7 +26,7 @@ import (
// CompilerManager is to manage compiler
type CompilerManager interface {
// GetCompiler is used to get compiler of specified proto file path
GetCompiler(ctx context.Context, protoFilePath string) (Compiler, error)
GetCompiler(ctx context.Context, protoFilePath string, tags []string) (Compiler, error)
}
// BasicCompilerManager is the basic implement of CompilerManager
@ -66,8 +66,8 @@ func NewBasicCompilerManager(ctx context.Context,
}
// GetCompiler is used to get compiler of specified proto file path
func (b *BasicCompilerManager) GetCompiler(ctx context.Context, protoFilePath string) (Compiler, error) {
config, err := b.configManager.GetConfig(ctx, protoFilePath)
func (b *BasicCompilerManager) GetCompiler(ctx context.Context, protoFilePath string, tags []string) (Compiler, error) {
config, err := b.configManager.GetConfig(ctx, protoFilePath, tags)
if err != nil {
return nil, err
}

View file

@ -30,7 +30,7 @@ import (
// ConfigManager is used to manage config
type ConfigManager interface {
// GetCompiler is used to get config of specified proto file path
GetConfig(ctx context.Context, protoFilePath string) (configs.ConfigItem, error)
GetConfig(ctx context.Context, protoFilePath string, tags []string) (configs.ConfigItem, error)
}
// NewConfigManager is used to create ConfigManager
@ -55,7 +55,7 @@ func NewBasicConfigManager(log logger.Logger) (*BasicConfigManager, error) {
}
// GetConfig is used to get config of specified proto file path
func (b *BasicConfigManager) GetConfig(ctx context.Context, protoFilePath string) (configs.ConfigItem, error) {
func (b *BasicConfigManager) GetConfig(ctx context.Context, protoFilePath string, tags []string) (configs.ConfigItem, error) {
possiblePath := configs.ListConfigPaths(filepath.Dir(protoFilePath))
for _, configFilePath := range possiblePath {
items, err := b.loadConfig(configFilePath)
@ -67,7 +67,15 @@ func (b *BasicConfigManager) GetConfig(ctx context.Context, protoFilePath string
for _, scope := range config.Config().Scopes {
scopePath := filepath.Join(dir, scope)
if strings.Contains(protoFilePath, scopePath) {
return config, nil
if len(tags) == 0 {
return config, nil
}
b.Logger.LogInfo(nil, "tags %s passed, filtering...", tags)
for _, tag := range tags {
if strings.Contains(tag, config.Config().Tag) {
return config, nil
}
}
}
}
}