Add new type in utils MapSubsystemIDs

This commit is contained in:
TeoV
2019-07-02 15:59:43 +03:00
committed by Dan Christian Bogos
parent a246124cc9
commit 763e030f03
2 changed files with 46 additions and 0 deletions

View File

@@ -247,3 +247,24 @@ func MapStringToInt64(in map[string]string) (out map[string]int64, err error) {
}
return mapout, nil
}
func MapSubsystemIDsFromSlice(s []string) (MapSubsystemIDs, error) {
result := make(MapSubsystemIDs, len(s))
for _, v := range s {
subsystemWithIDs := strings.Split(v, InInFieldSep)
result[subsystemWithIDs[0]] = []string{}
if len(subsystemWithIDs) == 2 {
result[subsystemWithIDs[0]] = strings.Split(subsystemWithIDs[1], INFIELD_SEP)
} else if len(subsystemWithIDs) > 2 {
return nil, ErrUnsupportedFormat
}
}
return result, nil
}
type MapSubsystemIDs map[string][]string
func (msIDs MapSubsystemIDs) HasKey(key string) (has bool) {
_, has = msIDs[key]
return
}