From 0f0f1d4bc8d09cc511e23cccec81d5ac5c77cbbc Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Thu, 28 Mar 2019 22:50:29 -0400 Subject: [PATCH] Validate the tree only once at creation. --- container/container.go | 3 +++ container/options.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/container/container.go b/container/container.go index 02cd534..af91c87 100644 --- a/container/container.go +++ b/container/container.go @@ -84,6 +84,9 @@ func New(t terminalapi.Terminal, opts ...Option) (*Container, error) { if err := applyOptions(root, opts...); err != nil { return nil, err } + if err := validateOptions(root); err != nil { + return nil, err + } return root, nil } diff --git a/container/options.go b/container/options.go index 9e76583..40b7831 100644 --- a/container/options.go +++ b/container/options.go @@ -35,7 +35,11 @@ func applyOptions(c *Container, opts ...Option) error { return err } } + return nil +} +// validateOptions validates options set in the container tree. +func validateOptions(c *Container) error { // ensure all the container identifiers are either empty or unique. var errStr string seenID := map[string]bool{}