Skip to content

Commit

Permalink
Finalize go version (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nudded authored Nov 26, 2024
1 parent d7125a9 commit 13dd41b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
25 changes: 13 additions & 12 deletions expression-go/main.go → expression-go/expression.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package main
package expression

// #cgo LDFLAGS: -L../target/release -lexpression_go
// #cgo LDFLAGS: -lexpression_go
// #include <stdio.h>
// #include <stdlib.h>
// #include "bindings.h"
import "C"
import "unsafe"

func main() {
cs := C.CString("concat(event.properties.a, 'test')")
event := C.CString("{\"code\":\"13\",\"timestamp\":2,\"properties\":{\"a\": 123.12}}")
func Evaluate(expression string, event_json string) *string {
cs := C.CString(expression)
event := C.CString(event_json)

// Evaluate the expression
ptr := C.evaluate(cs, event)
if ptr != nil {

result := C.GoString(ptr)
println(result)

C.free_evaluate(ptr)
}

C.free(unsafe.Pointer(cs))
C.free(unsafe.Pointer(event))

if ptr != nil {
result := C.GoString(ptr)
C.free_evaluate(ptr)
return &result
} else {
return nil
}
}
2 changes: 1 addition & 1 deletion expression-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module expressiongo
module github.com/getlago/lago-expression/expression-go

go 1.23.2
2 changes: 0 additions & 2 deletions expression-go/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ pub unsafe extern "C" fn evaluate(input: *const c_char, event: *const c_char) ->

let json = unsafe { CStr::from_ptr(event).to_str().unwrap() };

// TODO: solve the fact that json will contain numbers, deserialize will fail as it's expecting only
// strings. in the Event::properties which is a HashMap<String, String>
let Ok(event) = serde_json::from_str(json) else {
return null_mut();
};
Expand Down

0 comments on commit 13dd41b

Please sign in to comment.