Replace interface{} with any (#538)

Co-authored-by: Jonas Plum <git@jonasplum.de>
This commit is contained in:
Jonas Plum
2022-10-22 14:50:09 +02:00
committed by GitHub
parent 9200c865f8
commit fb69a1a07b
6 changed files with 192 additions and 193 deletions

View File

@@ -693,9 +693,9 @@ func (s *aqlInterpreter) function(ctx *parser.Function_callContext) {
} }
} }
func unique(array []interface{}) []interface{} { func unique(array []any) []any {
seen := map[interface{}]bool{} seen := map[any]bool{}
var filtered []interface{} var filtered []any
for _, e := range array { for _, e := range array {
_, ok := seen[e] _, ok := seen[e]
if !ok { if !ok {
@@ -707,7 +707,7 @@ func unique(array []interface{}) []interface{} {
return filtered return filtered
} }
func contains(values []interface{}, e interface{}) bool { func contains(values []any, e any) bool {
for _, v := range values { for _, v := range values {
if e == v { if e == v {
return true return true

View File

@@ -33,8 +33,7 @@ rm -rf generated/models/old
rm -rf generated/.openapi-generator generated/.openapi-generator-ignore generated/README.md rm -rf generated/.openapi-generator generated/.openapi-generator-ignore generated/README.md
rm -rf ui/src/client/.openapi-generator ui/src/client/git_push.sh ui/src/client/.gitignore ui/src/client/.openapi-generator-ignore rm -rf ui/src/client/.openapi-generator ui/src/client/git_push.sh ui/src/client/.gitignore ui/src/client/.openapi-generator-ignore
gofmt -w -r 'interface{} -> any' .
go mod tidy go mod tidy
gci write --Section Standard --Section Default --Section "Prefix(github.com/SecurityBrewery/catalyst)" . gci write --Section Standard --Section Default --Section "Prefix(github.com/SecurityBrewery/catalyst)" .
cd internal/maut
gci write --Section Standard --Section Default --Section "Prefix(github.com/jonas-plum/maut)" .
cd ../.. cd ../..

View File

@@ -118,7 +118,7 @@ func parseQueryOptionalBoolArray(r *http.Request, key string) ([]bool, error) {
return parseQueryBoolArray(r, key) return parseQueryBoolArray(r, key)
} }
func parseBody(b []byte, i interface{}) error { func parseBody(b []byte, i any) error {
dec := json.NewDecoder(bytes.NewBuffer(b)) dec := json.NewDecoder(bytes.NewBuffer(b))
err := dec.Decode(i) err := dec.Decode(i)
if err != nil { if err != nil {
@@ -137,7 +137,7 @@ func JSONErrorStatus(w http.ResponseWriter, status int, err error) {
w.Write(b) w.Write(b)
} }
func response(w http.ResponseWriter, v interface{}, err error) { func response(w http.ResponseWriter, v any, err error) {
if err != nil { if err != nil {
var httpError *HTTPError var httpError *HTTPError
if errors.As(err, &httpError) { if errors.As(err, &httpError) {
@@ -172,7 +172,7 @@ func validateSchema(body []byte, schema *gojsonschema.Schema, w http.ResponseWri
validationErrors = append(validationErrors, valdiationError.String()) validationErrors = append(validationErrors, valdiationError.String())
} }
b, _ := json.Marshal(map[string]interface{}{"error": "wrong input", "errors": validationErrors}) b, _ := json.Marshal(map[string]any{"error": "wrong input", "errors": validationErrors})
w.Write(b) w.Write(b)
return true return true
} }

View File

@@ -19,7 +19,7 @@ type Service interface {
CurrentUser(context.Context) (*model.UserResponse, error) CurrentUser(context.Context) (*model.UserResponse, error)
CurrentUserData(context.Context) (*model.UserDataResponse, error) CurrentUserData(context.Context) (*model.UserDataResponse, error)
UpdateCurrentUserData(context.Context, *model.UserData) (*model.UserDataResponse, error) UpdateCurrentUserData(context.Context, *model.UserData) (*model.UserDataResponse, error)
DashboardData(context.Context, string, *string) (map[string]interface{}, error) DashboardData(context.Context, string, *string) (map[string]any, error)
ListDashboards(context.Context) ([]*model.DashboardResponse, error) ListDashboards(context.Context) ([]*model.DashboardResponse, error)
CreateDashboard(context.Context, *model.Dashboard) (*model.DashboardResponse, error) CreateDashboard(context.Context, *model.Dashboard) (*model.DashboardResponse, error)
GetDashboard(context.Context, string) (*model.DashboardResponse, error) GetDashboard(context.Context, string) (*model.DashboardResponse, error)
@@ -60,8 +60,8 @@ type Service interface {
RemoveComment(context.Context, int64, int) (*model.TicketWithTickets, error) RemoveComment(context.Context, int64, int) (*model.TicketWithTickets, error)
AddTicketPlaybook(context.Context, int64, *model.PlaybookTemplateForm) (*model.TicketWithTickets, error) AddTicketPlaybook(context.Context, int64, *model.PlaybookTemplateForm) (*model.TicketWithTickets, error)
RemoveTicketPlaybook(context.Context, int64, string) (*model.TicketWithTickets, error) RemoveTicketPlaybook(context.Context, int64, string) (*model.TicketWithTickets, error)
SetTaskData(context.Context, int64, string, string, map[string]interface{}) (*model.TicketWithTickets, error) SetTaskData(context.Context, int64, string, string, map[string]any) (*model.TicketWithTickets, error)
CompleteTask(context.Context, int64, string, string, map[string]interface{}) (*model.TicketWithTickets, error) CompleteTask(context.Context, int64, string, string, map[string]any) (*model.TicketWithTickets, error)
SetTaskOwner(context.Context, int64, string, string, string) (*model.TicketWithTickets, error) SetTaskOwner(context.Context, int64, string, string, string) (*model.TicketWithTickets, error)
RunTask(context.Context, int64, string, string) error RunTask(context.Context, int64, string, string) error
SetReferences(context.Context, int64, *model.ReferenceArray) (*model.TicketWithTickets, error) SetReferences(context.Context, int64, *model.ReferenceArray) (*model.TicketWithTickets, error)
@@ -901,7 +901,7 @@ func (s *server) setTaskDataHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
var dataP map[string]interface{} var dataP map[string]any
if err := parseBody(body, &dataP); err != nil { if err := parseBody(body, &dataP); err != nil {
JSONError(w, err) JSONError(w, err)
return return
@@ -928,7 +928,7 @@ func (s *server) completeTaskHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
var dataP map[string]interface{} var dataP map[string]any
if err := parseBody(body, &dataP); err != nil { if err := parseBody(body, &dataP); err != nil {
JSONError(w, err) JSONError(w, err)
return return

File diff suppressed because one or more lines are too long

View File

@@ -251,14 +251,14 @@ type DashboardResponse struct {
} }
type Enrichment struct { type Enrichment struct {
Created time.Time `json:"created"` Created time.Time `json:"created"`
Data map[string]interface{} `json:"data"` Data map[string]any `json:"data"`
Name string `json:"name"` Name string `json:"name"`
} }
type EnrichmentForm struct { type EnrichmentForm struct {
Data map[string]interface{} `json:"data"` Data map[string]any `json:"data"`
Name string `json:"name"` Name string `json:"name"`
} }
type File struct { type File struct {
@@ -267,39 +267,39 @@ type File struct {
} }
type Job struct { type Job struct {
Automation string `json:"automation"` Automation string `json:"automation"`
Container *string `json:"container,omitempty"` Container *string `json:"container,omitempty"`
Log *string `json:"log,omitempty"` Log *string `json:"log,omitempty"`
Origin *Origin `json:"origin,omitempty"` Origin *Origin `json:"origin,omitempty"`
Output map[string]interface{} `json:"output,omitempty"` Output map[string]any `json:"output,omitempty"`
Payload interface{} `json:"payload,omitempty"` Payload any `json:"payload,omitempty"`
Running bool `json:"running"` Running bool `json:"running"`
Status string `json:"status"` Status string `json:"status"`
} }
type JobForm struct { type JobForm struct {
Automation string `json:"automation"` Automation string `json:"automation"`
Origin *Origin `json:"origin,omitempty"` Origin *Origin `json:"origin,omitempty"`
Payload interface{} `json:"payload,omitempty"` Payload any `json:"payload,omitempty"`
} }
type JobResponse struct { type JobResponse struct {
Automation string `json:"automation"` Automation string `json:"automation"`
Container *string `json:"container,omitempty"` Container *string `json:"container,omitempty"`
ID string `json:"id"` ID string `json:"id"`
Log *string `json:"log,omitempty"` Log *string `json:"log,omitempty"`
Origin *Origin `json:"origin,omitempty"` Origin *Origin `json:"origin,omitempty"`
Output map[string]interface{} `json:"output,omitempty"` Output map[string]any `json:"output,omitempty"`
Payload interface{} `json:"payload,omitempty"` Payload any `json:"payload,omitempty"`
Status string `json:"status"` Status string `json:"status"`
} }
type JobUpdate struct { type JobUpdate struct {
Container *string `json:"container,omitempty"` Container *string `json:"container,omitempty"`
Log *string `json:"log,omitempty"` Log *string `json:"log,omitempty"`
Output map[string]interface{} `json:"output,omitempty"` Output map[string]any `json:"output,omitempty"`
Running bool `json:"running"` Running bool `json:"running"`
Status string `json:"status"` Status string `json:"status"`
} }
type LogEntry struct { type LogEntry struct {
@@ -312,7 +312,7 @@ type LogEntry struct {
type Message struct { type Message struct {
Context *Context `json:"context,omitempty"` Context *Context `json:"context,omitempty"`
Payload interface{} `json:"payload,omitempty"` Payload any `json:"payload,omitempty"`
Secrets map[string]string `json:"secrets,omitempty"` Secrets map[string]string `json:"secrets,omitempty"`
} }
@@ -385,18 +385,18 @@ type Statistics struct {
} }
type Task struct { type Task struct {
Automation *string `json:"automation,omitempty"` Automation *string `json:"automation,omitempty"`
Closed *time.Time `json:"closed,omitempty"` Closed *time.Time `json:"closed,omitempty"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Data map[string]interface{} `json:"data,omitempty"` Data map[string]any `json:"data,omitempty"`
Done bool `json:"done"` Done bool `json:"done"`
Join *bool `json:"join,omitempty"` Join *bool `json:"join,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Next map[string]string `json:"next,omitempty"` Next map[string]string `json:"next,omitempty"`
Owner *string `json:"owner,omitempty"` Owner *string `json:"owner,omitempty"`
Payload map[string]string `json:"payload,omitempty"` Payload map[string]string `json:"payload,omitempty"`
Schema map[string]interface{} `json:"schema,omitempty"` Schema map[string]any `json:"schema,omitempty"`
Type string `json:"type"` Type string `json:"type"`
} }
type TaskOrigin struct { type TaskOrigin struct {
@@ -406,20 +406,20 @@ type TaskOrigin struct {
} }
type TaskResponse struct { type TaskResponse struct {
Active bool `json:"active"` Active bool `json:"active"`
Automation *string `json:"automation,omitempty"` Automation *string `json:"automation,omitempty"`
Closed *time.Time `json:"closed,omitempty"` Closed *time.Time `json:"closed,omitempty"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Data map[string]interface{} `json:"data,omitempty"` Data map[string]any `json:"data,omitempty"`
Done bool `json:"done"` Done bool `json:"done"`
Join *bool `json:"join,omitempty"` Join *bool `json:"join,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Next map[string]string `json:"next,omitempty"` Next map[string]string `json:"next,omitempty"`
Order int64 `json:"order"` Order int64 `json:"order"`
Owner *string `json:"owner,omitempty"` Owner *string `json:"owner,omitempty"`
Payload map[string]string `json:"payload,omitempty"` Payload map[string]string `json:"payload,omitempty"`
Schema map[string]interface{} `json:"schema,omitempty"` Schema map[string]any `json:"schema,omitempty"`
Type string `json:"type"` Type string `json:"type"`
} }
type TaskWithContext struct { type TaskWithContext struct {
@@ -432,28 +432,28 @@ type TaskWithContext struct {
} }
type Ticket struct { type Ticket struct {
Artifacts []*Artifact `json:"artifacts,omitempty"` Artifacts []*Artifact `json:"artifacts,omitempty"`
Comments []*Comment `json:"comments,omitempty"` Comments []*Comment `json:"comments,omitempty"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Details map[string]interface{} `json:"details,omitempty"` Details map[string]any `json:"details,omitempty"`
Files []*File `json:"files,omitempty"` Files []*File `json:"files,omitempty"`
Modified time.Time `json:"modified"` Modified time.Time `json:"modified"`
Name string `json:"name"` Name string `json:"name"`
Owner *string `json:"owner,omitempty"` Owner *string `json:"owner,omitempty"`
Playbooks map[string]*Playbook `json:"playbooks,omitempty"` Playbooks map[string]*Playbook `json:"playbooks,omitempty"`
Read []string `json:"read,omitempty"` Read []string `json:"read,omitempty"`
References []*Reference `json:"references,omitempty"` References []*Reference `json:"references,omitempty"`
Schema string `json:"schema"` Schema string `json:"schema"`
Status string `json:"status"` Status string `json:"status"`
Type string `json:"type"` Type string `json:"type"`
Write []string `json:"write,omitempty"` Write []string `json:"write,omitempty"`
} }
type TicketForm struct { type TicketForm struct {
Artifacts []*Artifact `json:"artifacts,omitempty"` Artifacts []*Artifact `json:"artifacts,omitempty"`
Comments []*Comment `json:"comments,omitempty"` Comments []*Comment `json:"comments,omitempty"`
Created *time.Time `json:"created,omitempty"` Created *time.Time `json:"created,omitempty"`
Details map[string]interface{} `json:"details,omitempty"` Details map[string]any `json:"details,omitempty"`
Files []*File `json:"files,omitempty"` Files []*File `json:"files,omitempty"`
ID *int64 `json:"id,omitempty"` ID *int64 `json:"id,omitempty"`
Modified *time.Time `json:"modified,omitempty"` Modified *time.Time `json:"modified,omitempty"`
@@ -479,7 +479,7 @@ type TicketResponse struct {
Artifacts []*Artifact `json:"artifacts,omitempty"` Artifacts []*Artifact `json:"artifacts,omitempty"`
Comments []*Comment `json:"comments,omitempty"` Comments []*Comment `json:"comments,omitempty"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Details map[string]interface{} `json:"details,omitempty"` Details map[string]any `json:"details,omitempty"`
Files []*File `json:"files,omitempty"` Files []*File `json:"files,omitempty"`
ID int64 `json:"id"` ID int64 `json:"id"`
Modified time.Time `json:"modified"` Modified time.Time `json:"modified"`
@@ -495,22 +495,22 @@ type TicketResponse struct {
} }
type TicketSimpleResponse struct { type TicketSimpleResponse struct {
Artifacts []*Artifact `json:"artifacts,omitempty"` Artifacts []*Artifact `json:"artifacts,omitempty"`
Comments []*Comment `json:"comments,omitempty"` Comments []*Comment `json:"comments,omitempty"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Details map[string]interface{} `json:"details,omitempty"` Details map[string]any `json:"details,omitempty"`
Files []*File `json:"files,omitempty"` Files []*File `json:"files,omitempty"`
ID int64 `json:"id"` ID int64 `json:"id"`
Modified time.Time `json:"modified"` Modified time.Time `json:"modified"`
Name string `json:"name"` Name string `json:"name"`
Owner *string `json:"owner,omitempty"` Owner *string `json:"owner,omitempty"`
Playbooks map[string]*Playbook `json:"playbooks,omitempty"` Playbooks map[string]*Playbook `json:"playbooks,omitempty"`
Read []string `json:"read,omitempty"` Read []string `json:"read,omitempty"`
References []*Reference `json:"references,omitempty"` References []*Reference `json:"references,omitempty"`
Schema string `json:"schema"` Schema string `json:"schema"`
Status string `json:"status"` Status string `json:"status"`
Type string `json:"type"` Type string `json:"type"`
Write []string `json:"write,omitempty"` Write []string `json:"write,omitempty"`
} }
type TicketTemplate struct { type TicketTemplate struct {
@@ -560,7 +560,7 @@ type TicketWithTickets struct {
Artifacts []*Artifact `json:"artifacts,omitempty"` Artifacts []*Artifact `json:"artifacts,omitempty"`
Comments []*Comment `json:"comments,omitempty"` Comments []*Comment `json:"comments,omitempty"`
Created time.Time `json:"created"` Created time.Time `json:"created"`
Details map[string]interface{} `json:"details,omitempty"` Details map[string]any `json:"details,omitempty"`
Files []*File `json:"files,omitempty"` Files []*File `json:"files,omitempty"`
ID int64 `json:"id"` ID int64 `json:"id"`
Logs []*LogEntry `json:"logs,omitempty"` Logs []*LogEntry `json:"logs,omitempty"`