Migrate grants to more structured output (#194)

This commit is contained in:
Jeff Mitchell authored and GitHub committed 2020-07-16 22:18:27 -04:00
1 parent 1a1d3058c9
commit 99653727bb
19 files changed
+757 -642

No files matched your search

-43
View File
@@ -1,17 +1,7 @@
// Code generated by "make api"; DO NOT EDIT.
package api
import (
"encoding/json"
"strings"
"github.com/fatih/structs"
"github.com/hashicorp/watchtower/api/internal/strutil"
)
type Error struct {
defaultFields []string
// The HTTP Status code applicable to this error
Status int32 `json:"status,omitempty"`
@@ -23,36 +13,3 @@ type Error struct {
// different fields will be populated.
Details *ErrorDetails `json:"details,omitempty"`
}
func (s *Error) SetDefault(key string) {
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) {
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) {
m := structs.Map(s)
if m == nil {
m = make(map[string]interface{})
}
for _, k := range s.defaultFields {
m[k] = nil
}
return json.Marshal(m)
}