Skip to content

Commit

Permalink
ts and go cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
noise64 committed Aug 16, 2024
1 parent a066371 commit bbb00b5
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 29 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repository = "https://github.com/golemcloud/golem-examples"
description = "Golem example templates"

[dependencies]
clap = { version = "4.4.17", features = ["derive"], optional = true }
colored = "2.1.0"
derive_more = "0.99.17"
golem-wit = { version = "0.4.0" }
include_dir = { version = "0.7.3" }
Expand All @@ -19,8 +21,6 @@ serde_json = { version = "1.0.111" }
strum = "0.26.1"
strum_macros = "0.26.1"

clap = { version = "4.4.17", features = ["derive"], optional = true }

[build-dependencies]
cargo_metadata = "0.18.1"
copy_dir = "0.1.3"
Expand Down
2 changes: 2 additions & 0 deletions examples/go/go-default-minimal/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.PHONY: build bindings compile clean

build: compile
wasm-tools component embed ./wit component_name.module.wasm --output component_name.embed.wasm
wasm-tools component new component_name.embed.wasm -o component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm
Expand Down
2 changes: 2 additions & 0 deletions examples/go/go-default-minimal/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module pack/name

go 1.20

require github.com/golemcloud/golem-go v0.6.0 // indirect
2 changes: 2 additions & 0 deletions examples/go/go-default-minimal/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/golemcloud/golem-go v0.6.0 h1:JkeHRrqqs+k6PTFASwknJVjcLBAvizqonhMO9M5B648=
github.com/golemcloud/golem-go v0.6.0/go.mod h1:VLL22qVo5R2+jGLO43tLPpPjf2WrA6B7GQoqXKnSODo=
8 changes: 3 additions & 5 deletions examples/go/go-default-minimal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
)

func init() {
a := ComponentNameImpl{}
component_name.SetExportsPackNameApi(a)
component_name.SetExportsPackNameApi(&ComponentNameImpl{})
}

// total State can be stored in global variables
Expand All @@ -17,12 +16,11 @@ type ComponentNameImpl struct {

// Implementation of the exported interface


func (e ComponentNameImpl) Add(value uint64) {
func (e *ComponentNameImpl) Add(value uint64) {
total += value
}

func (e ComponentNameImpl) Get() uint64 {
func (e *ComponentNameImpl) Get() uint64 {
return total
}

Expand Down
4 changes: 3 additions & 1 deletion examples/go/go-default/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: build bindings compile clean

build: compile
wasm-tools component embed ./wit component_name.module.wasm --world component-name-imports --output component_name.embed.wasm
wasm-tools component embed ./wit component_name.module.wasm --output component_name.embed.wasm
wasm-tools component new component_name.embed.wasm -o component_name.wasm --adapt adapters/tier1/wasi_snapshot_preview1.wasm

bindings:
Expand Down
2 changes: 1 addition & 1 deletion examples/go/go-default/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module pack/name

go 1.20

require github.com/golemcloud/golem-go v0.4.4 // indirect
require github.com/golemcloud/golem-go v0.6.0
4 changes: 2 additions & 2 deletions examples/go/go-default/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/golemcloud/golem-go v0.4.4 h1:MAxS+jPsJZTdhm/cegzLbPanpLGi1jnfDBq4d1LeEw0=
github.com/golemcloud/golem-go v0.4.4/go.mod h1:O3l4YC7os4nGPWbJc02wPDxsgRelcS5v1L2xxzhNro4=
github.com/golemcloud/golem-go v0.6.0 h1:JkeHRrqqs+k6PTFASwknJVjcLBAvizqonhMO9M5B648=
github.com/golemcloud/golem-go v0.6.0/go.mod h1:VLL22qVo5R2+jGLO43tLPpPjf2WrA6B7GQoqXKnSODo=
17 changes: 9 additions & 8 deletions examples/go/go-default/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package main

import (
"github.com/golemcloud/golem-go/roundtrip"
"pack/name/component_name"
"github.com/golemcloud/golem-go/std"

"net/http"
"pack/name/component_name"
)

type RequestBody struct {
Expand All @@ -16,9 +15,7 @@ type ResponseBody struct {
}

func init() {
a := ComponentNameImpl{}
component_name.SetExportsPackNameApi(a)
http.DefaultClient.Transport = roundtrip.WasiHttpTransport{}
component_name.SetExportsPackNameApi(&ComponentNameImpl{})
}

// total State can be stored in global variables
Expand All @@ -29,11 +26,15 @@ type ComponentNameImpl struct {

// Implementation of the exported interface

func (e ComponentNameImpl) Add(value uint64) {
func (e *ComponentNameImpl) Add(value uint64) {
std.Init(std.Packages{Os: true, NetHttp: true})

total += value
}

func (e ComponentNameImpl) Get() uint64 {
func (e *ComponentNameImpl) Get() uint64 {
std.Init(std.Packages{Os: true, NetHttp: true})

return total
}

Expand Down
6 changes: 1 addition & 5 deletions examples/go/go-default/wit/component-name.wit
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ interface api {
}

world component-name {
export api;
}

world component-name-imports {
import golem:api/host@0.2.0;
import golem:rpc/types@0.1.0;

Expand All @@ -36,5 +32,5 @@ world component-name-imports {
import wasi:sockets/ip-name-lookup@0.2.0;
import wasi:sockets/instance-network@0.2.0;

include component-name;
export api;
}
2 changes: 1 addition & 1 deletion examples/ts/ts-default-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stub": "jco stubgen wit -o src/generated",
"build": "rollup --config",
"componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js",
"clean": "rm -rf out src/interfaces src/main.d.ts"
"clean": "rm -rf out src/generated"
},
"devDependencies": {
"@golemcloud/componentize-js": "0.10.2-golem.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/ts-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stub": "jco stubgen wit -o src/generated",
"build": "rollup --config",
"componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js",
"clean": "rm -rf out src/interfaces src/main.d.ts"
"clean": "rm -rf out src/generated"
},
"devDependencies": {
"@golemcloud/componentize-js": "0.10.2-golem.1",
Expand Down
2 changes: 1 addition & 1 deletion examples/ts/ts-example-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"stub": "jco stubgen wit -o src/generated",
"build": "rollup --config",
"componentize": "npm run stub && npm run build && jco componentize -w wit -o out/component_name.wasm out/main.js",
"clean": "rm -rf out src/interfaces src/main.d.ts"
"clean": "rm -rf out src/generated"
},
"devDependencies": {
"@golemcloud/componentize-js": "0.10.2-golem.1",
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ fn test_example(example: &Example) -> Result<(), String> {
let target_path = PathBuf::from("examples-test");
let component_name = ComponentName::new(example.name.as_string().to_string() + "-comp");
let package_name =
PackageName::from_string(example.name.as_string().to_string() + ":test-example")
.ok_or("failed to create package name")?;
PackageName::from_string("golem:component").ok_or("failed to create package name")?;
let component_path = target_path.join(component_name.as_string());

println!("Target path: {}", target_path.display().to_string().blue());
Expand Down

0 comments on commit bbb00b5

Please sign in to comment.