Factored dcpMetadataByDir out as a global.
This commit is contained in:
parent
eadcb12812
commit
4370c89058
@ -64,10 +64,7 @@ func TaskSpecgen(t *tasking.T) {
|
|||||||
}
|
}
|
||||||
defer specArchive.Close()
|
defer specArchive.Close()
|
||||||
|
|
||||||
dcpCol := newDcpsCollection(map[string]DCPMetadata{
|
dcpCol := newDcpsCollection()
|
||||||
"Internet Gateway_1": {"internetgateway1"},
|
|
||||||
"Internet Gateway_2": {"internetgateway2"},
|
|
||||||
})
|
|
||||||
for _, f := range globFiles("standardizeddcps/*/*.zip", specArchive.Reader) {
|
for _, f := range globFiles("standardizeddcps/*/*.zip", specArchive.Reader) {
|
||||||
dirName := strings.TrimPrefix(f.Name, "standardizeddcps/")
|
dirName := strings.TrimPrefix(f.Name, "standardizeddcps/")
|
||||||
slashIndex := strings.Index(dirName, "/")
|
slashIndex := strings.Index(dirName, "/")
|
||||||
@ -100,15 +97,18 @@ type DCPMetadata struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
type dcpCollection struct {
|
var dcpMetadataByDir = map[string]DCPMetadata{
|
||||||
dcpMetadataByDir map[string]DCPMetadata
|
"Internet Gateway_1": {"internetgateway1"},
|
||||||
dcpByAlias map[string]*DCP
|
"Internet Gateway_2": {"internetgateway2"},
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDcpsCollection(dcpMetadataByDir map[string]DCPMetadata) *dcpCollection {
|
type dcpCollection struct {
|
||||||
|
dcpByAlias map[string]*DCP
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDcpsCollection() *dcpCollection {
|
||||||
c := &dcpCollection{
|
c := &dcpCollection{
|
||||||
dcpMetadataByDir: dcpMetadataByDir,
|
dcpByAlias: make(map[string]*DCP),
|
||||||
dcpByAlias: make(map[string]*DCP),
|
|
||||||
}
|
}
|
||||||
for _, metadata := range dcpMetadataByDir {
|
for _, metadata := range dcpMetadataByDir {
|
||||||
c.dcpByAlias[metadata.Name] = newDCP(metadata)
|
c.dcpByAlias[metadata.Name] = newDCP(metadata)
|
||||||
@ -117,7 +117,7 @@ func newDcpsCollection(dcpMetadataByDir map[string]DCPMetadata) *dcpCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *dcpCollection) dcpForDir(dirName string) *DCP {
|
func (c *dcpCollection) dcpForDir(dirName string) *DCP {
|
||||||
metadata, ok := c.dcpMetadataByDir[dirName]
|
metadata, ok := dcpMetadataByDir[dirName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user