Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize go version #2

Merged
merged 1 commit into from
Nov 26, 2024
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
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