capsdk

package module
v0.0.0-...-a9154ef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

CAP Go SDK

Go SDK with NATS helpers for workers and clients. Uses generated protobuf stubs from proto/.

Quick Start

  1. Generate protobuf stubs (once per change):

    ./tools/make_protos.sh
    

    This writes Go stubs to /go. The module uses a replace directive to point at the repo root.

  2. Install deps and run tests:

    cd sdk/go
    go test ./...
    

Structure

  • go.mod — module + replace for generated protos.
  • bus/ — NATS connector.
  • worker/ — worker skeleton with handler signature.
  • client/ — submission/result helpers.
  • types.go — common constants and helper functions.

Usage

nc, _ := bus.Connect(bus.Config{URL: "nats://127.0.0.1:4222"})
defer nc.Close()

w := worker.Worker{
    NATS: nc,
    Subject: "job.echo",
    Handler: func(ctx context.Context, req *agentv1.JobRequest) (*agentv1.JobResult, error) {
        // read from req.ContextPtr, produce result_ptr elsewhere
        return &agentv1.JobResult{
            JobId: req.JobId,
            Status: agentv1.JobStatus_JOB_STATUS_SUCCEEDED,
            ResultPtr: "redis://res/" + req.JobId,
            WorkerId: "worker-echo-1",
        }, nil
    },
}
go w.Start()
// publish jobs with client.Submit(...)

Signing

  • client.Submit and worker.Worker sign envelopes; pass a non-nil ECDSA private key (P-256) and configure PublicKeys to verify incoming packets when you want authenticity enforcement.
  • Generate a keypair in Go:
    priv, _ := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
    pub := &priv.PublicKey
    

Notes

  • The protobuf go_package is github.com/coretexos/cap/go/coretex/agent/v1; the replace in go.mod points to ../...
  • Swap the NATS adapter if you prefer another bus; only bus/ needs to change.

Documentation

Index

Constants

View Source
const (
	SubjectSubmit    = "sys.job.submit"
	SubjectResult    = "sys.job.result"
	SubjectHeartbeat = "sys.heartbeat"
)

DefaultSubject names for CAP. These match the transport profile in the spec.

View Source
const DefaultHeartbeatInterval = 5 * time.Second

DefaultHeartbeatInterval is a recommended interval for emitting heartbeats.

View Source
const DefaultProtocolVersion int32 = 1

DefaultProtocolVersion is the current CAP wire version.

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL