web

package
v1.832.8 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

Getting Started with Create React App

This project was bootstrapped with Create React App.

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

The page will reload when you make changes.
You may also see any lint errors in the console.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

npm run eject

Note: this is a one-way operation. Once you eject, you can't go back!

If you aren't satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

You don't have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

Learn More

You can learn more in the Create React App documentation.

To learn React, check out the React documentation.

Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

npm run build fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

Documentation

Index

Constants

View Source
const (
	BeforeStatic = iota
	BeforeRouter
	BeforeExec
	AfterExec
	FinishRouter
)

Filter positions, ordered as they run around a request.

View Source
const ModeProd = "prod"

ModeProd is the run mode under which ServeJSON omits indentation.

Variables

View Source
var ErrAbort = errors.New("web: stop run")

ErrAbort is the panic value StopRun raises to unwind a handler; the router recovers it and stops running the request without treating it as a crash.

View Source
var RunMode = ModeProd

RunMode selects response formatting: any value other than ModeProd pretty-prints ServeJSON output. It defaults to ModeProd (compact), matching the runtime default; the serving layer sets it from config when configured.

Functions

This section is empty.

Types

type Context

type Context struct {
	Input          *Input
	Output         *Output
	Request        *http.Request
	ResponseWriter *Response
}

Context carries one request's reader and writer: the Input for request data, the Output for the response, and the raw Request plus the wrapped ResponseWriter.

func NewContext

func NewContext() *Context

NewContext returns a Context with an initialized Input and Output.

func (*Context) Redirect

func (ctx *Context) Redirect(status int, localurl string)

Redirect writes an HTTP redirect to localurl with the given status.

func (*Context) Reset

func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)

Reset rebinds the Context to a request/response pair and clears the per-request state on the Input, Output and ResponseWriter.

func (*Context) SetCookie added in v1.822.2

func (ctx *Context) SetCookie(name, value string, others ...interface{})

SetCookie adds a Set-Cookie response header. See Output.Cookie for the positional option contract.

type Controller

type Controller struct {
	Ctx        *Context
	Data       map[interface{}]interface{}
	CruSession Store

	// EnableRender is retained for handler compatibility. Handlers write their
	// own responses (ServeJSON, Output.Body), so the router renders nothing;
	// toggling this flag has no effect on the response.
	EnableRender bool

	AppController interface{}
	// contains filtered or unexported fields
}

Controller is the base a request handler embeds. It holds the request Context, the response Data bag and the session store.

func (*Controller) DelSession

func (c *Controller) DelSession(name interface{})

DelSession deletes a session value.

func (*Controller) Finish

func (c *Controller) Finish()

Finish runs after the handler. The base does nothing; a controller may override it.

func (*Controller) GetFile added in v1.822.2

func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

GetFile returns the uploaded multipart file for a form key.

func (*Controller) GetSession

func (c *Controller) GetSession(name interface{}) interface{}

GetSession returns a session value, or nil when no session is bound.

func (*Controller) GetString

func (c *Controller) GetString(key string, def ...string) string

GetString returns a route parameter or form value for key, or the optional default when unset.

func (*Controller) Init

func (c *Controller) Init(ctx *Context, controllerName, actionName string, app interface{})

Init binds the controller to a request. Data aliases the Input's per-request map, so values set through Ctx.Input.SetData and c.Data are the same map.

func (*Controller) Input

func (c *Controller) Input() url.Values

Input parses and returns the request form values (query plus body form).

func (*Controller) Prepare

func (c *Controller) Prepare()

Prepare runs before the handler. The base does nothing; a controller may override it.

func (*Controller) ServeJSON

func (c *Controller) ServeJSON(encoding ...bool)

ServeJSON writes c.Data["json"] as the JSON response body, indented unless the run mode is prod. Passing true escapes non-ASCII runes.

func (*Controller) SetSession

func (c *Controller) SetSession(name interface{}, value interface{})

SetSession stores a session value.

func (*Controller) StartSession

func (c *Controller) StartSession() Store

StartSession binds the request session store, taking it from the Input on first use, and returns it.

func (*Controller) StopRun

func (c *Controller) StopRun()

StopRun unwinds the current handler via a recovered panic.

type ControllerInterface

type ControllerInterface interface {
	Init(ctx *Context, controllerName, actionName string, app interface{})
	Prepare()
	Finish()
}

ControllerInterface is the contract the router drives per request: build the controller with Init, run Prepare before the handler and Finish after.

type FilterFunc

type FilterFunc func(*Context)

FilterFunc runs against a request context at a filter position.

type Input

type Input struct {
	Context    *Context
	CruSession Store

	RequestBody []byte
	// contains filtered or unexported fields
}

Input reads the request line, headers, route parameters, per-request data and the cached body for one request.

func NewInput

func NewInput() *Input

NewInput returns an empty Input.

func (*Input) CopyBody

func (input *Input) CopyBody(maxMemory int64) []byte

CopyBody reads the request body once (up to maxMemory, transparently gunzipping a gzip-encoded body), caches it on RequestBody, and rewinds Request.Body from the cache so later readers see the same bytes.

func (*Input) Data

func (input *Input) Data() map[interface{}]interface{}

Data returns the per-request data map, allocating it on first use.

func (*Input) GetData

func (input *Input) GetData(key interface{}) interface{}

GetData returns a per-request value, or nil when the key is unset.

func (*Input) Header

func (input *Input) Header(key string) string

Header returns a request header value.

func (*Input) Method

func (input *Input) Method() string

Method returns the request method.

func (*Input) Param

func (input *Input) Param(key string) string

Param returns the value of a route parameter, or "" when absent.

func (*Input) Params

func (input *Input) Params() map[string]string

Params returns all route parameters as a name-to-value map.

func (*Input) Query

func (input *Input) Query(key string) string

Query returns a route parameter of the key, or the parsed form/query value when no such parameter exists.

func (*Input) Reset

func (input *Input) Reset(ctx *Context)

Reset rebinds the Input to a context and clears per-request state.

func (*Input) Scheme

func (input *Input) Scheme() string

Scheme returns the request scheme, preferring the X-Forwarded-Proto header, then the URL scheme, then "https" when the connection is TLS, else "http".

func (*Input) Session

func (input *Input) Session(key interface{}) interface{}

Session returns a session value for key, or nil when no session is bound. A missing store yields nil rather than a panic, so an unauthenticated request resolves to "no session value" and falls through to credential auth.

func (*Input) SetData

func (input *Input) SetData(key, val interface{})

SetData stores a per-request value.

func (*Input) SetParam

func (input *Input) SetParam(key, val string)

SetParam sets a route parameter, replacing any existing value for the key.

func (*Input) URL

func (input *Input) URL() string

URL returns the request path without query string or fragment.

type MemorySessions added in v1.823.0

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

MemorySessions is a cookie-keyed, in-memory session manager. It backs the cookie web-admin flow (API requests authenticate per-request via bearer credentials, not sessions). Single-process by design, matching the single-replica runtime.

var Sessions *MemorySessions

Sessions is the process session manager. The runtime sets it and binds it to the router; the logout path reaches it for SessionDestroy.

func NewMemorySessions added in v1.823.0

func NewMemorySessions(cookieName string, maxAge time.Duration) *MemorySessions

NewMemorySessions builds a session manager for a cookie name and lifetime and starts its expiry sweep.

func (*MemorySessions) SessionDestroy added in v1.823.0

func (m *MemorySessions) SessionDestroy(id string) error

SessionDestroy removes a session by id (the logout path).

func (*MemorySessions) SessionStart added in v1.823.0

func (m *MemorySessions) SessionStart(w http.ResponseWriter, r *http.Request) (Store, error)

SessionStart returns the session named by the request cookie, or creates a new one and sets the cookie on the response.

type Output

type Output struct {
	Context *Context
	Status  int
}

Output writes the response status, headers and body. Response compression is handled at the edge (the cloud/gateway serving layer), so Output writes bodies uncompressed.

func (*Output) Body

func (output *Output) Body(content []byte) error

Body writes content as the response body. It sets Content-Length, sends a status set earlier via SetStatus (then clears it so a second write cannot emit a duplicate status line), and writes the bytes.

func (*Output) Cookie added in v1.822.2

func (output *Output) Cookie(name, value string, others ...interface{})

Cookie adds a Set-Cookie response header. The optional args are positional, in order: max-age (int seconds; negative deletes), path (string, default "/"), domain (string), secure (bool) and http-only (bool).

func (*Output) Header

func (output *Output) Header(key, val string)

Header sets a response header.

func (*Output) JSON

func (output *Output) JSON(data interface{}, hasIndent bool, encoding bool) error

JSON writes data as a JSON body. hasIndent pretty-prints; encoding escapes non-ASCII runes to \uXXXX. A marshal error becomes a 500.

func (*Output) Reset

func (output *Output) Reset(ctx *Context)

Reset rebinds the Output to a context and clears the pending status.

func (*Output) SetStatus

func (output *Output) SetStatus(status int)

SetStatus records the status to send with the next Body write. It does not write the header immediately.

type Response

type Response struct {
	http.ResponseWriter
	Started bool
	Status  int
}

Response wraps http.ResponseWriter and records whether the reply has begun (Started) and the status written (Status). It passes Flush, Hijack, CloseNotify and Pusher through to the underlying writer so streaming and server-sent-event handlers keep working.

func (*Response) Flush

func (r *Response) Flush()

Flush forwards to the underlying writer when it is an http.Flusher, so streaming responses can push buffered bytes.

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack forwards to the underlying writer when it is an http.Hijacker.

func (*Response) Pusher

func (r *Response) Pusher() http.Pusher

Pusher forwards to the underlying writer when it is an http.Pusher.

func (*Response) Write

func (r *Response) Write(p []byte) (int, error)

Write sends body bytes and marks the reply as started.

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

WriteHeader sends the status line once; a second call is ignored so the handler chain cannot emit two WriteHeader calls.

type Router

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

Router registers controllers and filters and serves requests: it builds a per-request Context, runs the filter chain around a reflection-dispatched controller method, and is itself an http.Handler.

func NewRouter

func NewRouter() *Router

NewRouter returns an empty Router.

func (*Router) InsertFilter

func (p *Router) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error

InsertFilter adds a filter at a position for a URL pattern. The optional first bool is returnOnOutput (default true): a true filter that writes the response short-circuits the chain.

func (*Router) Patterns added in v1.831.12

func (p *Router) Patterns() map[string][]string

Patterns returns every registered route pattern, in registration order, with its methods — e.g. "/v1/ai/stores" -> ["GET","POST"].

Exported so a caller can assert things ABOUT its own route table that the table cannot see from the inside: most usefully, that a generated route never lands on a pattern a hand-written one already claimed. Two registrations of one pattern do not error here — the more specific, or the earlier, simply wins — so without a check like that the loser is silently unreachable.

func (*Router) Router

func (p *Router) Router(pattern string, c ControllerInterface, mapping string)

Router registers a controller for a URL pattern with a method mapping such as "GET:List;POST:Create". The controller value supplies the type that is freshly instantiated per request.

func (*Router) ServeHTTP

func (p *Router) ServeHTTP(rw http.ResponseWriter, r *http.Request)

ServeHTTP builds the request context, caches the body, runs the filter chain around the matched controller method, and recovers a StopRun abort or a handler panic.

func (*Router) UseSessions added in v1.822.2

func (p *Router) UseSessions(m SessionManager)

UseSessions binds a session manager. When set, ServeHTTP starts a session before the filter chain (so the auth filters and controllers read it) and releases it after the response.

type SessionManager added in v1.822.2

type SessionManager interface {
	SessionStart(w http.ResponseWriter, r *http.Request) (Store, error)
}

SessionManager starts the session store for a request. A provider that matches this shape (the session provider does) binds per-request sessions without the router depending on the provider.

type Store

type Store interface {
	Set(key, value interface{}) error
	Get(key interface{}) interface{}
	Delete(key interface{}) error
	SessionID() string
	SessionRelease(w http.ResponseWriter)
	Flush() error
}

Store is the per-request session store bound to Input.CruSession. Its shape is the session-provider contract, so a provider satisfies it unchanged.

Jump to

Keyboard shortcuts

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