summaryrefslogtreecommitdiff
path: root/modules.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules.go')
-rw-r--r--modules.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/modules.go b/modules.go
index a257a69..f1b4765 100644
--- a/modules.go
+++ b/modules.go
@@ -38,6 +38,26 @@ type Module struct {
New func() interface{}
}
+// ID returns a module's ID, which is the
+// last element of its name.
+func (m Module) ID() string {
+ if m.Name == "" {
+ return ""
+ }
+ parts := strings.Split(m.Name, ".")
+ return parts[len(parts)-1]
+}
+
+// Namespace returns the module's namespace (scope)
+// which is all but the last element of its name.
+func (m Module) Namespace() string {
+ lastDot := strings.LastIndex(m.Name, ".")
+ if lastDot < 0 {
+ return ""
+ }
+ return m.Name[:lastDot]
+}
+
func (m Module) String() string { return m.Name }
// RegisterModule registers a module. Modules must call