// Command example is abono's example app: sign-in by emailed link, the // starter pages `abono pages` wrote (abono_pages.go, templates/abono/), // and the sandbox standing in for Stripe, so the whole flow is clickable // with no Stripe account. Run it with `go run .` and open // http://localhost:8080. Nothing is mailed: each sign-in link is written // to the log instead, to be opened from there. // // Its settings are environment variables, all optional: // // ABONO_EXAMPLE_ADDR where to listen; 127.0.0.1:8080 // ABONO_EXAMPLE_ORIGIN the address people use; http://localhost:8080 // ABONO_EXAMPLE_OWNER the account that sees the owner's pages; owner@example.com // ABONO_EXAMPLE_PLANS what is for sale; DefaultPlans // ABONO_EXAMPLE_DB the database file; example.db // ABONO_EXAMPLE_INSTANCE_KEY seals sign-in state; a development-only key // STRIPE_KEY, STRIPE_WEBHOOK_SECRET a Stripe test account instead of the sandbox package main import ( "log/slog" "os" "amadan.net/rastrillo/rastrillo" "amadan.net/rastrillo/rastrillo/db" ) func main() { logger := slog.New(slog.NewTextHandler(os.Stderr, nil)) d, err := db.Open(env("ABONO_EXAMPLE_DB", "example.db"), logger) if err != nil { logger.Error("open database", "err", err) os.Exit(1) } defer d.Close() var secrets []string if s := os.Getenv("STRIPE_WEBHOOK_SECRET"); s != "" { secrets = []string{s} } instanceKey := os.Getenv("ABONO_EXAMPLE_INSTANCE_KEY") if instanceKey == "" { instanceKey = "abono-example-development-only-instance-key" logger.Warn("ABONO_EXAMPLE_INSTANCE_KEY not set; using a development-only key") } opts, err := Options(Config{ DB: d, InstanceKey: instanceKey, Origin: env("ABONO_EXAMPLE_ORIGIN", "http://localhost:8080"), Owner: env("ABONO_EXAMPLE_OWNER", "owner@example.com"), Plans: os.Getenv("ABONO_EXAMPLE_PLANS"), Key: os.Getenv("STRIPE_KEY"), WebhookSecrets: secrets, Logger: logger, }) if err != nil { logger.Error("build app", "err", err) os.Exit(1) } // Loopback by default: rastrillo's own default is every interface. opts.Addr = env("ABONO_EXAMPLE_ADDR", "127.0.0.1:8080") if err := rastrillo.Serve(opts); err != nil { logger.Error("serve", "err", err) os.Exit(1) } } func env(name, def string) string { if v := os.Getenv(name); v != "" { return v } return def }