| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This package is not in the latest version of its module.
Go to latest Published: Sep 27, 2023 License: Apache-2.0The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Modules with tagged versions give importers more predictable builds.
When a project reaches major version v1 it is considered stable.
This section is empty.
This section is empty.
This section is empty.
type ActionCtx struct {
Writer http.ResponseWriter
Request *http.Request
State json.RawMessage
Args json.RawMessage
}
ActionCtx is the context that is passed to an ActionFunc. It extends the Request and Writer from a typical HTTP request handler with State and Args fields from the Action call that were sent from the browser.
ActionFunc is the action handler function that should return an Update in response to the call from the client. ActionFuncs are registered with the Server using the AddAction() function.
Page gets returned from a PageFunc. The page needs to be able to write the HTML representation of the page to an io.Writer. It can be extended into an UpdateablePage by implementing Update().
type PageCtx struct {
Writer http.ResponseWriter
Request *http.Request
Params httprouter.Params // params from placeholders in the URL
}
PageCtx is the context that is passed to a PageFunc. It extends the Request and Writer from a typical HTTP request handler with Params from the HTTP router.
For more info on httrouter.Params see: https://github.com/julienschmidt/httprouter
PageFunc is the page handler function that should return a Page value in response to a HTTP request or guiapi page request. PageFuncs are registered with the using the AddPage() function.
type Server struct {
// contains filtered or unexported fields
}
Server contains all the registered Pages, Actions, Files and Streams. It implements the http.Handler interface, so it can be directly passed to a function like http.ListenAndServe(). When a request comes in, the server will handle GET requests for pages, POST requests for actions, and WebSocket requests for streams.
func New() *Server
New returns a new guiapi Server. After registering all the Pages, Actions, Files and Streams, the server can be directly used as a http.Handler.
func (s *Server) AddAction(name string, fn ActionFunc)
AddAction registers an ActionFunc with the passed name and handler function on the server.
func (s *Server) AddFiles(baseURL string, fs http.FileSystem)
AddFiles registers a http.FileSystem with the passed baseURL on the server. The files can also be in a subdirectory of the baseURL. This function is the main way of serving static files from the guiapi server.
AddPage registers a PageFunc with the passed path and page handler function on the server. The URL path can contain placeholders in the form of :name, which then get passed as Params in a PageCtx.
See https://github.com/julienschmidt/httprouter for more info.
func (s *Server) AddStream(name string, fn StreamFunc)
AddStream registers a StreamFunc with the passed name and handler function on the server.
func (s *Server) Router() *httprouter.Router
Router returns the underlying HTTP router. This way any additional endpoints can be added to the HTTP server, bypassing guiapi.
See https://github.com/julienschmidt/httprouter for more info.
StreamFunc is the type of a stream handler function. The initial arguments from the client side are passed as JSON in args. Any time an update is ready to be sent, it needs to be sent to the res channel. The stream can be closed by returning from the function. If the client side closes the connection, the context will be canceled. Because of this it is important to check ctx.Done() regularly.
type Update struct {
Name string `json:",omitempty"` // Name of the action that was called
URL string `json:",omitempty"` // URL that was loaded
Error *api.Error `json:",omitempty"` // Error that occurred while handling the action
HTML []api.HTMLUpdate `json:",omitempty"` // DOM updates to apply
JS []api.JSCall `json:",omitempty"` // JS calls to execute
State any `json:",omitempty"` // State to pass back to the browser
Stream []api.Stream `json:",omitempty"` // Stream to subscribe to via websocket
}
Update is the returned body of a GUI API call.
InsertAfter returns a new Update that inserts HTML content on the same level after the passed selector. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
InsertBefore returns a new Update that inserts HTML content on the same level before the passed selector. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
JSCall returns a new Update that will call the registered JavaScript function that is identified by the name, and will pass the arguments.
ReplaceContent returns a new Update that replaces the content of the element that gets selected by the passed selector with the HTML content. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
ReplaceElement returns a new Update that replaces the whole element that gets selected by the passed selector with the HTML content. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
Stream returns a new Update that will connect to a stream with the passed name and arguments.
AddInsertAfter adds a HTML update that inserts HTML content on the same level after the passed selector. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
AddInsertBefore adds a HTML update that inserts HTML content on the same level before the passed selector. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
AddJSCall adds a new JSCall Update that will call the registered JavaScript function that is identified by the name, and will pass the arguments.
AddReplaceContent adds a new HTML Update that replaces the content of the element that gets selected by the passed selector with the HTML content. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
AddReplaceElement adds a HTML Update that replaces the whole element that gets selected by the passed selector with the HTML content. The selector gets passed to document.querySelector, so it can be any valid CSS selector.
UpdateablePage is a Page that can also produce a relative Update. This means that the browser can just update the relevant parts of the page and doesn't have to reload the whole page.
| Back | FazBrowse Home | New Git URL |