@@ -2,10 +2,13 @@ package errorx
22
33import "fmt"
44
5- // A namespace is a way go group a number of error types together, and each error type belongs to exactly one namespace
6- // Namespaces may form hierarchy, with child namespaces inheriting the traits and modifiers of a parent
7- // Those modifiers and traits are then passed upon all error types in the namespace
8- // In formatting, a dot notation is used, for example: namespace.sub_namespace.type.subtype
5+ // Namespace is a way go group a number of error types together, and each error type belongs to exactly one namespace.
6+ // Namespaces may form hierarchy, with child namespaces inheriting the traits and modifiers of a parent.
7+ // Those modifiers and traits are then passed upon all error types in the namespace.
8+ // In formatting, a dot notation is used, for example:
9+ //
10+ // namespace.sub_namespace.type.subtype
11+ //
912type Namespace struct {
1013 parent * Namespace
1114 id int64
@@ -14,46 +17,46 @@ type Namespace struct {
1417 modifiers modifiers
1518}
1619
17- // Namespace itself is not comparable, so a key be used instead
20+ // Namespace itself is not comparable, so a key be used instead.
1821type NamespaceKey struct {
1922 id int64
2023 name string
2124}
2225
23- // Define a namespace with a name and, optionally, a number of inheritable traits
26+ // NewNamespace defines a namespace with a name and, optionally, a number of inheritable traits.
2427func NewNamespace (name string , traits ... Trait ) Namespace {
2528 namespace := newNamespace (nil , name , traits ... )
2629 globalRegistry .registerNamespace (namespace )
2730 return namespace
2831}
2932
30- // Define a child namespace that inherits all that is defined for a parent and, optionally, adds some more
33+ // NewSubNamespace defines a child namespace that inherits all that is defined for a parent and, optionally, adds some more.
3134func (n Namespace ) NewSubNamespace (name string , traits ... Trait ) Namespace {
3235 namespace := newNamespace (& n , name , traits ... )
3336 globalRegistry .registerNamespace (namespace )
3437 return namespace
3538}
3639
37- // One -time modification of defaults in error creation
40+ // ApplyModifiers makes a one -time modification of defaults in error creation.
3841func (n Namespace ) ApplyModifiers (modifiers ... TypeModifier ) Namespace {
3942 n .modifiers = n .modifiers .ReplaceWith (newTypeModifiers (modifiers ... ))
4043 return n
4144}
4245
43- // Create a new type within a namespace that inherits all that is defined for namespace and, optionally, adds some more
46+ // NewType creates a new type within a namespace that inherits all that is defined for namespace and, optionally, adds some more.
4447func (n Namespace ) NewType (typeName string , traits ... Trait ) * Type {
4548 return NewType (n , typeName , traits ... )
4649}
4750
48- // A comparison key
51+ // Key returns a comparison key for namespace.
4952func (n Namespace ) Key () NamespaceKey {
5053 return NamespaceKey {
5154 id : n .id ,
5255 name : n .name ,
5356 }
5457}
5558
56- // Check whether or not an error belongs either to this namespace or some of its sub-namespaces
59+ // IsNamespaceOf checks whether or not an error belongs either to this namespace or some of its sub-namespaces.
5760func (n Namespace ) IsNamespaceOf (t * Type ) bool {
5861 namespace := t .namespace
5962 other := & namespace
@@ -69,7 +72,7 @@ func (n Namespace) IsNamespaceOf(t *Type) bool {
6972 return false
7073}
7174
72- // Returns a full name of a namespace
75+ // FullName returns a full name of a namespace.
7376func (n Namespace ) FullName () string {
7477 return n .name
7578}
@@ -78,8 +81,8 @@ func (n Namespace) String() string {
7881 return n .name
7982}
8083
81- // Returns the immediate parent namespace, if present
82- // The use of this function outside of a system layer that handles error types (see TypeSubscriber) is a code smell
84+ // Parent returns the immediate parent namespace, if present.
85+ // The use of this function outside of a system layer that handles error types (see TypeSubscriber) is a code smell.
8386func (n Namespace ) Parent () * Namespace {
8487 return n .parent
8588}
0 commit comments