-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to configure custom protobuf definitions path
- Loading branch information
1 parent
d589143
commit f0ae0b5
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package view | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
const ( | ||
additionalProtoDirsKey = "additional-proto-dirs" | ||
) | ||
|
||
type Settings struct { | ||
AdditionalProtoDirs []string | ||
} | ||
|
||
var ( | ||
ErrRepackingSettings = errors.New("failed repacking settings") | ||
) | ||
|
||
func SettingsFromInterface(in interface{}) (*Settings, error) { | ||
settingsMap, ok := in.(map[string]interface{}) | ||
if !ok { | ||
return nil, fmt.Errorf("%w: settings should have a map[string]interface{} type", ErrRepackingSettings) | ||
} | ||
|
||
var settings Settings | ||
|
||
if value, ok := settingsMap[additionalProtoDirsKey]; ok { | ||
protoDirs, err := StringsSliceFromInterface(value) | ||
if err != nil { | ||
return nil, fmt.Errorf("%w: %s: key = %s", ErrRepackingSettings, err.Error(), additionalProtoDirsKey) | ||
} | ||
settings.AdditionalProtoDirs = protoDirs | ||
} | ||
|
||
return &settings, nil | ||
} | ||
|
||
func StringsSliceFromInterface(in interface{}) ([]string, error) { | ||
interfaceSlice, ok := in.([]interface{}) | ||
if !ok { | ||
return nil, errors.New("field should have a []interface{} type") | ||
} | ||
|
||
var result []string | ||
|
||
for i, item := range interfaceSlice { | ||
str, ok := item.(string) | ||
if !ok { | ||
return nil, fmt.Errorf("item [%d] should have a string type", i) | ||
} | ||
result = append(result, str) | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters