Compare commits
3 Commits
85d9fbcc8b
...
0574b7da54
Author | SHA1 | Date | |
---|---|---|---|
0574b7da54 | |||
5746ad66eb | |||
f72c66b434 |
@ -17,7 +17,7 @@ const _ string = runtime.Compiler
|
|||||||
|
|
||||||
var _ unsafe.Pointer
|
var _ unsafe.Pointer
|
||||||
|
|
||||||
//go:linkname wasmimport_Log go.wasmcloud.dev/component/gen/wasi/logging/logging.wasmimport_Log
|
//go:linkname wasmimport_Log gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging.wasmimport_Log
|
||||||
func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) {
|
func wasmimport_Log(level0 uint32, context0 *uint8, context1 uint32, message0 *uint8, message1 uint32) {
|
||||||
var __p runtime.Pinner
|
var __p runtime.Pinner
|
||||||
defer __p.Unpin()
|
defer __p.Unpin()
|
||||||
|
3
go.mod
3
go.mod
@ -14,14 +14,11 @@ require (
|
|||||||
github.com/klauspost/compress v1.17.11 // indirect
|
github.com/klauspost/compress v1.17.11 // 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.2 // indirect
|
||||||
github.com/samber/lo v1.47.0 // 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
|
||||||
github.com/ulikunitz/xz v0.5.12 // indirect
|
github.com/ulikunitz/xz v0.5.12 // indirect
|
||||||
github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect
|
github.com/urfave/cli/v3 v3.0.0-alpha9.2 // indirect
|
||||||
golang.org/x/mod v0.21.0 // indirect
|
golang.org/x/mod v0.21.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.26.0 // indirect
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
golang.org/x/text v0.18.0 // indirect
|
|
||||||
golang.org/x/tools v0.26.0 // indirect
|
golang.org/x/tools v0.26.0 // indirect
|
||||||
)
|
)
|
||||||
|
6
go.sum
6
go.sum
@ -17,10 +17,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
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.2 h1:vcldDAwBMLtighYVMeb6qNt5+0hKg3AN2IkCc0JIJNM=
|
||||||
github.com/regclient/regclient v0.7.2/go.mod h1:QlA7W9/pvmbblOXM4d49JgfuOTwVXcUMKt3bFuOSVIQ=
|
github.com/regclient/regclient v0.7.2/go.mod h1:QlA7W9/pvmbblOXM4d49JgfuOTwVXcUMKt3bFuOSVIQ=
|
||||||
github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc=
|
|
||||||
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/go.mod h1:mZSJhinB4aqHziR0SKPqpVZjJ0JO35JfH+dDIWqaCBk=
|
|
||||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
@ -44,8 +40,6 @@ golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
|
||||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
|
||||||
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
|
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
|
||||||
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
|
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
66
local.wadm.yaml
Normal file
66
local.wadm.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
apiVersion: core.oam.dev/v1beta1
|
||||||
|
kind: Application
|
||||||
|
metadata:
|
||||||
|
name: tinygo-hello-world
|
||||||
|
annotations:
|
||||||
|
description: 'HTTP hello world demo in Golang (TinyGo), using the WebAssembly Component Model and WebAssembly Interfaces Types (WIT)'
|
||||||
|
wasmcloud.dev/authors: wasmCloud team
|
||||||
|
wasmcloud.dev/source-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/wadm.yaml
|
||||||
|
wasmcloud.dev/readme-md-url: https://github.com/wasmCloud/wasmCloud/blob/main/examples/golang/components/http-hello-world/README.md
|
||||||
|
wasmcloud.dev/homepage: https://github.com/wasmCloud/wasmCloud/tree/main/examples/golang/components/http-hello-world
|
||||||
|
wasmcloud.dev/categories: |
|
||||||
|
http,outgoing-http,http-server,tinygo,golang,example
|
||||||
|
spec:
|
||||||
|
components:
|
||||||
|
- name: echo
|
||||||
|
type: component
|
||||||
|
properties:
|
||||||
|
# To use the locally compiled code in this folder, use the line below instead after running `wash build`:
|
||||||
|
image: file://./build/go_nats_client_s.wasm
|
||||||
|
# image: gitea.rebus.ninja/lore/go-nats-client:1.0.1
|
||||||
|
id: echo
|
||||||
|
traits:
|
||||||
|
# Govern the spread/scheduling of the component
|
||||||
|
- type: spreadscaler
|
||||||
|
properties:
|
||||||
|
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
|
||||||
|
- name: nats
|
||||||
|
type: capability
|
||||||
|
properties:
|
||||||
|
image: ghcr.io/wasmcloud/messaging-nats:0.23.1
|
||||||
|
## 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:
|
||||||
|
# Since the `nats` capability provider calls an component to handle messages
|
||||||
|
# coming over subscriptions, this provider needs a unidirectional link to the
|
||||||
|
# component that wil be called.
|
||||||
|
#
|
||||||
|
# Here we link the `nats` provider (the "source"), to the `echo` component (the "target"),
|
||||||
|
# so that so the provider can deliver messages to the component (by invoking the wasmcloud:messaging/handler interface) .
|
||||||
|
- type: link
|
||||||
|
properties:
|
||||||
|
target: echo
|
||||||
|
namespace: wasmcloud
|
||||||
|
package: messaging
|
||||||
|
interfaces: [handler]
|
||||||
|
source_config:
|
||||||
|
- name: simple-subscription
|
||||||
|
properties:
|
||||||
|
subscriptions: wasmcloud.echo
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/bytecodealliance/wasm-tools-go/cm"
|
"github.com/bytecodealliance/wasm-tools-go/cm"
|
||||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/consumer"
|
||||||
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
"gitea.rebus.ninja/lore/go-nats-client/gen/wasmcloud/messaging/types"
|
||||||
"go.wasmcloud.dev/component/log/wasilog"
|
logger "gitea.rebus.ninja/lore/go-nats-client/gen/wasi/logging/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
type messagingConsumerAdapter struct {
|
type messagingConsumerAdapter struct {
|
||||||
@ -17,9 +17,8 @@ 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.Info("Received message", "subject", msg.Subject)
|
logger.Log(logger.LevelInfo,"MessageHandler", "Received message on subject" + msg.Subject)
|
||||||
|
|
||||||
reply := types.BrokerMessage{
|
reply := types.BrokerMessage{
|
||||||
Subject: msg.Subject + ".reply",
|
Subject: msg.Subject + ".reply",
|
||||||
@ -28,7 +27,7 @@ func handleMessage(msg types.BrokerMessage) cm.Result[string, struct{}, string]
|
|||||||
}
|
}
|
||||||
res := messagingConsumer.Publish(reply)
|
res := messagingConsumer.Publish(reply)
|
||||||
if res.IsErr() {
|
if res.IsErr() {
|
||||||
logger.Error("Failed to send reply", "error", *res.Err())
|
logger.Log(logger.LevelError, "MessageHandler", "Failed to send reply, error: " + *res.Err())
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ 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: echo
|
||||||
|
@ -2,6 +2,15 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 1
|
version = 1
|
||||||
|
|
||||||
|
[[packages]]
|
||||||
|
name = "wasi:logging"
|
||||||
|
registry = "wasi.dev"
|
||||||
|
|
||||||
|
[[packages.versions]]
|
||||||
|
requirement = "=0.1.0-draft"
|
||||||
|
version = "0.1.0-draft"
|
||||||
|
digest = "sha256:09621a45b12b0a9cddc798517f778aac0e5ae4bd234077b3d70758d6cf625580"
|
||||||
|
|
||||||
[[packages]]
|
[[packages]]
|
||||||
name = "wasmcloud:component-go"
|
name = "wasmcloud:component-go"
|
||||||
registry = "wasmcloud.com"
|
registry = "wasmcloud.com"
|
||||||
|
@ -1,15 +1,36 @@
|
|||||||
package wasi:logging@0.1.0-draft;
|
package wasi:logging@0.1.0-draft;
|
||||||
|
|
||||||
|
/// WASI Logging is a logging API intended to let users emit log messages with
|
||||||
|
/// simple priority levels and context values.
|
||||||
interface logging {
|
interface logging {
|
||||||
|
/// A log level, describing a kind of message.
|
||||||
enum level {
|
enum level {
|
||||||
|
/// Describes messages about the values of variables and the flow of
|
||||||
|
/// control within a program.
|
||||||
trace,
|
trace,
|
||||||
|
/// Describes messages likely to be of interest to someone debugging a
|
||||||
|
/// program.
|
||||||
debug,
|
debug,
|
||||||
|
/// Describes messages likely to be of interest to someone monitoring a
|
||||||
|
/// program.
|
||||||
info,
|
info,
|
||||||
|
/// Describes messages indicating hazardous situations.
|
||||||
warn,
|
warn,
|
||||||
|
/// Describes messages indicating serious errors.
|
||||||
error,
|
error,
|
||||||
|
/// Describes messages indicating fatal errors.
|
||||||
critical,
|
critical,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Emit a log message.
|
||||||
|
///
|
||||||
|
/// A log message has a `level` describing what kind of message is being
|
||||||
|
/// sent, a context, which is an uninterpreted string meant to help
|
||||||
|
/// consumers group similar messages, and a string containing the message
|
||||||
|
/// text.
|
||||||
log: func(level: level, context: string, message: string);
|
log: func(level: level, context: string, message: string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
world imports {
|
||||||
|
import logging;
|
||||||
|
}
|
||||||
|
@ -5,4 +5,5 @@ world hello {
|
|||||||
|
|
||||||
export wasmcloud:messaging/handler@0.2.0;
|
export wasmcloud:messaging/handler@0.2.0;
|
||||||
import wasmcloud:messaging/consumer@0.2.0;
|
import wasmcloud:messaging/consumer@0.2.0;
|
||||||
|
import wasi:logging/logging@0.1.0-draft;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user