Help us shape the future of Go! Take the 2026 Go Developer Survey

genvisor

package
v1.3.104 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package genvisor pkg/skywireconfig/genvisor/genvisor.go c3-vis-core composes a fresh visor configuration (pkg/visor/visorconfig.V1) from a small Options struct plus the deployment-default services embedded in pkg/skycoin/skywire/deployment (deployment.Prod).

Lives in pkg/skywireconfig so it sits alongside autoconfigcmd and keypair as the third leg of the WASM-clean configuration surface: the apt-repo install-page form generates a downloadable /opt/skywire/skywire.json by calling Generate, encoding the returned V1 as JSON, and offering it as a Blob the operator downloads.

Generate is a thin shim around the visorconfig package's MakeBaseConfig helper (the same function cmd/skywire-cli's `config gen` builds on) — semantics are identical between the CLI's config-gen path and this WASM-compatible path. The Options struct exposes the most commonly-tuned knobs as fields so a WASM caller doesn't have to compose a full cobra command flag set just to set ISHYPERVISOR or REWARDSKYADDR; everything else can be edited on the returned V1 directly before JSON-encoding.

WASM cleanliness: this package imports only WASM-clean leaves (visorconfig, deployment, cipher, skyenv-spec). It compiles under GOOS=js GOARCH=wasm — verified end-to-end by the apt-repo install page's WASM build.

Package genvisor pkg/skywireconfig/genvisor/genvisor_native.go c3-vis-core

Non-WASM implementation of MustMarshalJSON — uses encoding/json.MarshalIndent. Build-tag-gated because encoding/json's reflect-based marshal calls reflect.unsafe_New / mapassign / typedmemmove, which TinyGo's stdlib doesn't ship. See the package doc / genvisor_js.go for the WASM alternative.

Package genvisor pkg/skywireconfig/genvisor/marshal_compat_native.go c3-vis-core

Native-build copy of the hand-rolled marshaler in marshal_js.go, with every symbol renamed to a `Native` suffix to avoid colliding with the real MustMarshalJSON in genvisor_native.go. Purpose: the comparison test (marshal_compare_test.go) needs to run the hand-rolled marshaler under GOOS=linux/darwin/windows to validate its output against encoding/json.MarshalIndent. Without this duplicate the test would require a TinyGo build + wasm runner — not worth the CI complexity for a regression check that fires once per V1 schema change.

Drift policy: this file MUST stay in sync with marshal_js.go. Regenerate by stripping the //go:build js line and running the rename sed pipeline (see the commit message in the PR introducing this file). The comparison test will fail if you forget — the rendered JSON would diverge from the stdlib codec.

Original file header from marshal_js.go follows:

Hand-rolled streaming JSON serializer for visorconfig.V1. Lives in the js build-tag because the WASM-clean path can't use encoding/json (reflect runtime helpers TinyGo's stdlib doesn't link). The output matches what `json.MarshalIndent(v, "", " ")` would produce on the !js build path, byte-for-byte for the common cases (and structurally for the rest), so the "Download skywire.json" button on the TinyGo install-page variant produces a config equivalent to the Go-WASM version.

Implementation style:

  • One `*objCtxNative` per JSON object; the close method emits the trailing `\n }` for nonempty objects and a bare `}` for empty ones.
  • `field(key)` is called BEFORE writing the value; it emits the comma-newline-indent-quoted-key-colon-space prefix. The value writer (e.g. `writeQuotedNative`, `marshalDmsgNative`) appends immediately after.
  • omitempty fields are guarded by an explicit `if`; the writer never sees a skipped field.

Field ORDER mirrors the V1 struct's declaration order (which is the order encoding/json uses for marshaling). Embedded *Common fields (version, sk, pk) appear at the V1 level where the embedding declaration sits — at the top of the object.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(opts Options) (*visorconfig.V1, error)

Generate composes a fresh visorconfig.V1 from opts + the embedded deployment configuration. Returns the V1 and any error from key derivation or services unmarshaling.

The returned V1 is operationally complete enough to load into a fresh visor: all required fields are populated with deployment defaults, the operator's identity is wired into Common, and the flags from Options that translate to V1 fields are applied. Optional sub-systems (Stats, Skychat, SkymailBridge, UI server, log server, etc.) are left at visorconfig's defaults.

The same set of fields can be tuned post-call by mutating the returned V1 directly — Generate is the prelude to "marshal + download" in the WASM flow.

func MustMarshalJSON

func MustMarshalJSON(v *visorconfig.V1) []byte

MustMarshalJSON renders v as indented JSON via the stdlib codec.

func MustMarshalJSONNative

func MustMarshalJSONNative(v *visorconfig.V1) []byte

MustMarshalJSONNative renders v as indented JSON. Mirrors the !js signature so the WASM install-page calls the same function in either Go-WASM or TinyGo-WASM builds.

Types

type Options

type Options struct {
	// SecretKey, when non-zero, becomes the visor's identity. The
	// matching PK is derived and written into Common.PK. Empty
	// triggers a fresh keypair via cipher.GenerateKeyPair (the
	// same path visorconfig.NewCommon takes when sk==nil but a
	// SecKey pointer is passed; see ensureKeys).
	SecretKey cipher.SecKey

	// IsHypervisor enables the local hypervisor stanza
	// (V1.Hypervisor.Enable=true and the rest of HypervisorConfig
	// gets populated by visorconfig.GenerateWorkDirConfig).
	IsHypervisor bool

	// HypervisorPKs is a list of remote hypervisor public keys to
	// dial. The visor opens a persistent RPC channel to each on
	// start. Empty leaves V1.Hypervisors nil.
	HypervisorPKs []cipher.PubKey

	// RewardAddress, when non-empty, is written verbatim to
	// V1.RewardAddress. Validated only at the wire level (must be
	// a Skycoin address or xpub string); the visor performs its
	// own deeper validation on first start.
	RewardAddress string

	// IsPublic toggles V1.IsPublic — when true, the visor
	// announces itself to the service-discovery service so other
	// operators can dial it as a transport endpoint.
	IsPublic bool

	// WalletCustody, when non-empty, sets V1.Wallet.Custody — where the
	// skycoin-web wallet keeps keys (browser | disk | remote; see the
	// visorconfig.WalletCustody* constants). Empty leaves the wallet block
	// unset, which means "serve the wallet, browser custody" — today's
	// behavior. The value is NOT clamped here: a config generated for a
	// native visor may legitimately say "disk", and V1.WalletCustody()
	// does the per-build clamping at read time.
	WalletCustody string

	// WalletDir sets V1.Wallet.Dir — the disk-custody wallet directory. It
	// is a seed-wallet store (one dir, N seed files), not one dir per coin.
	// Ignored unless WalletCustody is "disk".
	WalletDir string

	// WalletRemotePK sets V1.Wallet.RemotePK — the visor whose skycoin-web
	// server holds the wallets. Ignored unless WalletCustody is "remote".
	WalletRemotePK string

	// NoWallet disables serving the wallet frontend entirely
	// (V1.Wallet.Serve=false). Distinct from custody: this is the feature
	// on/off switch.
	NoWallet bool
}

Options groups the operator-tunable knobs Generate honors. Every field is optional — zero values mean "use the visorconfig default for that field". Anything not exposed here (advanced transport setup tweaks, multi-deployment dmsg, etc.) is still reachable on the returned *visorconfig.V1 — Generate gives you a well-formed config; further mutation is the caller's call.

Jump to

Keyboard shortcuts

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