assetserver

package
v3.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Code from https://github.com/erikdubbelboer/ringqueue

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	HeaderHost          = "Host"
	HeaderContentType   = "Content-Type"
	HeaderContentLength = "Content-Length"
	HeaderUserAgent     = "User-Agent"
	// TODO: Is this needed?
	HeaderCacheControl = "Cache-Control"
	HeaderUpgrade      = "Upgrade"

	WailsUserAgentValue = "wails.io"
)

Variables

This section is empty.

Functions

func GetDevServerURL

func GetDevServerURL() string

func GetMimetype

func GetMimetype(filename string, data []byte) string

func GetStartURL

func GetStartURL(userURL string) (string, error)

func NewAssetFileServer

func NewAssetFileServer(vfs fs.FS) http.Handler

func ServeFile

func ServeFile(rw http.ResponseWriter, filename string, blob []byte) error

Types

type AssetServer

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

func NewAssetServer

func NewAssetServer(options *Options) (*AssetServer, error)

func (*AssetServer) AddPluginScript

func (a *AssetServer) AddPluginScript(pluginName string, script string)

func (*AssetServer) LogDetails

func (a *AssetServer) LogDetails()

func (*AssetServer) ServeHTTP

func (a *AssetServer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*AssetServer) ServeWebViewRequest

func (a *AssetServer) ServeWebViewRequest(req webview.Request)

ServeWebViewRequest processes the HTTP Request asynchronously by faking a golang HTTP Server. The request will be finished with a StatusNotImplemented code if no handler has written to the response. The AssetServer takes ownership of the request and the caller mustn't close it or access it in any other way.

type Middleware

type Middleware func(next http.Handler) http.Handler

Middleware defines a HTTP middleware that can be applied to the AssetServer. The handler passed as next is the next handler in the chain. One can decide to call the next handler or implement a specialized handling.

func ChainMiddleware

func ChainMiddleware(middleware ...Middleware) Middleware

ChainMiddleware allows chaining multiple middlewares to one middleware.

type Options

type Options struct {
	// Handler which serves all the content to the WebView.
	Handler http.Handler

	// Middleware is a HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default
	// request handler dynamically, e.g. implement specialized Routing etc.
	// The Middleware is called to build a new `http.Handler` used by the AssetSever and it also receives the default
	// handler used by the AssetServer as an argument.
	//
	// This middleware injects itself before any of Wails internal middlewares.
	//
	// If not defined, the default AssetServer request chain is executed.
	//
	// Multiple Middlewares can be chained together with:
	//   ChainMiddleware(middleware ...Middleware) Middleware
	Middleware Middleware

	// Logger is the logger used by the AssetServer. If not defined, no logging will be done.
	Logger *slog.Logger
}

Options defines the configuration of the AssetServer.

func (Options) Validate

func (o Options) Validate() error

Validate the options

type RuntimeHandler

type RuntimeHandler interface {
	HandleRuntimeCall(w http.ResponseWriter, r *http.Request)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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