summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/admin/handlers.go2
-rw-r--r--system/api/handlers.go2
-rw-r--r--system/db/content.go2
-rw-r--r--system/item/types.go22
4 files changed, 17 insertions, 11 deletions
diff --git a/system/admin/handlers.go b/system/admin/handlers.go
index e7dabfe..c5c4a4c 100644
--- a/system/admin/handlers.go
+++ b/system/admin/handlers.go
@@ -1306,7 +1306,7 @@ func editHandler(res http.ResponseWriter, req *http.Request) {
contentType, ok := item.Types[t]
if !ok {
- fmt.Fprintf(res, item.ErrTypeNotRegistered, t)
+ fmt.Fprintf(res, item.ErrTypeNotRegistered.Error(), t)
return
}
post := contentType()
diff --git a/system/api/handlers.go b/system/api/handlers.go
index 8b4a387..869640f 100644
--- a/system/api/handlers.go
+++ b/system/api/handlers.go
@@ -178,7 +178,7 @@ func hide(it interface{}, res http.ResponseWriter, req *http.Request) bool {
// check if should be hidden
if h, ok := it.(item.Hideable); ok {
err := h.Hide(req)
- if err != nil && err.Error() == item.AllowHiddenItem {
+ if err != nil && err == item.ErrAllowHiddenItem {
return false
}
diff --git a/system/db/content.go b/system/db/content.go
index dc4477f..f4671de 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -485,7 +485,7 @@ func postToJSON(ns string, data url.Values) ([]byte, error) {
// find the content type and decode values into it
t, ok := item.Types[ns]
if !ok {
- return nil, fmt.Errorf(item.ErrTypeNotRegistered, ns)
+ return nil, fmt.Errorf(item.ErrTypeNotRegistered.Error(), ns)
}
post := t()
diff --git a/system/item/types.go b/system/item/types.go
index b4b361b..b796309 100644
--- a/system/item/types.go
+++ b/system/item/types.go
@@ -1,8 +1,9 @@
package item
+import "errors"
+
const (
- // ErrTypeNotRegistered means content type isn't registered (not found in Types map)
- ErrTypeNotRegistered = `Error:
+ typeNotRegistered = `Error:
There is no type registered for %[1]s
Add this to the file which defines %[1]s{} in the 'content' package:
@@ -14,13 +15,18 @@ Add this to the file which defines %[1]s{} in the 'content' package:
`
+)
- // AllowHiddenItem should be used as an error to tell a caller of Hideable#Hide
+var (
+ // ErrTypeNotRegistered means content type isn't registered (not found in Types map)
+ ErrTypeNotRegistered = errors.New(typeNotRegistered)
+
+ // ErrAllowHiddenItem should be used as an error to tell a caller of Hideable#Hide
// that this type is hidden, but should be shown in a particular case, i.e.
// if requested by a valid admin or user
- AllowHiddenItem = `Allow hidden item`
-)
+ ErrAllowHiddenItem = errors.New(`Allow hidden item`)
-// Types is a map used to reference a type name to its actual Editable type
-// mainly for lookups in /admin route based utilities
-var Types = make(map[string]func() interface{})
+ // Types is a map used to reference a type name to its actual Editable type
+ // mainly for lookups in /admin route based utilities
+ Types = make(map[string]func() interface{})
+)