Skip to content
Proyek

Tentang

Reactive web apps in pure Go

Pengembangan web dan aplikasi

Cara angka ini diukur

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
0
dalam 15 hari
0
dalam 1 bulan
0

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

via

via

Go Reference CI CodeQL License: MIT

Live web UI in Go. A page is a struct, a click is a method call, and the server can push the change to every open tab. No JavaScript to write, no build step.

A counter every tab shares

via needs Go 1.27 or newer.

go mod init example.com/counter
go get github.com/go-via/via

main.go:

package main

import (
	"log"
	"net/http"
	"sync"

	"github.com/go-via/via"
	"github.com/go-via/via/h"
	"github.com/go-via/via/on"
	"github.com/go-via/via/topic"
)

var (
	mu    sync.Mutex
	count int64
	moved = topic.New[int64]()
)

func add(n int64) {
	mu.Lock()
	defer mu.Unlock()
	count += n
	moved.Publish(count)
}

func load() int64 {
	mu.Lock()
	defer mu.Unlock()
	return count
}

type Counter struct{ N via.State[int64] }

func (c *Counter) Inc(ctx *via.Ctx) { add(1) }
func (c *Counter) Dec(ctx *via.Ctx) { add(-1) }

func (c *Counter) View() h.H {
	return h.Div(
		h.Button(on.Click(c.Dec), h.Str("-")),
		h.H1(c.N.Display()),
		h.Button(on.Click(c.Inc), h.Str("+")),
	)
}

func main() {
	r := via.Handler(Counter{N: via.StateTrack(moved, load)})
	log.Fatal(http.ListenAndServe(":8080", r))
}
go run .

Open http://localhost:8080 in two tabs and click + in one. Both update. At startup via warns that no WithTrustedOrigin is set; Security covers what to set before you deploy. Getting started builds up to this program.

Why via

  • Actions are methods. on.Click(c.Inc) takes a method value, so a misspelled action is a compile error, not a dead button.
  • Live only where it needs to be. A page is plain HTTP until something on it goes live; then its tab holds one stream. Live state
  • Nothing to build. The browser client ships inside the module, and the markup is Go.
  • Testable from go test. Package vt drives pages, actions and live streams without a browser. Testing

What it costs

Live state is held on the server. What it costs lists the tradeoffs.

Documentation

Status

Pre-1.0: the API can change between minor versions. CHANGELOG.md records each release.

Contributing

./ci.sh

It is the release gate: green means releasable. It runs every check on all three modules, including the browser tier in vtbrowser, which needs Chromium or Chrome on PATH or in VIA_CHROME. It reports, never rewrites. A PR also runs ./mutation.sh origin/main, which mutates the changed lines in the root module and fails when the tests kill too few of the mutants.

CONVENTIONS.md has the code and test conventions, including the bar for a new duck-typed method.

License

MIT, see LICENSE.

Jelajahi proyek terkait

Memuat…