Skip to content

Commit

Permalink
Replaced all 'interface{}' usage with 'any'
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Nov 15, 2023
1 parent 79bf7b8 commit f671596
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions modules/analyze/export-graph.go
Expand Up @@ -35,7 +35,7 @@ func ExportGraphViz(pg engine.Graph, filename string) error {

type MethodMap map[string]bool

type MapStringInterface map[string]interface{}
type MapStringInterface map[string]any

type CytoGraph struct {
FormatVersion string `json:"format_version"`
Expand Down Expand Up @@ -88,7 +88,7 @@ func GenerateCytoscapeJS(pg engine.Graph, alldetails bool) (CytoGraph, error) {

newnode := CytoFlatElement{
Group: "nodes",
Data: map[string]interface{}{
Data: map[string]any{
"id": fmt.Sprintf("n%v", object.ID()),
"label": object.Label(),
"type": object.Type().String(),
Expand Down
8 changes: 4 additions & 4 deletions modules/analyze/preferences.go
Expand Up @@ -9,15 +9,15 @@ import (
)

type Prefs struct {
data map[string]interface{}
data map[string]any
}

var prefmutex sync.Mutex

func (p *Prefs) Load() error {
prefmutex.Lock()
defer prefmutex.Unlock()
p.data = make(map[string]interface{})
p.data = make(map[string]any)

rawprefs, err := ioutil.ReadFile("preferences.json")
if errors.Is(err, os.ErrNotExist) {
Expand All @@ -41,13 +41,13 @@ func (p *Prefs) Save() error {
return err
}

func (p *Prefs) Set(key string, val interface{}) {
func (p *Prefs) Set(key string, val any) {
prefmutex.Lock()
defer prefmutex.Unlock()
p.data[key] = val
}

func (p *Prefs) Get(key string) interface{} {
func (p *Prefs) Get(key string) any {
prefmutex.Lock()
defer prefmutex.Unlock()
return p.data[key]
Expand Down
2 changes: 1 addition & 1 deletion modules/analyze/webservicefuncs.go
Expand Up @@ -921,7 +921,7 @@ func analysisfuncs(ws *webservice) {
case "GET":
json.NewEncoder(w).Encode(prefs.data)
case "POST":
newprefs := make(map[string]interface{})
newprefs := make(map[string]any)
err := json.NewDecoder(r.Body).Decode(&newprefs)
if err != nil {
w.WriteHeader(500)
Expand Down
18 changes: 9 additions & 9 deletions modules/engine/attributevalue.go
Expand Up @@ -147,7 +147,7 @@ func (avo AttributeValueOne) StringSlice() []string {

type AttributeValue interface {
String() string
Raw() interface{}
Raw() any
IsZero() bool
}

Expand All @@ -164,7 +164,7 @@ func (avo AttributeValueObject) String() string {
return (*Object)(avo.Object).Label() + " (object)"
}

func (avo AttributeValueObject) Raw() interface{} {
func (avo AttributeValueObject) Raw() any {
return (*Object)(avo.Object)
}

Expand All @@ -181,7 +181,7 @@ func (as AttributeValueString) String() string {
return string(as)
}

func (as AttributeValueString) Raw() interface{} {
func (as AttributeValueString) Raw() any {
return string(as)
}

Expand All @@ -195,7 +195,7 @@ func (ab AttributeValueBlob) String() string {
return fmt.Sprintf("% x", []byte(ab))
}

func (ab AttributeValueBlob) Raw() interface{} {
func (ab AttributeValueBlob) Raw() any {
return []byte(ab)
}

Expand All @@ -212,7 +212,7 @@ func (ab AttributeValueBool) String() string {
return "false"
}

func (ab AttributeValueBool) Raw() interface{} {
func (ab AttributeValueBool) Raw() any {
return bool(ab)
}

Expand All @@ -226,7 +226,7 @@ func (as AttributeValueInt) String() string {
return strconv.FormatInt(int64(as), 10)
}

func (as AttributeValueInt) Raw() interface{} {
func (as AttributeValueInt) Raw() any {
return int64(as)
}

Expand All @@ -240,7 +240,7 @@ func (as AttributeValueTime) String() string {
return time.Time(as).Format("20060102150405")
}

func (as AttributeValueTime) Raw() interface{} {
func (as AttributeValueTime) Raw() any {
return time.Time(as)
}

Expand All @@ -254,7 +254,7 @@ func (as AttributeValueSID) String() string {
return windowssecurity.SID(as).String()
}

func (as AttributeValueSID) Raw() interface{} {
func (as AttributeValueSID) Raw() any {
return windowssecurity.SID(as)
}

Expand All @@ -268,7 +268,7 @@ func (as AttributeValueGUID) String() string {
return (uuid.UUID)(as).String()
}

func (as AttributeValueGUID) Raw() interface{} {
func (as AttributeValueGUID) Raw() any {
return uuid.UUID(as)
}

Expand Down
10 changes: 5 additions & 5 deletions modules/engine/graph.go
Expand Up @@ -2,7 +2,7 @@ package engine

import "github.com/lkarlslund/adalanche/modules/ui"

type DynamicFields map[string]interface{}
type DynamicFields map[string]any

type Graph struct {
Nodes []GraphNode
Expand Down Expand Up @@ -142,14 +142,14 @@ type GraphNode struct {
Target bool
}

func (n *GraphNode) Set(key string, value interface{}) {
func (n *GraphNode) Set(key string, value any) {
if n.DynamicFields == nil {
n.DynamicFields = make(DynamicFields)
}
n.DynamicFields[key] = value
}

func (n *GraphNode) Get(key string) interface{} {
func (n *GraphNode) Get(key string) any {
if n.DynamicFields == nil {
return nil
}
Expand All @@ -162,14 +162,14 @@ type GraphEdge struct {
EdgeBitmap
}

func (e *GraphEdge) Set(key string, value interface{}) {
func (e *GraphEdge) Set(key string, value any) {
if e.DynamicFields == nil {
e.DynamicFields = make(DynamicFields)
}
e.DynamicFields[key] = value
}

func (e *GraphEdge) Get(key string) interface{} {
func (e *GraphEdge) Get(key string) any {
if e.DynamicFields == nil {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions modules/engine/object.go
Expand Up @@ -52,7 +52,7 @@ type Object struct {

var IgnoreBlanks = "_IGNOREBLANKS_"

func NewObject(flexinit ...interface{}) *Object {
func NewObject(flexinit ...any) *Object {
var result Object
result.init(0)
result.setFlex(flexinit...)
Expand Down Expand Up @@ -526,7 +526,7 @@ func (o *Object) OneAttrString(attr Attribute) string {
return a.First().String()
}

func (o *Object) OneAttrRaw(attr Attribute) interface{} {
func (o *Object) OneAttrRaw(attr Attribute) any {
a := o.Attr(attr)
if a == nil {
return nil
Expand Down Expand Up @@ -614,18 +614,18 @@ func (o *Object) SetValues(a Attribute, values ...AttributeValue) {
}
}

func (o *Object) SetFlex(flexinit ...interface{}) {
func (o *Object) SetFlex(flexinit ...any) {
o.setFlex(flexinit...)
}

var avsPool = sync.Pool{
New: func() interface{} {
New: func() any {
avs := make(AttributeValueSlice, 0, 16)
return &avs
},
}

func (o *Object) setFlex(flexinit ...interface{}) {
func (o *Object) setFlex(flexinit ...any) {
var ignoreblanks bool

attribute := NonExistingAttribute
Expand Down
12 changes: 6 additions & 6 deletions modules/engine/objects.go
Expand Up @@ -21,7 +21,7 @@ type typestatistics [256]int

type Objects struct {
root *Object
DefaultValues []interface{}
DefaultValues []any
objects gsync.MapOf[ObjectID, *Object]
multiindexes map[AttributePair]*MultiIndex // Uses a map for storage considerations

Expand All @@ -42,7 +42,7 @@ func NewObjects() *Objects {
return &os
}

func (os *Objects) AddDefaultFlex(data ...interface{}) {
func (os *Objects) AddDefaultFlex(data ...any) {
os.DefaultValues = append(os.DefaultValues, data...)
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func (os *Objects) Filter(evaluate func(o *Object) bool) *Objects {
return result
}

func (os *Objects) AddNew(flexinit ...interface{}) *Object {
func (os *Objects) AddNew(flexinit ...any) *Object {
o := NewObject(flexinit...)
if os.DefaultValues != nil {
o.setFlex(os.DefaultValues...)
Expand Down Expand Up @@ -504,7 +504,7 @@ func (os *Objects) IterateParallel(each func(o *Object) bool, parallelFuncs int)
wg.Wait()
}

func (os *Objects) MergeOrAdd(attribute Attribute, value AttributeValue, flexinit ...interface{}) (*Object, bool) {
func (os *Objects) MergeOrAdd(attribute Attribute, value AttributeValue, flexinit ...any) (*Object, bool) {
results, found := os.FindMultiOrAdd(attribute, value, func() *Object {
// Add this is not found
return NewObject(append(flexinit, attribute, value)...)
Expand All @@ -530,7 +530,7 @@ func (os *Objects) FindOrAddObject(o *Object) bool {
return found
}

func (os *Objects) FindOrAdd(attribute Attribute, value AttributeValue, flexinit ...interface{}) (*Object, bool) {
func (os *Objects) FindOrAdd(attribute Attribute, value AttributeValue, flexinit ...any) (*Object, bool) {
o, found := os.FindMultiOrAdd(attribute, value, func() *Object {
return NewObject(append(flexinit, attribute, value)...)
})
Expand All @@ -553,7 +553,7 @@ func (os *Objects) FindTwo(attribute Attribute, value AttributeValue, attribute2
return results.First(), results.Len() == 1
}

func (os *Objects) FindTwoOrAdd(attribute Attribute, value AttributeValue, attribute2 Attribute, value2 AttributeValue, flexinit ...interface{}) (o *Object, found bool) {
func (os *Objects) FindTwoOrAdd(attribute Attribute, value AttributeValue, attribute2 Attribute, value2 AttributeValue, flexinit ...any) (o *Object, found bool) {
results, found := os.FindTwoMultiOrAdd(attribute, value, attribute2, value2, func() *Object {
return NewObject(append(flexinit, attribute, value, attribute2, value2)...)
})
Expand Down
Expand Up @@ -305,8 +305,8 @@ func (c *ControlInteger) String() string {
return fmt.Sprintf("Control Type: %v Critiality: %t Control Value: %v", c.ControlType, c.Criticality, c.ControlValue)
}

func LDAPtoMaptringInterface(e *ldap.Entry) map[string]interface{} {
result := make(map[string]interface{})
func LDAPtoMaptringInterface(e *ldap.Entry) map[string]any {
result := make(map[string]any)
for _, attribute := range e.Attributes {
if len(attribute.Values) == 1 {
result[attribute.Name] = attribute.Values[0]
Expand Down
2 changes: 1 addition & 1 deletion modules/integrations/activedirectory/rawobject.go
Expand Up @@ -76,7 +76,7 @@ func (item *RawObject) IngestLDAP(source *ldap.Entry) error {

// Performance hack
var avsPool = sync.Pool{
New: func() interface{} {
New: func() any {
return make(engine.AttributeValueSlice, 0, 16)
},
}
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/log.go
Expand Up @@ -68,7 +68,7 @@ type Logger struct {
pterm pterm.PrefixPrinter
}

func (t Logger) Msgf(format string, args ...interface{}) Logger {
func (t Logger) Msgf(format string, args ...any) Logger {
outputMutex.Lock()

var timetext string
Expand Down

0 comments on commit f671596

Please sign in to comment.