Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llx/builtin_global.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func ipCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error)
return nil, 0, errors.New("called `ip` with unsupported type (expected string)")
}

return &RawData{Type: types.IP, Value: raw}, 0, nil
return IPData(raw), 0, nil
}

func stringCall(e *blockExecutor, f *Function, ref uint64) (*RawData, uint64, error) {
Expand Down
17 changes: 17 additions & 0 deletions llx/rawdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ func rawDataString(typ types.Type, value interface{}) string {
default:
return "map[?]?"
}
case types.IP:
return value.(string)
default:
return "?value? (typ:" + typ.Label() + ")"
}
Expand Down Expand Up @@ -588,6 +590,21 @@ func RangeData(r Range) *RawData {
}
}

// IPData creates a rawdata struct from a raw ip address
func IPData(ip string) *RawData {
return &RawData{
Type: types.IP,
Value: ip,
}
}

func IPDataPtr(ip *string) *RawData {
if ip == nil {
return NilData
}
return IPData(*ip)
}

// RawResultByRef is used to sort an array of raw results
type RawResultByRef []*RawResult

Expand Down
1 change: 1 addition & 0 deletions llx/rawdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestRawData_String(t *testing.T) {
{DictData(map[string]interface{}{"a": "b"}), "{\"a\":\"b\"}"},
{ArrayData([]interface{}{"a", "b"}, types.String), "[\"a\",\"b\"]"},
{MapData(map[string]interface{}{"a": "b"}, types.String), "{\"a\":\"b\"}"},
{IPData("1.2.3.4"), "1.2.3.4"},
// implicit nil:
{&RawData{types.String, nil, nil}, "<null>"},
}
Expand Down