initial commit
Some checks failed
ci / go (push) Has been cancelled
ci / admin-ui (push) Has been cancelled
ci / runtime-sdk (push) Has been cancelled
ci / helm (push) Has been cancelled
ci / openapi (push) Has been cancelled
ci / container (push) Has been cancelled
ci / release-config (push) Has been cancelled
ci / shared styling (push) Has been cancelled
ci / security (push) Has been cancelled
ci / all green (push) Has been cancelled

This commit is contained in:
Daniel Noulet 2026-10-07 15:11:35 +02:00
commit 951dd8d26b
175 changed files with 50041 additions and 0 deletions

95
cmd/go-bananas/main.go Normal file
View file

@ -0,0 +1,95 @@
// Command go-bananas is the theme service: an administrative UI for authoring
// design-token themes, and a runtime API that serves those themes to any
// application at run time.
//
// It reads its entire configuration from the environment so that the Helm chart
// is the single source of truth for how a deployment is configured.
package main
import (
"context"
"errors"
"fmt"
"io"
"os"
"os/signal"
"syscall"
"github.com/urpi/go-bananas/internal/app"
)
func main() {
os.Exit(run(os.Args[1:]))
}
// run dispatches on the subcommand and returns the process exit status.
//
// The subcommand is checked before the signal handler is installed: a backup is a
// short batch job that should exit on its own, and a context cancelled by an
// interrupt would make a snapshot look like it failed when it was in fact told to
// stop.
func run(args []string) int {
// The server is the default, so an invocation with no arguments, or one whose
// first argument is not a known subcommand, starts it.
if len(args) > 0 {
switch args[0] {
case "backup":
if err := app.RunBackup(context.Background(), args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "Go Bananas!! backup: %v\n", err)
return 1
}
return 0
case "version":
fmt.Printf("Go Bananas!! %s\n", app.Version)
return 0
case "help", "-h", "--help":
usage(os.Stdout)
return 0
}
}
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
if err := app.Run(ctx); err != nil {
// Configuration and wiring failures are the expected failure mode at
// start-up, so they are reported plainly on stderr with no log decoration.
fmt.Fprintf(os.Stderr, "Go Bananas!!: %v\n", err)
return exitCodeFor(err)
}
return 0
}
// usage prints the top-level help.
func usage(w io.Writer) {
fmt.Fprint(w, `usage: go-bananas [command]
Runs the theme service: an administrative UI for authoring design-token themes and
a runtime API that serves them to any application at run time.
With no command, the HTTP server starts. Configuration comes entirely from the
environment; see docs/deployment.md.
Commands:
backup Write a consistent snapshot of the database and exit
version Print the build version
help Print this message
Examples:
go-bananas
go-bananas backup --to /srv/data/snapshots/go-bananas.db
`)
}
// exitCodeFor maps an error onto a process exit status.
//
// 1 configuration or wiring failure
// 2 the context was cancelled before the server started
func exitCodeFor(err error) int {
switch {
case errors.Is(err, context.Canceled):
return 2
default:
return 1
}
}