-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
85 lines (70 loc) · 1.95 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
/*
struct Result {
int success;
char* response;
};
*/
import "C"
import (
"encoding/json"
"joelmoss/proscenium/internal/builder"
"joelmoss/proscenium/internal/resolver"
"joelmoss/proscenium/internal/types"
)
//export reset_config
func reset_config() {
types.Config.Reset()
}
// Build the given `path` using the `config`.
//
// - path - The path to build relative to `root`.
// - config
//
//export build_to_string
func build_to_string(filePath *C.char, configJson *C.char) C.struct_Result {
err := json.Unmarshal([]byte(C.GoString(configJson)), &types.Config)
if err != nil {
return C.struct_Result{C.int(0), C.CString(err.Error())}
}
success, result := builder.BuildToString(C.GoString(filePath))
if success {
return C.struct_Result{C.int(1), C.CString(result)}
}
return C.struct_Result{C.int(0), C.CString(result)}
}
// Build the given `path` in the `root`.
//
// - path - The path to build relative to `root`.
// - config
//
//export build_to_path
func build_to_path(filePath *C.char, configJson *C.char) C.struct_Result {
err := json.Unmarshal([]byte(C.GoString(configJson)), &types.Config)
if err != nil {
return C.struct_Result{C.int(0), C.CString(err.Error())}
}
success, result := builder.BuildToPath(C.GoString(filePath))
if success {
return C.struct_Result{C.int(1), C.CString(result)}
}
return C.struct_Result{C.int(0), C.CString(result)}
}
// Resolve the given `path` relative to the `root`.
//
// - path - The path to build relative to `root`.
// - config
//
//export resolve
func resolve(filePath *C.char, configJson *C.char) C.struct_Result {
err := json.Unmarshal([]byte(C.GoString(configJson)), &types.Config)
if err != nil {
return C.struct_Result{C.int(0), C.CString(err.Error())}
}
resolvedPath, err := resolver.Resolve(C.GoString(filePath), "")
if err != nil {
return C.struct_Result{C.int(0), C.CString(string(err.Error()))}
}
return C.struct_Result{C.int(1), C.CString(resolvedPath)}
}
func main() {}