Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureTinyGo(out io.Writer) error
- func ExportAssetHash(content []byte, ext string) string
- 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 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
Constants ¶
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 ( // CompilerModeStdlib compila el frontend con el Go estandar en vez de TinyGo: // binario grande, compilacion rapida, sin minificar. Es el modo de desarrollo. CompilerModeStdlib = "L" )
const HeaderIdentity = "x-goflare"
HeaderIdentity es la cabecera con la que un Worker desplegado por goflare se identifica. Su presencia prueba que la respuesta la produjo el Worker y no la capa de archivos estaticos.
Variables ¶
var ErrNotFound = errors.New("not found")
var WorkerFirstRoutes = []string{"/api/*", "/oauth/*"}
WorkerFirstRoutes son los prefijos que Cloudflare debe enviar al Worker antes que a los assets estaticos. No es configuracion del proyecto: /api/ es la convencion de rutas de tinywasm/router y /oauth/ lo monta tinywasm/user. Un proyecto que use el ecosistema queda correcto sin declarar nada.
Functions ¶
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.
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 compila el sitio estático del proyecto.
Es una costura deliberada: la tubería real de sitec exige un módulo Go válido en disco y un compilador instalado, y los tests de este repo no tienen ninguna de las dos cosas. La implementación real es buildSite.
type SiteOutput ¶ added in v0.5.0
SiteOutput es el sitio ya compilado, listo para volcarse a disco.