Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from suborbital/jagger/tinygo-api-refactor
Refactor TinyGo API into separate packages
- Loading branch information
Showing
40 changed files
with
276 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/suborbital/reactr/api/tinygo/runnable/internal/ffi" | ||
) | ||
|
||
func Get(key string) ([]byte, error) { | ||
return ffi.CacheGet(key) | ||
} | ||
|
||
func Set(key, val string, ttl int) { | ||
ffi.CacheSet(key, val, ttl) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
api/tinygo/runnable/cache.go → api/tinygo/runnable/internal/ffi/cache.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
//go:build tinygo.wasm | ||
|
||
package runnable | ||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func CacheGet(key string) ([]byte, error) { | ||
ptr, size := rawSlicePointer([]byte(key)) | ||
|
||
return result(C.cache_get(ptr, size, ident())) | ||
return result(C.cache_get(ptr, size, Ident())) | ||
} | ||
|
||
func CacheSet(key, val string, ttl int) { | ||
keyPtr, keySize := rawSlicePointer([]byte(key)) | ||
valPtr, valSize := rawSlicePointer([]byte(val)) | ||
|
||
C.cache_set(keyPtr, keySize, valPtr, valSize, int32(ttl), ident()) | ||
C.cache_set(keyPtr, keySize, valPtr, valSize, int32(ttl), Ident()) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
import ( | ||
"github.com/suborbital/reactr/api/tinygo/runnable/runnable" | ||
) | ||
|
||
var runnable_ runnable.Runnable | ||
var ident_ int32 | ||
|
||
func Ident() int32 { | ||
return ident_ | ||
} | ||
|
||
func Use(runnable runnable.Runnable) { | ||
runnable_ = runnable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func DoHTTPRequest(method int32, urlStr string, body []byte, headers map[string]string) ([]byte, error) { | ||
urlPtr, urlSize := rawSlicePointer([]byte(urlStr)) | ||
bodyPtr, bodySize := rawSlicePointer(body) | ||
|
||
size := C.fetch_url(method, urlPtr, urlSize, bodyPtr, bodySize, Ident()) | ||
|
||
return result(size) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func LogAtLevel(message string, level int32) { | ||
msgPtr, size := rawSlicePointer([]byte(message)) | ||
|
||
C.log_msg(msgPtr, size, level, Ident()) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
|
||
func ReqGetField(fieldType int32, key string) []byte { | ||
ptr, size := rawSlicePointer([]byte(key)) | ||
|
||
res, err := result(C.request_get_field(fieldType, ptr, size, Ident())) | ||
if err != nil { | ||
return []byte{} | ||
} | ||
return res | ||
} | ||
|
||
func ReqSetField(fieldType int32, key string, value string) ([]byte, error) { | ||
keyPtr, keySize := rawSlicePointer([]byte(key)) | ||
valPtr, valSize := rawSlicePointer([]byte(value)) | ||
|
||
return result(C.request_set_field(fieldType, keyPtr, keySize, valPtr, valSize, Ident())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build tinygo.wasm | ||
|
||
package ffi | ||
|
||
// #include <reactr.h> | ||
import "C" | ||
import ( | ||
"github.com/suborbital/reactr/api/tinygo/runnable/runnable" | ||
) | ||
|
||
func result(size int32) ([]byte, runnable.HostErr) { | ||
allocSize := size | ||
|
||
if size < 0 { | ||
if size == -1 { | ||
return nil, runnable.NewHostError("unknown error returned from host") | ||
} | ||
|
||
allocSize = -size | ||
} | ||
|
||
result := make([]byte, allocSize) | ||
resultPtr, _ := rawSlicePointer(result) | ||
|
||
if code := C.get_ffi_result(resultPtr, Ident()); code != 0 { | ||
return nil, runnable.NewHostError("unknown error returned from host") | ||
} | ||
|
||
if size < 0 { | ||
return nil, runnable.NewHostError(string(result)) | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
api/tinygo/runnable/alloc.go → api/tinygo/runnable/internal/ffi/unsafe.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
//go:build tinygo.wasm | ||
|
||
package runnable | ||
package ffi | ||
|
||
import ( | ||
"reflect" | ||
|
14 changes: 6 additions & 8 deletions
14
api/tinygo/runnable/log.go → api/tinygo/runnable/log/log.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.