resources: Add NewNamedResource helper

This makes the common pattern of NewResource, SetName, easier. It also
makes it less likely for you to forget to use SetName.
This commit is contained in:
James Shubin
2017-06-17 17:32:52 -04:00
parent e341256627
commit 0dadf3d78a
8 changed files with 41 additions and 36 deletions

View File

@@ -65,11 +65,10 @@ func (obj *MyGAPI) Graph() (*pgraph.Graph, error) {
}
var vertex pgraph.Vertex
for i := uint(0); i < obj.Count; i++ {
n, err := resources.NewResource("noop")
n, err := resources.NewNamedResource("noop", fmt.Sprintf("noop%d", i))
if err != nil {
return nil, err
}
n.SetName(fmt.Sprintf("noop%d", i))
g.AddVertex(n)
if i > 0 {
g.AddEdge(vertex, n, &resources.Edge{Name: fmt.Sprintf("e%d", i)})