Authenticate Handler API and SDK, and much more (#183)
This commit is contained in:
1 parent
acce195dcb
commit
28dbcd84bd
89 files changed
+5296
-1943
No files matched your search
+20
-5
@@ -3,6 +3,7 @@ package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
|
||||
@@ -13,22 +14,36 @@ type Error struct {
|
||||
defaultFields []string
|
||||
|
||||
// The HTTP Status code applicable to this error
|
||||
Status *int32 `json:"status,omitempty"`
|
||||
Status int32 `json:"status,omitempty"`
|
||||
// An application-specific error string
|
||||
Code *string `json:"code,omitempty"`
|
||||
Code string `json:"code,omitempty"`
|
||||
// A human readable explanation specific to this occurrence of the error
|
||||
Message *string `json:"message,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
// Additional metadata regarding the error. Depending on the error
|
||||
// different fields will be populated.
|
||||
Details *ErrorDetails `json:"details,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Error) SetDefault(key string) {
|
||||
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, key)
|
||||
lowerKey := strings.ToLower(key)
|
||||
validMap := map[string]string{"code": "code", "details": "details", "message": "message", "status": "status"}
|
||||
for k, v := range validMap {
|
||||
if k == lowerKey || v == lowerKey {
|
||||
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Error) UnsetDefault(key string) {
|
||||
s.defaultFields = strutil.StrListDelete(s.defaultFields, key)
|
||||
lowerKey := strings.ToLower(key)
|
||||
validMap := map[string]string{"code": "code", "details": "details", "message": "message", "status": "status"}
|
||||
for k, v := range validMap {
|
||||
if k == lowerKey || v == lowerKey {
|
||||
s.defaultFields = strutil.StrListDelete(s.defaultFields, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s Error) MarshalJSON() ([]byte, error) {
|
||||
|
||||
Reference in new issue
Block a user