web

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: Apache-2.0, MIT Imports: 34 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Pages, screens and attachments over HTTP (web)

Package web is the part of a ringi server that browsers use. It serves

  • the pages on which people make requests, approve them and follow their own
  • the screens ritsu made (A2UI), filled with the server's data, and what their buttons do
  • the files people attach

and passes every other request to the server's API. It also does what a browser needs for all of them: it finds whose request it is, refuses what another site sends, limits sizes, and sets the headers. Japanese: README.ja.md.

To Read
run a server that ritsu ringi init made Run it, and approve a request. Package serve uses this package, and you call nothing of it
put a server together in Go Embed it in a program of your own, and Use, below
make screens of your own, with the API or with A2UI Make screens of your own
see what is sent and what comes back With curl, below
know how it works, and why the design

Use

srv, err := server.New(server.Config{…, Files: store.Files()}) // or web.NewDiskFiles(dir)
h, err := web.New(srv, web.Config{
	Require: signIn.Require, LoginURL: signIn.LoginURL, SignOut: "/logout", // a sign-in's hooks, for the pages
})
signIn.Mount(h) // the sign-in's routes, behind the same guards
(&http.Server{Addr: ":8080", Handler: h, ReadHeaderTimeout: 5 * time.Second}).ListenAndServe()

The server's Authenticator finds whose request it is. With a sign-in that keeps a session (package oidc), Config.Require sends a browser with no session to sign in and back, and each page has a button to sign out. Behind a proxy that signs people in, web.ProxyHeader takes the person from the proxy's headers (how).

The routes

The pages
Route What it returns
GET / A redirect to /pages/
GET /pages/ The start page: what waits for the person, the requests they may make, and their own requests, with counts; and the request types whose requests they see all of (the department that keeps a type)
GET, POST /pages/requests/{kind}/new The form of a new request, and its post
GET, POST /pages/tickets/{id} A request, and the buttons of what the person may do to it; its post
GET, POST /pages/tickets/{id}/form The form to submit a request again that was sent back, and its post
GET /pages/tickets/{id}/history The history of a request
GET /pages/waiting/{kind}, /pages/mine/{kind} The requests of the kind that wait for the person, and the person's own: the newest first, 50 a page
GET /pages/requests/{kind} All the requests of the kind, to a person the gate lets see them all: the newest first, 50 a page
GET /pages/assets/{name} The style sheet and the script of the pages, and ritsu's functions
The A2UI screens
Route What it returns
GET /a2ui/requests/{kind}/form The form of a new request
GET /a2ui/tickets/{id}/card, …/form, …/history A request's screens
GET /a2ui/waiting/{kind}, /a2ui/mine/{kind}, /a2ui/requests/{kind} The same lists as the pages', ?limit= of them (50 when not given, 100 at most) after ?before=
POST /a2ui/actions Does what a button asks, and returns the screen after it
GET /a2ui/find/people, /a2ui/find/teams, /a2ui/find/masters/{file}/{master} The values that a part of their names or IDs finds, for the fields that choose one (the design, 5.1)
GET /a2ui/catalog.json, /a2ui/functions.js ritsu's catalog and functions
The attachments
Route What it returns
POST /files The ID of the attachment it keeps
GET /files/{id} An attachment, for the person who uploaded it
GET /tickets/{ticket}/files/{id} An attachment of a request, for the people who may see the request

How a page answers

The pages are plain HTML, and work without a script: a person makes a request, approves it, or sends it back. The script adds what only a script can do. It works out totals as one types, shows what is wrong before the form is sent, and adds rows without a round trip.

A form is posted to the page it came from. The handler makes it an operation of the API and does it as the person. White space at the ends of texts and comments is left out.

The post is The browser gets
taken The page of the request (303), so that reloading sends nothing again
stopped by the page's own checks The page again, with what was typed and why (422)
refused by the server The page again, with the reason in the page's language, at the field it is about or at the head of the page (409). If the request changed after the page was shown, it is shown as it is now
Enter in a field, without the script Nothing (204): the page stays, with what was typed and the focus

The language

A page is in English or Japanese, and a screen is in one of the languages of its request type. The first of these is used:

  1. the one chosen with ?lang= (a cookie keeps it for the pages)
  2. the browser's (Accept-Language)
  3. the person's in the organization's data (the column language of people.csv)
  4. the request type's own (server.LanguageChoice)

With curl

In examples/, start the example server, with the attachments in a directory:

go run ./cmd/server -files ./files

The header X-Person says who sends a request. It is for your own computer, and checks no one (Three ways to sign in). To see the pages themselves, start the server with -dev-login and open http://127.0.0.1:8080/ (Try it). Run the commands below in another terminal, in a directory of your own. The IDs differ each time.

A page

It loads its style sheet and its script from the server, under a policy of its own.

curl -sI -H 'X-Person: e1201' 'http://127.0.0.1:8080/pages/?lang=en'
HTTP/1.1 200 OK
Cache-Control: no-store
Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'
Content-Type: text/html; charset=utf-8
Referrer-Policy: same-origin
Set-Cookie: ringi-lang=en; Path=/; Max-Age=31536000; HttpOnly; SameSite=Lax
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

A form that another site sends

It is refused before it is read, with a page that says so.

curl -s -o /dev/null -w '%{http_code}\n' -H 'X-Person: e1201' -H 'Origin: https://elsewhere.example' \
  --data-urlencode '_do=button.submit' 'http://127.0.0.1:8080/pages/requests/expense/new?lang=en'
403
The form of a new request

e1201, on the sales staff of Section 1A, opens the form of an expense as a screen. The answer is A2UI's messages, in the order a renderer takes them. can says which buttons the form shows.

curl -s -H 'X-Person: e1201' 'http://127.0.0.1:8080/a2ui/requests/expense/form?lang=en' \
  | jq -c '[.[] | keys[0]], .[1].updateDataModel.value.can'
["createSurface","updateDataModel","updateComponents"]
{"discard":false,"resubmit":false,"submit":true}

The form's data also holds two addresses the handler fills in: find (/a2ui/find), where the fields that choose a value search, and upload (/files), where the file field sends a file.

Finding a person

A renderer's PersonPicker finds people by a part of the name, in either language, under the form's find. The pages do the same past 1,000 people (web.PicksListed).

curl -s -H 'X-Person: e1201' 'http://127.0.0.1:8080/a2ui/find/people?q=staff+3&lang=en' | jq -c .
curl -s -G -H 'X-Person: e1201' --data-urlencode 'q=営業 3' --data-urlencode 'lang=ja' \
  http://127.0.0.1:8080/a2ui/find/people | jq -c .
{"found":[{"value":"e1203","name":"Sales staff 3","label":"Sales staff 3 (e1203)"}],"more":false}
{"found":[{"value":"e1203","name":"営業担当 3","label":"営業担当 3(e1203)"},{"value":"e3101","name":"営業一部長","label":"営業一部長(e3101)"}],"more":false}

The second finds e3101 too, as each word is in its name or its ID (3 in e3101). Only the people of the organization find people and teams, as through the API.

curl -s -w ' %{http_code}\n' -H 'X-Person: x9999' 'http://127.0.0.1:8080/a2ui/find/people?q=staff+3&lang=en'
{"error":"the organization is read by its people only, and x9999 is not in the version in effect on 2026-11-18"} 404
Uploading a receipt

The file field of the form uploads it to the form's upload, and puts its id in the form.

printf '%%PDF-1.4\n%% a receipt (fictional)\n' > receipt.pdf
curl -s -H 'X-Person: e1201' -F 'file=@receipt.pdf;type=application/pdf' http://127.0.0.1:8080/files | tee uploaded.json | jq .
{
  "id": "910972bb8b22fc6b54a795faa6d008fb",
  "name": "receipt.pdf",
  "content_type": "application/pdf",
  "size": 33,
  "url": "/files/910972bb8b22fc6b54a795faa6d008fb"
}
Making the request

Here it is made through the API. The submit button of the form does the same operation.

F=$(jq -r .id uploaded.json)
cat > request.json <<EOF
{"form": {"category": "purchase", "items": [{"what": "A second monitor", "price": 32000}],
          "purpose": "A monitor for the desk", "used_on": "2026-11-16", "receipt": "$F"},
 "comment": "The receipt is attached."}
EOF
curl -s -H 'X-Person: e1201' -H 'Idempotency-Key: monitor-1' -H 'Content-Type: application/json' \
  -d @request.json http://127.0.0.1:8080/requests/expense/tickets | tee made.json \
  | jq -c '{id: .ticket.id, stage: .ticket.stage, approvers: .ticket.stages[0].parts[0].approvers}'
{"id":"01M7KSHBTFEM304GVA00FCBYEH","stage":"first","approvers":["e1101"]}

A form may name only a file the ticket already holds, or one that the person sending it uploaded. With a file of e1101's, the same request is answered 400, as for an ID that is not there.

printf 'notes\n' > notes.txt
O=$(curl -s -H 'X-Person: e1101' -F 'file=@notes.txt;type=text/plain' http://127.0.0.1:8080/files | jq -r .id)
sed "s/$F/$O/" request.json > other.json
curl -s -w ' %{http_code}\n' -H 'X-Person: e1201' -H 'Idempotency-Key: monitor-2' \
  -H 'Content-Type: application/json' -d @other.json http://127.0.0.1:8080/requests/expense/tickets
{"error":"form.receipt: no such file"} 400
The approver's card

e1101, the manager of Section 1A, opens the ticket's card in Japanese. The buttons are the ones e1101 may press now, the names are in the screen's language, and the receipt is linked through the ticket.

T=$(jq -r .ticket.id made.json)
curl -s -H 'X-Person: e1101' "http://127.0.0.1:8080/a2ui/tickets/$T/card?lang=ja" | tee card.json \
  | jq -c '.[1].updateDataModel.value | {can, people, files}'
{"can":{"add_approver":false,"approve":true,"comment":true,"discard":false,"edit":true,"hand_over":false,"reject":true,"send_back":true,"withdraw":false},"people":{"e1101":"営業一課長","e1201":"営業担当 1"},"files":{"910972bb8b22fc6b54a795faa6d008fb":"/tickets/01M7KSHBTFEM304GVA00FCBYEH/files/910972bb8b22fc6b54a795faa6d008fb"}}
Opening the receipt

A browser shows a PDF. It saves a file of a type it is not to show, whose answer has the CSP sandbox. The Date header is left out here.

curl -si -H 'X-Person: e1101' http://127.0.0.1:8080/tickets/$T/files/$F
HTTP/1.1 200 OK
Cache-Control: no-store
Content-Disposition: inline; filename=receipt.pdf
Content-Length: 33
Content-Security-Policy: default-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'
Content-Type: application/pdf
Referrer-Policy: same-origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

%PDF-1.4
% a receipt (fictional)

Before a ticket holds a file, only the person who uploaded it may download it. After that, the people who may see the ticket may, through the ticket. To anyone else it is answered 404, as a file that is not there.

for p in "e1201 /files/$F" "e1101 /files/$F" "e2101 /tickets/$T/files/$F"; do
  echo "${p%% *} ${p#* } $(curl -s -o /dev/null -w '%{http_code}' -H "X-Person: ${p%% *}" http://127.0.0.1:8080${p#* })"
done
e1201 /files/910972bb8b22fc6b54a795faa6d008fb 200
e1101 /files/910972bb8b22fc6b54a795faa6d008fb 404
e2101 /tickets/01M7KSHBTFEM304GVA00FCBYEH/files/910972bb8b22fc6b54a795faa6d008fb 404
Approving on the card

This is the message a renderer posts when the approve button is pressed, with the revision the card shows.

R=$(jq -c '.[1].updateDataModel.value.ticket.revision' card.json)
cat > approve.json <<EOF
{"version": "1.0", "action": {"name": "approve", "surfaceId": "expense.card.$T", "sourceComponentId": "button.approve",
  "timestamp": "2026-11-17T01:00:00Z", "context": {"ticket": "$T", "revision": $R, "comment": "OK."}}}
EOF
curl -s -H 'X-Person: e1101' -H 'Content-Type: application/json' -d @approve.json \
  'http://127.0.0.1:8080/a2ui/actions?lang=ja' | jq -c '{outcome, ticket, messages: [.messages[] | keys[0]]}'
{"outcome":"ok","ticket":"01M7KSHBTFEM304GVA00FCBYEH","messages":["deleteSurface","createSurface","updateDataModel","updateComponents"]}

The surface the button was on is deleted, and the card is filled again on it. The same message sent again (a double click, a retry) is the same operation. The answer is the same, and the ticket moved once, to its second stage.

curl -s -H 'X-Person: e1101' -H 'Content-Type: application/json' -d @approve.json \
  'http://127.0.0.1:8080/a2ui/actions?lang=ja' | jq -c '{outcome, ticket, messages: [.messages[] | keys[0]]}'
curl -s -H 'X-Person: e1201' http://127.0.0.1:8080/tickets/$T \
  | jq -c '{stage: .ticket.stage, answered: [.ticket.stages[] | select(.phase == "answered") | .parts[].answers[].by]}'
{"outcome":"ok","ticket":"01M7KSHBTFEM304GVA00FCBYEH","messages":["deleteSurface","createSurface","updateDataModel","updateComponents"]}
{"stage":"second","answered":["e1101"]}
A refusal

Pressed again on the old card with another comment, the approval is a new operation, and e1101 may no longer approve. words is the sentence for the person, in the screen's language. The card comes back as the ticket is now: without the button, with the refusal in its refused, and with the comment put back.

sed 's/"OK."/"OK, once more."/' approve.json > again.json
curl -s -w '\n%{http_code}\n' -H 'X-Person: e1101' -H 'Content-Type: application/json' -d @again.json \
  'http://127.0.0.1:8080/a2ui/actions?lang=ja' > again.out
head -1 again.out | jq -c '{outcome, refused, words, messages: [.messages[] | keys[0]]}'; tail -1 again.out
{"outcome":"refused","refused":"person","words":"この操作はできません。","messages":["deleteSurface","createSurface","updateDataModel","updateComponents","updateDataModel"]}
409
A person's own requests

They are listed the newest first, 50 a page. ?limit= asks for 1 to 100, and ?before= is the last ticket of the page before. In each row, made_by is the person who made the request for its requester, or null when the requester made it.

curl -s -H 'X-Person: e1201' 'http://127.0.0.1:8080/a2ui/mine/expense?lang=en' \
  | jq -c '[.[] | keys[0]], [.[1].updateDataModel.value.tickets[] | {id, status, stage}]'
["createSurface","updateDataModel","updateComponents"]
[{"id":"01M7KSHBTFEM304GVA00FCBYEH","status":"in_progress","stage":"second"}]
A kind with no version in effect

e6001 switches version 1 of leave off (Administer it). Version 2 starts on 2027-04-01, so until then a new leave request has no form. A person who may make it from that day gets a screen that says the day, with the way back to the start page. For anyone else there is no such kind.

curl -s -o /dev/null -X POST http://127.0.0.1:8080/admin/kinds/leave/versions/1 -H 'X-Person: e6001' \
  -H 'X-Roles: workflow_admin' -H 'Content-Type: application/json' -H 'Idempotency-Key: off-1' \
  -d '{"start": "never", "reason": "Version 2 replaces it", "number": 0}'
curl -s -o offered.json -w '%{http_code}\n' -H 'X-Person: e1201' 'http://127.0.0.1:8080/a2ui/requests/leave/form?lang=en'
jq -c '[.[] | keys[0]]' offered.json
jq -c '.[1].updateDataModel.value' offered.json
curl -s -w ' %{http_code}\n' -H 'X-Person: e0001' 'http://127.0.0.1:8080/a2ui/requests/leave/form?lang=en'
200
["createSurface","updateDataModel","updateComponents"]
{"from":"2027-04-01","home":"/pages/?lang=en"}
{"error":"no such kind of request"} 404
What another site sends, and what no one sends

A POST of another site is refused before it is read. A screen asked for with no person is answered 401.

curl -s -w ' %{http_code}\n' -H 'X-Person: e1101' -H 'Content-Type: application/json' \
  -H 'Origin: https://elsewhere.example' -d @again.json http://127.0.0.1:8080/a2ui/actions
curl -s -w ' %{http_code}\n' http://127.0.0.1:8080/a2ui/tickets/$T/card
{"error":"a request from another origin"} 403
{"error":"no one is signed in"} 401
The catalog and the functions

They need no person. A renderer keeps them by their ETag.

curl -sI http://127.0.0.1:8080/a2ui/functions.js
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Security-Policy: default-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'
Content-Type: text/javascript; charset=utf-8
Etag: "c6b49574b07eda4dc3b9320ba76b4eee19c0854e01d8584f690b797ae3964426"
Referrer-Policy: same-origin
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

Stop the server with Ctrl-C.

The tests

go test ./web checks the stores of files, the proxy's headers and the small parts. go test ./... in examples/ checks the routes on the examples: who gets which page, screen and button, what is refused, the languages, the lists a page at a time, the attachments, signing in, and the vectors made on the pages and on the screens. Changing the framework says what they need, what came of them, and how the pages are tested in a browser.

Documentation

Overview

Package web serves the pages people use in a browser, in which they make requests, approve them and see their own. In front of the server's API, it also serves the A2UI screens filled with the server's data and the actions of their buttons, ritsu's catalog and functions, and the files people attach. All of it is behind one set of guards: the person, the protection against cross-site requests, the limits of size, and the headers a browser is held to.

Package serve uses it. https://i2y.github.io/ringi-server/screens/ says how to add routes and screens of your own, README.md what each route answers, and DESIGN.md how it works.

Index

Constants

View Source
const (
	PagesPath  = "/pages/"
	PageAssets = "/pages/assets/"
)

The addresses of the pages and of their files.

View Source
const (
	Policy     = "default-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'"
	PagePolicy = "" /* 152-byte string literal not displayed */
)

The policies of the Content-Security-Policy header: Policy for every answer of this package, PagePolicy for an HTML page that loads its style sheet and script from the server.

View Source
const DefaultMaxFile = 10 << 20

DefaultMaxFile is the largest attachment when Config.MaxFile is 0.

View Source
const FindPath = "/a2ui/find"

FindPath is where a picker finds the values it has too many of to list (DESIGN 5.1), the address the screens' /find holds (ringi's DESIGN 13.2): a renderer's PersonPicker and MasterPicker, and the pages' script, find under it, at "/people", "/teams" or "/masters/<file>/<master>".

View Source
const LanguageCookie = "ringi-lang"

LanguageCookie keeps the language a person chose on a page (with ?lang=).

View Source

MaxLogo is the most bytes of Look.Logo.

View Source
const MaxLookName = 60

MaxLookName is the most characters of Look.Name.

View Source
const MinProxySecret = 32

MinProxySecret is the shortest Secret ProxyHeader takes.

View Source
const OpenAPIPath = "/openapi.json"

OpenAPIPath is where the description of the whole API is served (server.Server.OpenAPI): the kinds' operations, the ones no kind owns, the administration's and the attachments', as OpenAPI 3.1, to a person signed in.

View Source
const PicksListed = 1000

PicksListed is the most people, teams or rows of a master a picker lists: with more, a person finds the value by a name (FindPath, server.Find), or types its ID or key.

View Source
const UploadPath = "/files"

UploadPath is where a file is uploaded (DESIGN 6.2): the address the screens' /upload holds (ringi's DESIGN 13.2), which a FileAttachment posts its file to.

Variables

View Source
var (
	ErrTooLarge    = errors.New("web: the file is larger than the server takes")
	ErrFileType    = errors.New("web: the server does not take files of this type")
	ErrFileContent = errors.New("web: the file is not of the type it is sent as")
	ErrNoFiles     = errors.New("web: the server keeps no files")
)

The errors of keeping a file: one larger than Config.MaxFile, one of a media type it does not take, one that does not begin as a file of its media type does, and a server with no Config.Files.

View Source
var DefaultFileTypes = []string{
	"application/pdf",
	"image/png", "image/jpeg", "image/gif", "image/webp",
	"text/plain", "text/csv",
	"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
	"application/vnd.openxmlformats-officedocument.presentationml.presentation",
	"application/vnd.oasis.opendocument.text",
	"application/vnd.oasis.opendocument.spreadsheet",
	"application/vnd.oasis.opendocument.presentation",
}

DefaultFileTypes are the media types an attachment may have when Config.FileTypes is nil: PDF, images, text, CSV, and the documents of word processors, spreadsheets and presentations.

View Source
var DefaultInline = []string{"application/pdf", "image/png", "image/jpeg", "image/gif", "image/webp"}

DefaultInline are the media types a browser shows rather than saves when Config.Inline is nil.

View Source
var ErrShortSecret = errors.New("web: ProxyHeader needs a Secret of at least 32 characters")

ErrShortSecret is ProxyHeader's failure with no Secret, or one shorter than 32 characters.

Functions

This section is empty.

Types

type CatalogConflict

type CatalogConflict struct {
	First, Second           int      // the packages, from 1, in the order of Config.Packages
	FirstKinds, SecondKinds []string // the kinds of each, as "<name> <version>"
	ID                      string   // the catalog's ID
}

CatalogConflict is New's error for two packages whose screens name one catalog by its ID, each with a catalog of other files (catalog.json or functions.js): a renderer keeps one catalog by its ID (A2UI 1.0), so it would draw the screens of one of them with the functions of the other. Two packages that name one ID with the same files are one catalog, and are taken.

func (*CatalogConflict) Error

func (e *CatalogConflict) Error() string

func (*CatalogConflict) In

func (e *CatalogConflict) In(lang string) string

In says the error in a language: "ja" in Japanese, any other in English.

type Config

type Config struct {
	// MaxFile is the largest attachment, in bytes (10 MiB when 0).
	MaxFile int64
	// FileTypes are the media types an attachment may have (DefaultFileTypes when nil).
	FileTypes []string
	// Inline are the media types a browser shows rather than saves (DefaultInline when nil): PDF and
	// the images of DefaultInline at most, whose first bytes the handler checks (New refuses others).
	Inline []string
	// TrustedOrigins are origins ("https://host[:port]") besides the server's own that may send
	// what changes things: a host of the screens on an origin of its own.
	TrustedOrigins []string
	Logger         *slog.Logger

	// Require wraps each route of the plain HTML pages: a sign-in's guard, which sends a browser with
	// no session to sign in and come back (oidc's SignIn.Require). With none, a page asked for with
	// no person is a notice (401).
	Require func(http.Handler) http.Handler
	// LoginURL answers the address of signing in that comes back to a path, for the link of that
	// notice (oidc's SignIn.LoginURL); nil shows none.
	LoginURL func(returnTo string) string
	// SignOut is the path the pages' bar posts to, to sign out (oidc's LogoutPath); "" shows no
	// button.
	SignOut string

	// Look is how the pages look for the organization: its logo and name in the bar, and the colour
	// of the links and the buttons. The zero Look is the framework's.
	Look Look
}

Config is what the handler is made with. The rest (the person, the files, the largest body) is the server's.

type DiskFiles

type DiskFiles struct {
	// contains filtered or unexported fields
}

DiskFiles keeps the attachments in a directory: each file at <dir>/<id[:2]>/<id>, and what is kept of it at <id>.json beside it, each written to a temporary file and renamed into place. An ID is 32 lowercase hexadecimal digits; any other is not looked up.

func NewDiskFiles

func NewDiskFiles(dir string) (*DiskFiles, error)

NewDiskFiles makes the store of a directory, making the directory when it is not there.

func (*DiskFiles) Delete

func (d *DiskFiles) Delete(_ context.Context, id string) error

Delete deletes a file: its record first, so that it is not there from then on, then its bytes. Bytes left by a failure are deleted when it is deleted again.

func (*DiskFiles) Open

Open reads a file.

func (*DiskFiles) Put

func (d *DiskFiles) Put(_ context.Context, info server.FileInfo, r io.Reader) (string, error)

Put keeps a file and answers its ID.

func (*DiskFiles) Stat

func (d *DiskFiles) Stat(_ context.Context, id string) (server.FileInfo, error)

Stat answers what is kept of a file.

func (*DiskFiles) URL

func (d *DiskFiles) URL(ctx context.Context, id string) (string, error)

URL answers "": the server sends the bytes itself.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the pages, the screens, the attachments and the server's API.

func New

func New(srv *server.Server, cfg Config) (*Handler, error)

New makes the handler of a server. It loads the screens of each package the server serves, and refuses one whose screens do not load, and a Look that Look.Check refuses.

func (*Handler) Handle

func (h *Handler) Handle(pattern string, handler http.Handler)

Handle adds a route (a ServeMux pattern) behind the guards: a page of the plain HTML screens, or a route of signing in. It finds the person with Person.

func (*Handler) Keep

Keep keeps a file a person posted with a form, as an upload keeps it: ErrTooLarge past Config.MaxFile, ErrFileType for a media type Config.FileTypes does not have, ErrFileContent for a file that does not begin as its type does, *server.TooManyUploads for a person who has as many uploads that no ticket holds as the server keeps. It answers the file's ID. It keeps the file anew each time; a post of a page keeps its files with Keeper.

func (*Handler) Keeper

func (h *Handler) Keeper(ctx context.Context, p server.Person, post page.Post) page.Keeper

Keeper keeps the files a post of a page (of package page) attaches as the person's, as an upload does, each once: the same post sent again (pressed twice with no script, sent again from a page gone back to) names the files it named the first time, and is the same operation. A file the server does not take is said at its field.

func (*Handler) Lookup

func (h *Handler) Lookup(ctx context.Context, p server.Person, ticket string) *Lookup

Lookup makes the lookup of a screen the person is shown: of a ticket, or of no ticket ("") for a new request's form and a list.

func (*Handler) Person

func (h *Handler) Person(r *http.Request) (server.Person, error)

Person answers who sends r: the server's Authenticator's answer.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP puts the headers on the answer and serves the request behind the guards.

type Look

type Look struct {
	// Name is the organization's name, or the pages', at the start of the bar: at most MaxLookName
	// characters, with no control character and no space at its ends. "" for none: the bar says
	// "Home" where there is no logo either.
	Name string
	// at most MaxLogo bytes, served at PageAssets+"logo". The bar shows it 1.75rem high (28 pixels at
	// the browser's usual size). nil for none.
	Logo []byte
	// Accent is the colour of the links, the buttons and the stage a request is at on the light
	// pages, as #rrggbb: it reads at 4.5:1 or more on their paper and tint (WCAG 1.4.3). "" for the
	// framework's.
	Accent string
	// AccentDark is the same on the dark pages, for a browser set to the dark scheme: it reads at
	// 4.5:1 or more on their dark paper and tint. "" makes it of Accent, mixed with white in steps of
	// 5 % until it reads; with no Accent either, it is the framework's.
	AccentDark string
}

Look is how the pages look for an organization: its logo and name at the start of the pages' bar, where they lead to the start page, and the colour of the links, the buttons and the stage a request is at. The zero Look is the framework's. It is the look of the plain HTML pages, and of the pages of signing in that load their style sheet; a host of the A2UI screens shows them in its own. New refuses a Look that Check refuses.

func (Look) Check

func (l Look) Check() error

Check says what is wrong with a look: a name too long, with a control or format character, or with a space at its ends; a logo too large, or of no image type the pages show; a colour that is not #rrggbb, or does not read at 4.5:1 on the pages it is for. The package serve asks it before it makes or reaches anything, and New asks it too.

type Lookup

type Lookup struct {
	// contains filtered or unexported fields
}

Lookup answers the names a screen shows to a person (screens.Lookup): the names of the people and teams and of the masters' rows in the screen's language, and the addresses and the names of the files the person may open. One serves a screen: the A2UI screens and the plain HTML pages alike.

func (*Lookup) FileNames

func (l *Lookup) FileNames(ids []string) (map[string]string, error)

FileNames answers the names the files were given when they were uploaded, of those FileURLs answers an address for: a file the ticket holds, and one the person uploaded. Any other ID gets none, and the screen shows it by its ID.

func (*Lookup) FileURLs

func (l *Lookup) FileURLs(ids []string) (map[string]string, error)

FileURLs answers the addresses the handler serves the files at: a file the ticket holds through the ticket, a file the person uploaded at /files/{id}. Any other ID gets none.

func (*Lookup) MasterNames

func (l *Lookup) MasterNames(lang, master string, keys []string) (map[string]string, error)

MasterNames answers the names of a master's rows that may be chosen today, named by its path (company_masters/vendors): the column the kinds' descriptions name a row by (the master's name_field, ringi's DESIGN 12.2), the same in every language.

func (*Lookup) PeopleNames

func (l *Lookup) PeopleNames(lang string, ids []string) (map[string]string, error)

PeopleNames answers the names of people and teams in the version of the organization in effect today: for ja their name_ja when the data has one, else their name.

type ProxyHeader

type ProxyHeader struct {
	// Secret is what the proxy sends in SecretHeader: at least 32 characters.
	Secret string
	// The headers; by default X-Ringi-Proxy-Secret, X-Ringi-Person and X-Ringi-Roles (the roles
	// separated by commas).
	SecretHeader, PersonHeader, RolesHeader string
}

ProxyHeader is the Authenticator of a server behind a proxy that signs people in: it trusts the proxy's headers naming the person and their roles only on a request that carries Secret, which only the proxy knows and sends, in a header of its own. A request without it, or with another, has no person (401), even when it names one.

The proxy sends each of the three headers once on every request, the roles header too when the person has no role (empty), and takes away the headers of the same names a client sent. A request with two or more of any of them, or with no roles header, has no person: a client's header the proxy added to instead of replacing would otherwise be read for the proxy's.

func (ProxyHeader) Authenticate

func (a ProxyHeader) Authenticate(r *http.Request) (server.Person, error)

Authenticate answers the person the proxy names. With a Secret shorter than MinProxySecret (a server made with New stops before; this is for one that wraps ProxyHeader in an Authenticator of its own), it answers ErrShortSecret and no person.

func (ProxyHeader) Check

func (a ProxyHeader) Check() error

Check reports what is wrong with the configuration, for a server to stop before it takes requests (server.New asks it, as a server.Checker): no Secret, or one shorter than MinProxySecret; a Secret with a character a header does not carry as it is (a space at its ends, a control character, a character past ASCII), which no request would then match; a header name that is not one; two of the three headers named alike. nil when nothing is wrong.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL