Documentation
¶
Index ¶
- Constants
- Variables
- func CheckVersionSkew(moduleRoot string) error
- func CheckWasmSize(path string, log func(...any)) error
- func CompareVersions(project, embedded string) error
- func EmbeddedCloudflareVersion() string
- func EnsureTinyGo(out io.Writer) error
- func ExportAssetHash(content []byte, ext string) string
- func FilterActionable(chains []gobuild.ImportChain) []gobuild.ImportChain
- func ForbiddenImports(moduleRoot, entryPkg string) ([]gobuild.ImportChain, error)
- func FormatTinyGoOutput(dir, version string) string
- func GoflareAction(tinyGoVersion, goflareVersion string) actiongen.Action
- func IsStdlib(importPath string) bool
- func LatestReleaseTag() (string, error)
- func NewD1Migrator(accountID, databaseID, apiToken string) (ddl.Execer, error)
- func NewD1MigratorFromClient(client *CfClient, accountID, databaseID string) ddl.Execer
- func ProjectCloudflareVersion(moduleRoot string) (string, error)
- func RunAuth(envPath string, out io.Writer, check bool) error
- func RunBuild(envPath string, out io.Writer) error
- func RunDeploy(envPath string, out io.Writer) error
- func RunSize(envPath string, out io.Writer) error
- func RunTinyGo(out io.Writer) error
- func SizeBreakdown(entryDir string) (string, error)
- func TinyGoBinDir() (dir, version string, err error)
- func Usage() string
- type CfClient
- type Config
- type DeployResult
- type Goflare
- func (g *Goflare) Auth() error
- func (g *Goflare) Build() error
- func (h *Goflare) Change(newValue string, progress func(msgs ...any))
- func (g *Goflare) Deploy() error
- func (g *Goflare) ExportBuildAssetManifest(dir string) (map[string]assetEntry, map[string]string, error)
- func (g *Goflare) ExportUploadAssets(client *CfClient, manifest map[string]assetEntry, byHash map[string]string) (string, error)
- func (g *Goflare) GeneratePagesFiles() error
- func (g *Goflare) GenerateWorkerFiles() error
- func (h *Goflare) Label() string
- func (g *Goflare) Logger(messages ...any)
- func (h *Goflare) MainInputFileRelativePath() string
- func (h *Goflare) Name() string
- func (h *Goflare) NewFileEvent(fileName, extension, filePath, event string) error
- func (g *Goflare) SetCompilerMode(newValue string)
- func (g *Goflare) SetLog(f func(message ...any))
- func (g *Goflare) SetSiteBuilder(b SiteBuilder)
- func (h *Goflare) Shortcuts() []map[string]string
- func (g *Goflare) StagingDir() string
- func (h *Goflare) SupportedExtensions() []string
- func (h *Goflare) UnobservedFiles() []string
- func (h *Goflare) Value() string
- func (g *Goflare) WriteSummary(out io.Writer, results []DeployResult)
- type MemoryStore
- type SiteBuilder
- type SiteOutput
- type Store
- type WasmSizes
Constants ¶
const ( ActionFilePath = "action.yml" ReleaseAssetURLFmt = "https://github.com/tinywasm/goflare/releases/download/%s/%s" TinyGoCacheKeyFmt = "tinygo-${{ runner.os }}-${{ runner.arch }}-%s" )
const ( EnvKeyProjectName = "PROJECT_NAME" EnvKeyAccountID = "CLOUDFLARE_ACCOUNT_ID" EnvKeyWorkerName = "WORKER_NAME" EnvKeyDomain = "DOMAIN" EnvKeyCompilerMode = "COMPILER_MODE" EnvKeyD1DatabaseID = "D1_DATABASE_ID" EnvKeyD1DatabaseName = "D1_DATABASE_NAME" EnvKeyR2BucketID = "R2_BUCKET_ID" EnvKeyR2BucketName = "R2_BUCKET_NAME" EnvKeyCompatibilityDate = "COMPATIBILITY_DATE" EnvKeyNotFoundHandling = "NOT_FOUND_HANDLING" DefaultCompatibilityDate = "2026-08-01" DefaultNotFoundHandling = "single-page-application" HTMLHandlingDefault = "auto-trailing-slash" )
const ( ImportEdge = "github.com/tinywasm/cloudflare/edge" ImportWorkers = "github.com/tinywasm/cloudflare/workers" // LegacyImportEdge/Workers kept for backwards compat during migration. LegacyImportEdge = "github.com/tinywasm/goflare/edge" LegacyImportWorkers = "github.com/tinywasm/goflare/workers" ErrNoKnownImport = "cannot infer mode: edge/main.go imports neither " + ImportEdge + " nor " + ImportWorkers )
const ( // WasmWarnSizeKiB is the warning threshold, measured on the RAW size. WasmWarnSizeKiB = 256 // WasmMaxSizeKiB is goflare's OWN budget, not a Cloudflare limit. WasmMaxSizeKiB = 900 // EnvKeyWasmWarnSizeKiB raises or lowers the warning without a rebuild. EnvKeyWasmWarnSizeKiB = "WASM_WARN_SIZE_KIB" // EnvKeyWasmMaxSizeKiB raises or lowers the hard cut-off without a rebuild. EnvKeyWasmMaxSizeKiB = "WASM_MAX_SIZE_KIB" // WasmArtifactName is the standard name of the Worker's WASM binary. WasmArtifactName = "edge.wasm" )
const ( // TinyGoVersion is the TinyGo version this goflare binary will install. TinyGoVersion = tinygo.DefaultVersion // TinyGoBinDirPrefix marks the stdout line carrying the directory. TinyGoBinDirPrefix = "TINYGO_BINDIR=" // TinyGoVersionPrefix marks the stdout line carrying the version. TinyGoVersionPrefix = "TINYGO_VERSION=" )
const ( // CloudflareModulePath is the edge runtime module. goflare embeds its JS // assets; the project compiles its Go code. Both halves have to come from // the same version. CloudflareModulePath = "github.com/tinywasm/cloudflare" )
const ( // CompilerModeStdlib builds the frontend with standard Go instead of TinyGo: // large binary, fast build, no minification. This is the development mode. CompilerModeStdlib = "L" )
const HeaderIdentity = "x-goflare"
HeaderIdentity is the header a goflare-deployed Worker identifies itself with. Its presence proves the response came from the Worker and not from the static file layer.
Variables ¶
var ErrNotFound = errors.New("not found")
var WorkerFirstRoutes = []string{"/api/*", "/oauth/*"}
WorkerFirstRoutes are the prefixes Cloudflare must send to the Worker ahead of the static assets. This is not project configuration: /api/ is the route convention of tinywasm/router and /oauth/ is mounted by tinywasm/user. A project using the ecosystem is correct without declaring anything.
Functions ¶
func CheckVersionSkew ¶ added in v0.5.23
CheckVersionSkew fails when the project and this binary resolve different versions of tinywasm/cloudflare.
func CheckWasmSize ¶ added in v0.5.23
CheckWasmSize measures the artifact, ALWAYS writes the report to log, warns when it passes the warning threshold, and errors when it passes the budget.
func CompareVersions ¶ added in v0.5.23
CompareVersions implements the version-skew decision table.
func EmbeddedCloudflareVersion ¶ added in v0.5.23
func EmbeddedCloudflareVersion() string
EmbeddedCloudflareVersion returns the github.com/tinywasm/cloudflare version THIS binary was built against.
func EnsureTinyGo ¶ added in v0.2.22
EnsureTinyGo installs TinyGo if absent and guarantees its bin dir is in PATH before any compilation attempt. Safe to call multiple times (idempotent).
func ExportAssetHash ¶ added in v0.5.13
ExportAssetHash exports assetHash for testing.
func FilterActionable ¶ added in v0.5.23
func FilterActionable(chains []gobuild.ImportChain) []gobuild.ImportChain
FilterActionable drops the chains where the forbidden package is reached through another stdlib package. Our code neither causes nor can fix those; reporting them only trains the user to ignore the guard.
func ForbiddenImports ¶ added in v0.5.23
func ForbiddenImports(moduleRoot, entryPkg string) ([]gobuild.ImportChain, error)
ForbiddenImports returns only the ACTIONABLE chains into forbidden stdlib within the edge graph.
func FormatTinyGoOutput ¶ added in v0.5.23
FormatTinyGoOutput produces the standard output of the tinygo command.
func GoflareAction ¶ added in v0.5.23
GoflareAction builds the description of the goflare action.
func IsStdlib ¶ added in v0.5.23
IsStdlib reports whether an import path belongs to the Go standard library.
func LatestReleaseTag ¶ added in v0.5.23
LatestReleaseTag returns the highest semver tag in the repository.
func NewD1Migrator ¶ added in v0.5.22
NewD1Migrator returns a ddl.Execer that runs schema migrations against a D1 database from CI or a developer machine — outside a Worker, where the tinywasm/cloudflare/d1.NewEdge binding does not exist.
It builds on CfClient rather than a second HTTP implementation: Bearer auth and {success,errors,result} envelope parsing are already correct in cloudflare.go's parseCFResponse. This repo is where that belongs — see tinywasm/cloudflare/AGENTS.md, "no tooling code, ever, regardless of build tag".
Usage:
conn, err := goflare.NewD1Migrator(accountID, databaseID, apiToken) err = ddl.New(conn, sqlt.NewCompiler()).Sync(models...)
func NewD1MigratorFromClient ¶ added in v0.5.22
NewD1MigratorFromClient is the test seam: it takes an already-constructed CfClient (whose BaseURL can point at an httptest.Server) instead of building one from real credentials.
func ProjectCloudflareVersion ¶ added in v0.5.23
ProjectCloudflareVersion returns the github.com/tinywasm/cloudflare version the project go.mod in moduleRoot resolves to.
func RunTinyGo ¶ added in v0.5.23
RunTinyGo installs TinyGo when missing and prints its bindir and version to stdout.
func SizeBreakdown ¶ added in v0.5.23
SizeBreakdown builds entryDir with symbols and returns the per-package table TinyGo emits. The artifact is written to a temporary directory and deleted: only the report matters. It NEVER replaces the build that gets deployed, which still comes out of sitec without symbols.
func TinyGoBinDir ¶ added in v0.5.23
TinyGoBinDir installs TinyGo when missing and returns the directory holding the binary, along with the version it reports.
Types ¶
type Config ¶
type Config struct {
// Project identity
ProjectName string // PROJECT_NAME
AccountID string // CLOUDFLARE_ACCOUNT_ID
WorkerName string // WORKER_NAME (default: ProjectName + "-worker")
// Routing
Domain string // DOMAIN (optional — custom domain)
// Build inputs (conventions, not configurable via .env)
Entry string // ENTRY (path to main Go file, empty = Pages only)
PublicDir string // PUBLIC_DIR (path to static assets, empty = Worker only)
// Build output (not in .env — always .build/)
OutputDir string // default: ".build/"
// Compiler
CompilerMode string // "S" | "M" | "L" default: "S"
D1DatabaseID string // D1_DATABASE_ID
D1DatabaseName string // D1_DATABASE_NAME — optional, default: ProjectName
R2BucketID string // R2_BUCKET_ID
R2BucketName string // R2_BUCKET_NAME
}
func LoadConfigFromEnv ¶ added in v0.1.0
LoadConfigFromEnv reads a .env file and populates Config. Falls back to OS environment variables if .env path is empty or does not exist. Applies defaults after loading.
func (*Config) ValidateBuild ¶ added in v0.2.17
ValidateBuild checks only what goflare build requires. ProjectName and AccountID are deploy-only — never referenced by build.go.
func (*Config) ValidateDeploy ¶ added in v0.2.17
ValidateDeploy checks everything required for a Cloudflare API deploy.
type DeployResult ¶ added in v0.1.0
DeployResult represents the result of a deployment to a target.
type Goflare ¶
type Goflare struct {
Config *Config // exported so CLI can read it after LoadConfigFromEnv
BaseURL string
SiteURL string // override public URL for testing probe
RetryBackoff time.Duration // base duration for retries (defaults to 1s)
// contains filtered or unexported fields
}
func (*Goflare) Deploy ¶ added in v0.1.0
Deploy uploads the site to Cloudflare as a Worker with static assets.
func (*Goflare) ExportBuildAssetManifest ¶ added in v0.5.13
func (g *Goflare) ExportBuildAssetManifest(dir string) (map[string]assetEntry, map[string]string, error)
ExportBuildAssetManifest exports buildAssetManifest for testing.
func (*Goflare) ExportUploadAssets ¶ added in v0.5.13
func (g *Goflare) ExportUploadAssets(client *CfClient, manifest map[string]assetEntry, byHash map[string]string) (string, error)
ExportUploadAssets exports uploadAssets for testing.
func (*Goflare) GeneratePagesFiles ¶
func (*Goflare) GenerateWorkerFiles ¶
func (*Goflare) MainInputFileRelativePath ¶
MainInputFileRelativePath returns the relative path to the main input file This is used by devwatch to determine file ownership for Go files
func (*Goflare) NewFileEvent ¶
NewFileEvent handles file change events for goflare This method is called by devwatch when a relevant file changes
func (*Goflare) SetCompilerMode ¶
SetCompilerMode changes the compiler mode mode: "L" (Large fast/Go), "M" (Medium TinyGo debug), "S" (Small TinyGo production)
func (*Goflare) SetSiteBuilder ¶ added in v0.5.0
func (g *Goflare) SetSiteBuilder(b SiteBuilder)
SetSiteBuilder sustituye el compilador de sitio. Pensado para tests; en producción nadie lo llama y se usa buildSite.
func (*Goflare) StagingDir ¶ added in v0.2.13
StagingDir returns the temporary directory used for intermediate build artifacts. Exposed for testing — verifies that staging is outside the project tree.
func (*Goflare) SupportedExtensions ¶
SupportedExtensions returns the file extensions that goflare monitors For edge workers, we primarily watch .go files
func (*Goflare) UnobservedFiles ¶
UnobservedFiles returns files that should be ignored by the file watcher These are output files generated by goflare that shouldn't trigger recompilation
func (*Goflare) WriteSummary ¶ added in v0.1.0
func (g *Goflare) WriteSummary(out io.Writer, results []DeployResult)
WriteSummary formats and writes the deploy summary to out.
type MemoryStore ¶ added in v0.1.0
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory Store exported for use by library consumers in tests. Safe for concurrent use.
func NewMemoryStore ¶ added in v0.1.0
func NewMemoryStore() *MemoryStore
func (*MemoryStore) Set ¶ added in v0.1.0
func (s *MemoryStore) Set(key, value string) error
type SiteBuilder ¶ added in v0.5.0
type SiteBuilder func(cfg sitec.BuildConfig) (SiteOutput, error)
SiteBuilder builds the project's static site.
It is a deliberate seam: the real sitec pipeline demands a valid Go module on disk and an installed compiler, and this repo's tests have neither. The real implementation is buildSite.
type SiteOutput ¶ added in v0.5.0
SiteOutput is the already-built site, ready to be flushed to disk.
type WasmSizes ¶ added in v0.5.23
WasmSizes holds the two figures that matter for an edge artifact: the raw one, which is what the isolate compiles and instantiates, and the compressed one, which is what Cloudflare weighs against its limit.
func MeasureWasm ¶ added in v0.5.23
MeasureWasm returns the file's raw size and its gzip-compressed size.