MCPcopy Index your code
hub / github.com/adhocteam/pushup

github.com/adhocteam/pushup @v0.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2 ↗ · + Follow
800 symbols 2,690 edges 27 files 48 documented · 6% updated 7d agov0.2 · 2023-12-22★ 85447 open issues

Browse by type

Functions 727 Types & classes 73
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Pushup - a page-oriented web framework for Go

workflow status Contributor Covenant

Project status

Pushup is an experiment. In terms of the development life cycle, it should be considered preview pre-release software: it is largely functional, likely has significant bugs (including potential for data loss) and/or subpar performance, but is suitable for demos and testing. It has a decent unit test suite, including fuzzing test cases for the parser. Don't count on it for anything serious yet, and expect significant breaking changes.

screenshot of syntax highlighting of an example Pushup page

Pushup is an experimental new project that is exploring the viability of a new approach to web frameworks in Go.

Pushup seeks to make building page-oriented, server-side web apps using Go easy. It embraces the server, while acknowledging the reality of modern web apps and their improvements to UI interactivity over previous generations.

What is Pushup?

Pushup is a program that compiles projects developed with the Pushup markup language into standalone web app servers.

There are three main aspects to Pushup:

  1. An opinionated project/app directory structure that enables file-based routing,
  2. A lightweight markup alternative to traditional web framework templates that combines Go code for control flow and imperative, view-controller-like code with HTML markup, and
  3. A compiler that parses that markup and generates pure Go code, building standalone web apps on top of the Go stdlib net/http package.

Pages in Pushup

The core object in Pushup is the "page": a file with the .up extension that is a mix of HTML, Go code, and a lightweight markup language that glues them together. Pushup pages participate in URL routing by virtue of their path in the filesystem. Pushup pages are compiled into pure Go which is then built along with a thin runtime into a standalone web app server (which is all net/http under the hood).

The main proposition motivating Pushup is that the page is the right level of abstraction for most kinds of server-side web apps.

The syntax of the Pushup markup language looks like this:


^import "time"

^{
    title := "Hello, from Pushup!"
}

<h1>^title</h1>



The time is now ^time.Now().String().



^if time.Now().Weekday() == time.Friday {


It's Friday! Enjoy the start to your weekend.


} ^else {


Have a great day, we're glad you're here.


}

You would then place this code in a file somewhere in your app/pages directory, like hello.up. The .up extension is important and tells the compiler that it is a Pushup page. Once you build and run your Pushup app, that page is automatically mapped to the URL path /hello.

Quick start with Docker

git clone https://github.com/adhocteam/pushup.git
cd pushup
make build-docker

Then create a scaffolded new project in the current directory:

docker run --rm -v $(pwd):/usr/src/app --user $(id -u):$(id -g) pushup new myproject
cd myproject
docker run --rm -v $(pwd):/usr/src/app --user $(id -u):$(id -g) -p 8080:8080 pushup run

See Creating a new Pushup project for more information.

Getting started

To make a new Pushup app, first install the main Pushup executable.

Installing Pushup

Prerequisites

  • go 1.18 or later

Make sure the directory where the go tool installs executables is in your $PATH. It is $(go env GOPATH)/bin. You can check if this is the case with:

echo $PATH | grep $(go env GOPATH)/bin > /dev/null && echo yes || echo no

Install an official release

Download Pushup for your platform from the releases page.

Install via git

git clone git@github.com:AdHocRandD/pushup.git
cd pushup
make

Install via go install

Make sure you have Go installed (at least version 1.18), and type:

go install github.com/adhocteam/pushup@latest

Creating a new Pushup project

To create a new Pushup project, use the pushup new command.

pushup new

Without any additional arguments, it will attempt to create a scaffolded new project in the current directory. However, the directory must be completely empty, or the command will abort. To simulataneously make a new directory and generate a scaffolded project, pass a relative path as argument:

pushup new myproject

The scaffolded new project directory consists of a directory structure for .up files and auxiliary project Go code, and a go.mod file.

Change to the new project directory if necessary, then do a pushup run, which compiles the Pushup project to Go code, builds the app, and starts up the server.

pushup run

If all goes well, you should see a message on the terminal that the Pushup app is running and listening on a port:

↑↑ Pushup ready and listening on 0.0.0.0:8080 ↑↑

By default it listens on port 8080, but with the -port or -unix-socket flags you can pick your own listener.

Open http://localhost:8080/ in your browser to see the default layout and a welcome index page.

Example demo app

See the example directory for a demo Pushup app that demonstrates many of the concepts in Pushup and implements a few small common patterns like some HTMX examples and a simple CRUD app.

Click on "view source" at the bottom of any page in the example app to see the source of the .up page for that route, including the source of the "view source" .up page itself. This is a good way to see how to write Pushup syntax.

Go modules and Pushup projects

Pushup treats projects as their own self-contained Go module. The build process assumes this is the case by default. But it is possible to include a Pushup project as part of a parent Go module. See the the -module option to pushup new.

Project directory structure

Pushup projects have a particular directory structure that the compiler expects before building. The most minimal Pushup project would look like:

app
├── layouts
├── pages
│   └── index.up
├── pkg
└── static
go.mod

Pages

Pushup pages are the main units in Pushup. They are a combination of logic and content. It may be helpful to think of them as both the controller and the view in a MVC-like system, but colocated together in the same file.

They are also the basis of file-based routing: the name of the Pushup file, minus the .up extension, is mapped to the portion of the URL path for routing.

Layouts

Layouts are HTML templates that used in common across multiple pages. They are just HTML, with Pushup syntax as necessary. Each page renders its contents, and then the layout inserts the page contents into the template with the ^outputSection("contents") Pushup expression.

Static media

Static media files like CSS, JS, and images, can be added to the app/static project directory. These will be embedded directly in the project executable when it is built, and are accessed via a straightforward mapping under the "/static/" URL path.

File-based routing

Pushup maps file locations to URL route paths. So about.up becomes /about, and foo/bar/baz.up becomes /foo/bar/baz. More TK ...

You can print a list of the app's routes with the command:

pushup routes

Dynamic routes

If the filename of a Pushup page starts with a $ dollar sign, the portion of the URL path that matches will be available to the page via the getParam() Pushup API method.

For example, let's say there is a Pushup page at app/pages/people/$id.up. If a browser visits the URL /people/1234, the page can access it like a named parameter with the API method getParam(), for example:



ID: ^getParam(req, "id")


would output:



ID: 1234


The name of the parameter is the word following the $ dollar sign, up to a dot or a slash. Conceptually, the URL route is /people/:id, where :id is the named parameter that is substituted for the actual value in the request URL.

Directories can be dynamic, too. app/pages/products/$pid/details.up maps to /products/:pid/details.

Multiple named parameters are allowed, for example, app/pages/users/$uid/projects/$pid.up maps to /users/:uid/projects/:pid.

Enhanced hypertext

Inline partials

Inline partials allow pages to denote subsections of themselves, and allow for these subsections (the inline partials) to be rendered and returned to the client independently, without having to render the entire enclosing page.

Typically, partials in templating languages are stored in their own files, which are then transcluded into other templates. Inline partials, however, are partials declared and defined in-line a parent or including template.

Inline partials are useful when combined with enhanced hypertext solutions (eg., htmx). The reason is that these sites make AJAX requests for partial HTML responses to update portions of an already-loaded document. Partial responses should not have enclosing markup such as base templates applied by the templating engine, since that would break the of the document they are being inserted into. Inline partials in Pushup automatically disable layouts so that partial responses have just the content they define.

The ability to quickly define partials, and not have to deal with complexities like toggling off layouts, makes it easier to build enhanced hypertext sites.

Basic web framework functionality

All modern web frameworks should implement a standard set of functionality, spanning from safety to convenience. As of this writing, Pushup does not yet implement them all, but aspires to prior to any public release.

Escaping

By default, all content is HTML-escaped, so in general it is safe to directly place user-supplied data into Pushup pages. (Note that the framework does not (yet) do this in your Go code, data from form submissions and URL queries should be validated and treated as unsafe.)

For example, if you wanted to display on the page the query a user searched for, this is safe:

^{ query := req.FormValue("query") }


You search for: <b>^query</b>


Pushup syntax

How it works

Pushup is a mix of a new syntax consisting of Pushup directives and keywords, Go code, and HTML markup.

Parsing a .up file always starts out in HTML mode, so you can just put plain HTML in a file and that's a valid Pushup page.

When the parser encounters a '^' character (caret, ASCII 0x5e) while in HTML mode, it switches to parsing Pushup syntax, which consists of simple directives, control flow statements, block delimiters, and Go expressions. It then switches to the Go code parser. Once it detects the end of the directive, statement, or expression, it switches back to HTML mode, and parsing continues in a similar fashion.

Pushup uses the tokenizers from the [go/scanner][scannerpkg] and [golang.org/x/net/html][htmlpkg] packages, so it should be able to handle any valid syntax from either language.

Directives

^import

Use ^import to import a Go package into the current Pushup page. The syntax for ^import is the same as a regular Go import declaration

Example:

^import "strings"
^import "strconv"
^import . "strings"

^layout

Layouts are HTML templates that enclose the contents of a Pushup page.

The ^layout directive instructs Pushup what layout to apply the contents of the current page.

The name of the layout following the directive is the file

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 609
Method 118
Struct 54
TypeAlias 12
Interface 6
FuncType 1

Languages

TypeScript62%
Go38%

Modules by API surface

scaffold/static/htmx.min.js164 symbols
example/app/static/js/htmx.min.js164 symbols
docs/app/static/htmx.min.js164 symbols
parser.go60 symbols
main.go44 symbols
codegen.go39 symbols
ast.go38 symbols
_runtime/pushup_support.go31 symbols
lexer.go30 symbols
reloader.go11 symbols
example/app/pkg/app.go9 symbols
compiler.go8 symbols

For agents

$ claude mcp add pushup \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page