goflare

package module
v0.2.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: 19 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:       "edge/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)
    }
}

📁 Project Structure

A GoFlare project follows this fixed convention (not configurable):

my-project/
├── .env                 # credentials — gitignored
├── .env.example         # public template
├── .build/              # build output — gitignored
│   ├── edge.js          # bundled + minified JS (wasm_exec + runtime + entry)
│   ├── edge.wasm        # compiled edge function binary
│   └── dist/            # Pages upload staging (copy of web/public/)
├── web/
│   ├── client.go        # //go:build wasm  — frontend WASM (browser)
│   ├── server.go        # //go:build !wasm — backend for local dev (tinywasm)
│   └── public/          # PUBLIC_DIR in .env
│       ├── index.html
│       └── client.wasm  # generated by goflare build
└── edge/
    └── main.go          # //go:build wasm  — edge function backend (Cloudflare)

Fixed rules:

  • Frontend WASM source: always web/client.go
  • Static assets: always web/public/ (PUBLIC_DIR)
  • Edge function: always edge/main.go (auto-detected — no ENTRY needed)
  • Build output: always .build/

⚙️ 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 .build/ 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 .build/)
	OutputDir string // default: ".build/"

	// 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