56 results available
Sign in
Skills directory

go-pubsub

encoredev

·

Last changed
Hardened

This skill has been hardened by Chainguard

Last changed

This version passed the hardening gate. Hardening applied 5 targeted changes and preserved all other text. Classified findings before hardening: 0. Classified findings closed: 0. Classified findings remaining: 0. Unclassified scanner findings remaining: 0. Review findings closed: 7. Review findings remaining: 5.


Open before hardening

None

Open after hardening

None


Expand
File
Group
Subtype
Severity
Status

No findings available

0 findings


SKILL.md

Encore Go Pub/Sub

Instructions

Pub/Sub is for asynchronous messaging between services. Producers publish events to a Topic; consumers attach Subscriptions to react. Resources must be declared as package-level variables — never inside functions.

Topics

package events

import "encore.dev/pubsub"

type OrderCreatedEvent struct {
    OrderID string `json:"order_id"`
    UserID  string `json:"user_id"`
    Total   int    `json:"total"`
}

// Package level declaration
var OrderCreated = pubsub.NewTopic[*OrderCreatedEvent]("order-created", pubsub.TopicConfig{
    DeliveryGuarantee: pubsub.AtLeastOnce,
})

Publishing

msgID, err := events.OrderCreated.Publish(ctx, &events.OrderCreatedEvent{
    OrderID: "123",
    UserID:  "user-456",
    Total:   9999,
})

Subscriptions

package notifications

import (
    "context"
    "myapp/events"
    "encore.dev/pubsub"
)

var _ = pubsub.NewSubscription(events.OrderCreated, "send-confirmation-email",
    pubsub.SubscriptionConfig[*events.OrderCreatedEvent]{
        Handler: sendConfirmationEmail,
    },
)

func sendConfirmationEmail(ctx context.Context, event *events.OrderCreatedEvent) error {
    // Send email...
    return nil
}

Topic References

Pass topic access to library code while maintaining static analysis. The snippet below is a sketch: create the reference inside a function within an Encore service so static analysis still applies, and pass the context of the caller into the helper as a parameter instead of relying on an undeclared one:

// Create a reference with publish permission
ref := pubsub.TopicRef[pubsub.Publisher[*OrderCreatedEvent]](OrderCreated)

// Use the reference in library code
func publishEvent(ref pubsub.Publisher[*OrderCreatedEvent], event *OrderCreatedEvent) error {
    _, err := ref.Publish(ctx, event)
    return err
}

Delivery Guarantees

  • pubsub.AtLeastOnce (default): may deliver duplicates → handlers must be idempotent.
  • pubsub.ExactlyOnce: stricter, capped throughput (AWS 300 msg/s/topic, GCP 3000+ msg/s/region). Does not deduplicate on the publish side. Even with exactly once delivery, duplicate Publish calls produce distinct messages, so keep handlers idempotent. Throughput limits depend on the cloud provider; check them against current Encore and cloud documentation.

Guidelines

  • Topics and subscriptions must be declared as package-level variables.
  • Subscription handlers must be idempotent (at-least-once delivery is the default).
  • To make a handler idempotent, record a processed key, such as the order ID plus the subscription name, in a database table with a unique constraint before the side effect, and skip the work when the key already exists. Returning an error after a partial side effect causes a retry, so that side effect may repeat.
  • Validate required event fields, such as a non-empty order ID and user ID, before any side effect, and load authoritative state from the owning service when the handler depends on it. For permanently invalid messages, log them and return nil so they are not retried forever.
  • Keep event payloads minimal and prefer IDs over personal data. Keep secrets and tokens out of events, since every subscriber receives them and the broker may store them; subscribers can fetch sensitive details from the owning service.
  • Subscription handlers receive a context.Context and the event pointer; return an error to retry per the retry policy of the subscription. The retry policy is configured on the subscription, and messages that exceed the maximum retries go to a dead letter.
  • Publish returns once the message is queued and does not wait for subscribers. Move slow work into subscription handlers, and always check the error that Publish returns.

Install

Install with chainctl
chainctl skill install public/encoredev/go-pubsub:latest
Get started with chainctl
View source

Harden your own skills

Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.

Provenance

Upstream sourcehttps://github.com/encoredev/skills
Upstream commitcb69bb1f246274419aed69c84ee5815955c4c499
OCI reference

skills.cgr.dev/public/github.com/encoredev/encore/go-pubsub:latest

License

Apache-2.0

Files

HARDENING.md

LICENSE

SKILL.md


The trusted source for open source

Talk to an expert
PrivacyTerms

Product

Chainguard ContainersChainguard LibrariesChainguard VMsChainguard OS PackagesChainguard ActionsChainguard Agent SkillsIntegrationsPricing
© 2026 Chainguard, Inc. All Rights Reserved.
Chainguard® and the Chainguard logo are registered trademarks of Chainguard, Inc. in the United States and/or other countries.
The other respective trademarks mentioned on this page are owned by the respective companies and use of them does not imply any affiliation or endorsement.