Compare commits
No commits in common. "85d9fbcc8bd540edee0e6eddac6325ba60b28415" and "ea8a3ee209777819f20702409ddba96b7bfec2bf" have entirely different histories.
85d9fbcc8b
...
ea8a3ee209
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
gen/*
|
gen/*
|
||||||
build/*
|
build/*
|
||||||
|
|
||||||
creds.json
|
|
@ -15,11 +15,6 @@ This is a simple TinyGo Wasm example that responds with a "Hello World" message
|
|||||||
wash build
|
wash build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Push OCI Artifact to Gitea
|
|
||||||
```bash
|
|
||||||
wash push gitea.rebus.ninja/lore/go-nats-client:1.x.x build/go_nats_client_s.wasm
|
|
||||||
```
|
|
||||||
|
|
||||||
## Running with wasmtime
|
## Running with wasmtime
|
||||||
|
|
||||||
You must have wasmtime 25.0.0 for this to work. Make sure to follow the build step above first.
|
You must have wasmtime 25.0.0 for this to work. Make sure to follow the build step above first.
|
||||||
|
4
go.mod
4
go.mod
@ -11,9 +11,9 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1 // indirect
|
github.com/coreos/go-semver v0.3.1 // indirect
|
||||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
|
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
|
||||||
github.com/klauspost/compress v1.17.11 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||||
github.com/regclient/regclient v0.7.2 // indirect
|
github.com/regclient/regclient v0.7.1 // indirect
|
||||||
github.com/samber/lo v1.47.0 // indirect
|
github.com/samber/lo v1.47.0 // indirect
|
||||||
github.com/samber/slog-common v0.17.1 // indirect
|
github.com/samber/slog-common v0.17.1 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
|
12
go.sum
12
go.sum
@ -7,16 +7,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
|
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4=
|
||||||
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
|
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
|
||||||
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
|
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||||
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
|
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
github.com/olareg/olareg v0.1.1 h1:Ui7q93zjcoF+U9U71sgqgZWByDoZOpqHitUXEu2xV+g=
|
github.com/olareg/olareg v0.1.0 h1:1dXBOgPrig5N7zoXyIZVQqU0QBo6sD9pbL6UYjY75CA=
|
||||||
github.com/olareg/olareg v0.1.1/go.mod h1:w8NP4SWrHHtxsFaUiv1lnCnYPm4sN1seCd2h7FK/dc0=
|
github.com/olareg/olareg v0.1.0/go.mod h1:RBuU7JW7SoIIxZKzLRhq8sVtQeAHzCAtRrXEBx2KlM4=
|
||||||
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
|
||||||
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/regclient/regclient v0.7.2 h1:vcldDAwBMLtighYVMeb6qNt5+0hKg3AN2IkCc0JIJNM=
|
github.com/regclient/regclient v0.7.1 h1:qEsJrTmZd98fZKjueAbrZCSNGU+ifnr6xjlSAs3WOPs=
|
||||||
github.com/regclient/regclient v0.7.2/go.mod h1:QlA7W9/pvmbblOXM4d49JgfuOTwVXcUMKt3bFuOSVIQ=
|
github.com/regclient/regclient v0.7.1/go.mod h1:+w/BFtJuw0h0nzIw/z2+1FuA2/dVXBzDq4rYmziJpMc=
|
||||||
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
|
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
|
||||||
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
|
github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU=
|
||||||
github.com/samber/slog-common v0.17.1 h1:jTqqLBgoJshpoxlPSGiypyOanjH6tY+i9bwyYmIbjhI=
|
github.com/samber/slog-common v0.17.1 h1:jTqqLBgoJshpoxlPSGiypyOanjH6tY+i9bwyYmIbjhI=
|
||||||
|
7
main.go
7
main.go
@ -2,6 +2,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/handler"
|
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/handler"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -9,6 +12,10 @@ func init() {
|
|||||||
handler.Exports.HandleMessage = handleMessage
|
handler.Exports.HandleMessage = handleMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "Hello from Go!\n")
|
||||||
|
}
|
||||||
|
|
||||||
// Since we don't run this program like a CLI, the `main` function is empty. Instead,
|
// Since we don't run this program like a CLI, the `main` function is empty. Instead,
|
||||||
// we call the `handleRequest` function when an HTTP request is received.
|
// we call the `handleRequest` function when an HTTP request is received.
|
||||||
func main() {}
|
func main() {}
|
||||||
|
@ -18,11 +18,15 @@ var messagingConsumer = &messagingConsumerAdapter{
|
|||||||
|
|
||||||
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string] {
|
||||||
logger := wasilog.ContextLogger("handleMessage")
|
logger := wasilog.ContextLogger("handleMessage")
|
||||||
|
replyTo := msg.ReplyTo.Some()
|
||||||
|
|
||||||
logger.Info("Received message", "subject", msg.Subject)
|
logger.Info("Received message", "subject", msg.Subject)
|
||||||
|
|
||||||
|
if replyTo != nil {
|
||||||
|
logger.Info("Sending reply", "subject", *replyTo)
|
||||||
|
|
||||||
reply := types.BrokerMessage{
|
reply := types.BrokerMessage{
|
||||||
Subject: msg.Subject + ".reply",
|
Subject: *replyTo,
|
||||||
Body: msg.Body,
|
Body: msg.Body,
|
||||||
ReplyTo: cm.None[string](),
|
ReplyTo: cm.None[string](),
|
||||||
}
|
}
|
||||||
@ -31,6 +35,7 @@ func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string]
|
|||||||
logger.Error("Failed to send reply", "error", *res.Err())
|
logger.Error("Failed to send reply", "error", *res.Err())
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
return cm.OK[cm.Result[string, struct{}, string]](struct{}{})
|
||||||
}
|
}
|
||||||
|
54
wadm.yaml
54
wadm.yaml
@ -10,58 +10,38 @@ metadata:
|
|||||||
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
|
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
|
||||||
wasmcloud.dev/categories: |
|
wasmcloud.dev/categories: |
|
||||||
http,outgoing-http,http-server,tinygo,golang,example
|
http,outgoing-http,http-server,tinygo,golang,example
|
||||||
spec:
|
|
||||||
spec:
|
spec:
|
||||||
components:
|
components:
|
||||||
- name: echo
|
- name: http-component
|
||||||
type: component
|
type: component
|
||||||
properties:
|
properties:
|
||||||
# To use the locally compiled code in this folder, use the line below instead after running `wash build`:
|
image: file://./build/http_hello_world_s.wasm
|
||||||
# image: file://./build/echo_messaging_s.wasm
|
|
||||||
image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
|
||||||
id: echo
|
|
||||||
traits:
|
traits:
|
||||||
# Govern the spread/scheduling of the component
|
# Govern the spread/scheduling of the component
|
||||||
- type: spreadscaler
|
- type: spreadscaler
|
||||||
properties:
|
properties:
|
||||||
instances: 1
|
instances: 1
|
||||||
# Establish a unidirectional link to the messaging capability provider (powered by NATS),
|
|
||||||
# so the `echo` component can make use of messaging interface functionality
|
|
||||||
# (i.e. making interacting with the messaging system, in this case NATS)
|
|
||||||
- type: link
|
|
||||||
properties:
|
|
||||||
target: nats
|
|
||||||
namespace: wasmcloud
|
|
||||||
package: messaging
|
|
||||||
interfaces: [consumer]
|
|
||||||
|
|
||||||
# Add a capability provider that implements `wasmcloud:messaging` using NATS
|
# Add a capability provider that enables HTTP access
|
||||||
- name: nats
|
- name: httpserver
|
||||||
type: capability
|
type: capability
|
||||||
properties:
|
properties:
|
||||||
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
image: ghcr.io/wasmcloud/http-server:0.23.2
|
||||||
## To configure OTEL integration for this provider specifically, uncomment the lines below
|
|
||||||
# config:
|
|
||||||
# - name: otel
|
|
||||||
# properties:
|
|
||||||
# otel_exporter_otlp_endpoint: "http://all-in-one:4318"
|
|
||||||
# otel_exporter_otlp_traces_endpoint: "http://traces-backend/v1/traces"
|
|
||||||
# otel_exporter_otlp_metrics_endpoint: "http://metrics-backend/v1/metrics"
|
|
||||||
# otel_exporter_otlp_logs_endpoint: "http://logs-backend/v1/logs"
|
|
||||||
traits:
|
traits:
|
||||||
# Since the `nats` capability provider calls an component to handle messages
|
# Link the httpserver to the component, and configure the HTTP server
|
||||||
# coming over subscriptions, this provider needs a unidirectional link to the
|
# to listen on port 8000 for incoming requests
|
||||||
# component that wil be called.
|
|
||||||
#
|
#
|
||||||
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
# Since the HTTP server calls the `http-component` component, we establish
|
||||||
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
# a unidirectional link from this `httpserver` provider (the "source")
|
||||||
|
# to the `http-component` component (the "target"), so the server can invoke
|
||||||
|
# the component to handle a request.
|
||||||
- type: link
|
- type: link
|
||||||
properties:
|
properties:
|
||||||
target: echo
|
target: http-component
|
||||||
namespace: wasmcloud
|
namespace: wasi
|
||||||
package: messaging
|
package: http
|
||||||
interfaces: [handler]
|
interfaces: [incoming-handler]
|
||||||
source_config:
|
source_config:
|
||||||
- name: simple-subscription
|
- name: default-http
|
||||||
properties:
|
properties:
|
||||||
subscriptions: wasmcloud.echo
|
address: 127.0.0.1:8000
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
name = "go_nats_client"
|
name = "http-hello-world"
|
||||||
language = "tinygo"
|
language = "tinygo"
|
||||||
type = "component"
|
type = "component"
|
||||||
version = "1.0.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[component]
|
[component]
|
||||||
wit_world = "hello"
|
wit_world = "hello"
|
||||||
wasm_target = "wasm32-wasip2"
|
wasm_target = "wasm32-wasip2"
|
||||||
destination = "build/go_nats_client_s.wasm"
|
destination = "build/http_hello_world_s.wasm"
|
||||||
|
|
||||||
[registry]
|
|
||||||
url = "gitea.rebus.ninja/lore"
|
|
||||||
credentials = "./creds.json"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user