-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export View, Redirect, add test cases
- Loading branch information
Showing
7 changed files
with
84 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
package-lock.json | ||
*.wasm |
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,7 @@ | ||
module route | ||
|
||
go 1.21.3 | ||
|
||
replace github.com/primatejs/go/primate => ../primate | ||
|
||
require github.com/primatejs/go/primate v0.0.0-20231105213429-e38c2a977313 // indirect |
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,7 @@ | ||
{ | ||
"dependencies": { | ||
"@primate/binding": "file:../../primate/packages/binding", | ||
"rcompat": "^0.2.0" | ||
}, | ||
"type": "module" | ||
} |
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,24 @@ | ||
/// {{{ start of primate wrapper, prefix | ||
package main | ||
import "syscall/js" | ||
// }}} end | ||
|
||
import "github.com/primatejs/go/primate"; | ||
|
||
func Get(request primate.Request) interface{} { | ||
//return request.View("1test", map[string]interface{}{ | ||
// "test": 1234, | ||
//}); | ||
//return map[string]interface{}{ | ||
// "test": 1234, | ||
//}; | ||
return primate.View("test", map[string]interface{}{}); | ||
} | ||
|
||
// {{{ start primate wrapper, postfix | ||
func main() { | ||
c := make(chan bool) | ||
js.Global().Set("Get", js.FuncOf(primate.MakeRequest(Get))) | ||
<-c | ||
} | ||
// }}} end |
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,24 @@ | ||
import { Path } from "rcompat/fs"; | ||
import { serve } from "rcompat/http"; | ||
import { make_request, make_response, env } from "@primate/binding/go"; | ||
|
||
env(); | ||
|
||
const cwd = await new Path(import.meta.url); | ||
const { directory } = cwd; | ||
const file = await directory.join("route.wasm").arrayBuffer(); | ||
const typedArray = new Uint8Array(file); | ||
|
||
const go = new globalThis.Go(); | ||
await WebAssembly.instantiate(typedArray, { | ||
...go.importObject, | ||
env: {}}).then(async result => { | ||
go.run(result.instance); | ||
serve(request => { | ||
const get = globalThis.Get; | ||
const response = make_response(get(make_request({ url: new URL(request.url) }))); | ||
console.log(response); | ||
//const $response = typeof response === "object" ? JSON.stringify(response) : response; | ||
return new Response("11"); | ||
}, {host: "0.0.0.0", port: 6161}); | ||
}); |
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,2 @@ | ||
GOOS=js GOARCH=wasm go build -o route.wasm route.go | ||
node run.js |