github.com/secoba/wails/v2@v2.6.4/pkg/options/assetserver/options.go (about)

     1  package assetserver
     2  
     3  import (
     4  	"fmt"
     5  	"io/fs"
     6  	"net/http"
     7  )
     8  
     9  // Options defines the configuration of the AssetServer.
    10  type Options struct {
    11  	// Assets defines the static assets to be used. A GET request is first tried to be served from this Assets. If the Assets returns
    12  	// `os.ErrNotExist` for that file, the request handling will fallback to the Handler and tries to serve the GET
    13  	// request from it.
    14  	//
    15  	// If set to nil, all GET requests will be forwarded to Handler.
    16  	Assets fs.FS
    17  
    18  	// Handler will be called for every GET request that can't be served from Assets, due to `os.ErrNotExist`. Furthermore all
    19  	// non GET requests will always be served from this Handler.
    20  	//
    21  	// If not defined, the result is the following in cases where the Handler would have been called:
    22  	//   GET request:   `http.StatusNotFound`
    23  	//   Other request: `http.StatusMethodNotAllowed`
    24  	Handler http.Handler
    25  
    26  	// Middleware is a HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default
    27  	// request handler dynamically, e.g. implement specialized Routing etc.
    28  	// The Middleware is called to build a new `http.Handler` used by the AssetSever and it also receives the default
    29  	// handler used by the AssetServer as an argument.
    30  	//
    31  	// If not defined, the default AssetServer request chain is executed.
    32  	//
    33  	// Multiple Middlewares can be chained together with:
    34  	//   ChainMiddleware(middleware ...Middleware) Middleware
    35  	Middleware Middleware
    36  }
    37  
    38  // Validate the options
    39  func (o Options) Validate() error {
    40  	if o.Assets == nil && o.Handler == nil && o.Middleware == nil {
    41  		return fmt.Errorf("AssetServer options invalid: either Assets, Handler or Middleware must be set")
    42  	}
    43  
    44  	return nil
    45  }