goflare

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 17 Imported by: 1

README ΒΆ

GoFlare

GoFlare is a self-contained Go tool (library + CLI) for deploying Go WASM projects to Cloudflare Workers and Pages. No Node.js, no Wrangler, no GitHub Actions. Pure Go, direct Cloudflare API.


πŸš€ Features

  • Zero Dependencies: No Node.js or Wrangler required.
  • Go β†’ WASM/JS: Seamlessly compiles Go to WASM for the edge.
  • Dual Target: Supports both Cloudflare Workers and Cloudflare Pages.
  • Direct Upload: Uses Cloudflare's Direct Upload v2 API for Pages.
  • Secure Auth: Uses the system keyring to store your Cloudflare API token.
  • Pure Go: Entirely written in Go.

πŸ’» CLI Usage

Install the CLI:

go install github.com/tinywasm/goflare/cmd/goflare@latest
1. Initialize

Set up your project and create a .env file with necessary configurations.

goflare init
2. Build

Compile your Go code to WASM and prepare assets.

goflare build
3. Deploy

Push your project to Cloudflare.

goflare deploy

πŸ“š Library Usage

GoFlare can also be used as a library in your own Go tools.

import (
    "os"
    "github.com/tinywasm/goflare"
)

func main() {
    cfg := &goflare.Config{
        ProjectName: "myapp",
        AccountID:   "abc1234567890",
        Entry:       "cmd/worker/main.go",
        PublicDir:   "public",
    }

    g := goflare.New(cfg)

    // Build
    if err := g.Build(); err != nil {
        panic(err)
    }

    // Deploy
    store := goflare.NewKeyringStore()
    if err := g.Auth(store, os.Stdin); err != nil {
        panic(err)
    }

    if err := g.DeployWorker(store); err != nil {
        panic(err)
    }

    if err := g.DeployPages(store); err != nil {
        panic(err)
    }
}

βš™οΈ Configuration

Configuration is primarily loaded from a .env file or environment variables.

Field .env Key Default Required Description
ProjectName PROJECT_NAME - Yes Unique name for your project
AccountID CLOUDFLARE_ACCOUNT_ID - Yes Your Cloudflare Account ID
WorkerName WORKER_NAME <ProjectName>-worker No Name of the Worker script
Domain DOMAIN - No Custom domain for Pages
Entry ENTRY - No* Path to main Go file for Worker
PublicDir PUBLIC_DIR - No* Path to static assets for Pages
CompilerMode COMPILER_MODE S No S (Small), M (Medium), L (Large)

*At least one of ENTRY or PUBLIC_DIR must be provided.


πŸ› οΈ Requirements

  • Go 1.25.2+
  • TinyGo in your PATH (for Worker builds)

πŸ“ License

Distributed under the MIT License. See LICENSE for more information.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func RunBuild ΒΆ added in v0.1.0

func RunBuild(envPath string, out io.Writer) error

RunBuild runs the build command.

func RunDeploy ΒΆ added in v0.1.0

func RunDeploy(envPath string, in io.Reader, out io.Writer) error

RunDeploy runs the deploy command.

func RunInit ΒΆ added in v0.1.0

func RunInit(envPath string, in io.Reader, out io.Writer) error

RunInit runs the init command.

func UpdateGitignore ΒΆ added in v0.1.0

func UpdateGitignore(dir string) error

UpdateGitignore reads .gitignore in dir. Appends .env and .goflare/ if not already present. Creates .gitignore if it does not exist.

func Usage ΒΆ added in v0.1.0

func Usage() string

Usage returns the usage string.

func WriteEnvFile ΒΆ added in v0.1.0

func WriteEnvFile(cfg *Config, path string) error

WriteEnvFile writes a .env file with all non-empty fields.

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 for Pages)

	// Build inputs
	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 .goflare/)
	OutputDir string // default: ".goflare/"

	// Compiler
	CompilerMode string // "S" | "M" | "L"  default: "S"
}

func Init ΒΆ added in v0.1.0

func Init(in io.Reader, out io.Writer) (*Config, error)

Init runs the interactive wizard and returns a populated Config.

func LoadConfigFromEnv ΒΆ added in v0.1.0

func LoadConfigFromEnv(path string) (*Config, error)

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) Validate ΒΆ added in v0.1.0

func (c *Config) Validate() error

type DeployResult ΒΆ added in v0.1.0

type DeployResult struct {
	Target string
	URL    string
	Err    error
}

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
	// contains filtered or unexported fields
}

func New ΒΆ

func New(cfg *Config) *Goflare

New creates a new Goflare instance with the provided configuration

func (*Goflare) Auth ΒΆ added in v0.0.97

func (g *Goflare) Auth(store Store, in io.Reader) error

Auth implements token validation and keyring storage as a method.

func (*Goflare) Build ΒΆ added in v0.1.0

func (g *Goflare) Build() error

Build orchestrates the build pipeline as a method.

func (*Goflare) Change ΒΆ

func (h *Goflare) Change(newValue string, progress func(msgs ...any))

func (*Goflare) Deploy ΒΆ added in v0.1.0

func (g *Goflare) Deploy(store Store) error

func (*Goflare) DeployPages ΒΆ added in v0.0.97

func (g *Goflare) DeployPages(store Store) error

DeployPages uploads the Pages build output (from config.OutputDir) to Cloudflare Pages.

func (*Goflare) DeployWorker ΒΆ added in v0.0.99

func (g *Goflare) DeployWorker(store Store) error

DeployWorker uploads the Worker build output to Cloudflare Workers.

func (*Goflare) GeneratePagesFiles ΒΆ

func (g *Goflare) GeneratePagesFiles() error

func (*Goflare) GenerateWorkerFiles ΒΆ

func (g *Goflare) GenerateWorkerFiles() error

func (*Goflare) GetToken ΒΆ added in v0.1.0

func (g *Goflare) GetToken(store Store) (string, error)

GetToken reads the token from the store without prompting.

func (*Goflare) Label ΒΆ

func (h *Goflare) Label() string

func (*Goflare) Logger ΒΆ added in v0.0.40

func (g *Goflare) Logger(messages ...any)

func (*Goflare) MainInputFileRelativePath ΒΆ

func (h *Goflare) MainInputFileRelativePath() string

MainInputFileRelativePath returns the relative path to the main input file This is used by devwatch to determine file ownership for Go files

func (*Goflare) Name ΒΆ

func (h *Goflare) Name() string

func (*Goflare) NewFileEvent ΒΆ

func (h *Goflare) NewFileEvent(fileName, extension, filePath, event string) error

NewFileEvent handles file change events for goflare This method is called by devwatch when a relevant file changes

func (*Goflare) SetCompilerMode ΒΆ

func (g *Goflare) SetCompilerMode(newValue string)

SetCompilerMode changes the compiler mode mode: "L" (Large fast/Go), "M" (Medium TinyGo debug), "S" (Small TinyGo production)

func (*Goflare) SetLog ΒΆ added in v0.0.40

func (g *Goflare) SetLog(f func(message ...any))

func (*Goflare) Shortcuts ΒΆ

func (h *Goflare) Shortcuts() []map[string]string

func (*Goflare) SupportedExtensions ΒΆ

func (h *Goflare) SupportedExtensions() []string

SupportedExtensions returns the file extensions that goflare monitors For edge workers, we primarily watch .go files

func (*Goflare) UnobservedFiles ΒΆ

func (h *Goflare) UnobservedFiles() []string

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) Value ΒΆ

func (h *Goflare) Value() string

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 KeyringStore ΒΆ added in v0.1.0

type KeyringStore struct {
	ProjectName string
}

KeyringStore is the real implementation using go-keyring.

func NewKeyringStore ΒΆ added in v0.1.0

func NewKeyringStore() *KeyringStore

func (*KeyringStore) Get ΒΆ added in v0.1.0

func (s *KeyringStore) Get(key string) (string, error)

func (*KeyringStore) Set ΒΆ added in v0.1.0

func (s *KeyringStore) Set(key, value string) error

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) Get ΒΆ added in v0.1.0

func (s *MemoryStore) Get(key string) (string, error)

func (*MemoryStore) Set ΒΆ added in v0.1.0

func (s *MemoryStore) Set(key, value string) error

type Store ΒΆ added in v0.0.99

type Store interface {
	Get(key string) (string, error)
	Set(key, value string) error
}

Store abstracts keyring access for testability.

Directories ΒΆ

Path Synopsis
cmd
goflare command

Jump to

Keyboard shortcuts

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