Documentation ¶
Index ¶
- Constants
- Variables
- func AppLogger(w logger.Log) func(*Application) error
- func AppSettings(settings Settings) func(*Application) error
- func Apps(apps ...any) func(*Application) error
- func ConfigGet[T any](s Settings, key string, default_ ...T) T
- func ConfigGetOK[T any](s Settings, key string, default_ ...T) (T, bool)
- func Configure(m map[string]interface{}) func(*Application) error
- func Flag(flags ...AppFlag) func(*Application) error
- func GetApp[T AppConfig](name string) T
- func LogRequest(r *http.Request, enabled bool) *http.Request
- func LoggingDisabledMiddleware(next mux.Handler) mux.Handler
- func LoggingEnabled(r *http.Request) bool
- func RequestSignalMiddleware(next mux.Handler) mux.Handler
- type AppConfig
- type AppFlag
- type Application
- func (a *Application) App(name string) AppConfig
- func (a *Application) AppInstalled(name string) bool
- func (a *Application) Config(key string) interface{}
- func (a *Application) Flagged(flag AppFlag) bool
- func (a *Application) Initialize() error
- func (a *Application) Quit() error
- func (a *Application) Register(apps ...any)
- func (a *Application) Reverse(name string, args ...any) string
- func (a *Application) Serve() error
- func (a *Application) ServerError(err error, w http.ResponseWriter, r *http.Request)
- func (a *Application) Static(path string) string
- func (a *Application) Task(description string, fn func(*Application) error) error
- type DjangoHook
- type Mux
- type NosurfSetupHook
- type Option
- type ServerErrorHook
- type Settings
Constants ¶
const ( HOOK_SERVER_ERROR = "django.ServerError" HOOK_SETUP_NOSURF = "django.SetupNosurf" )
const ( APPVAR_DEBUG = "DEBUG" // bool APPVAR_ALLOWED_HOSTS = "ALLOWED_HOSTS" // []string (e.g. ["*"]) APPVAR_RECOVERER = "RECOVERER" // bool (use recoverer middleware) APPVAR_HOST = "HOST" // string APPVAR_PORT = "PORT" // string APPVAR_STATIC_URL = "STATIC_URL" // string APPVAR_TLS_PORT = "TLS_PORT" // string APPVAR_TLS_CERT = "TLS_CERT" // /path/to/cert.pem APPVAR_TLS_KEY = "TLS_KEY" // /path/to/key.pem APPVAR_TLS_CONFIG = "TLS_CONFIG" // *tls.Config APPVAR_DATABASE = "DATABASE" // *sql.DB APPVAR_CONTINUE_AFTER_COMMANDS = "CONTINUE_AFTER_COMMAND" // bool )
const CancelServeError errs.Error = "Serve cancelled, signal hijacked response"
CancelServeError is an error that can be returned from a signal to indicate that the serve should be cancelled.
It can be used to hijack the response and return a custom response.
This signal will be sent before most middleware has been executed.
Variables ¶
var ( Global *Application AppInstalled = Global.AppInstalled Reverse = Global.Reverse Static = Global.Static Task = Global.Task )
var DEFAULT_LOGGING_ENABLED = true
Functions ¶
func AppSettings ¶
func AppSettings(settings Settings) func(*Application) error
func Apps ¶
func Apps(apps ...any) func(*Application) error
func Configure ¶
func Configure(m map[string]interface{}) func(*Application) error
func Flag ¶
func Flag(flags ...AppFlag) func(*Application) error
func LoggingEnabled ¶
func RequestSignalMiddleware ¶
RequestSignalMiddleware is a middleware that sends signals before and after a request is served.
It sends SIGNAL_BEFORE_REQUEST before the request is served and SIGNAL_AFTER_REQUEST after the request is served.
The signal it sends is of type *core.HttpSignal.
This can be used to initialize and / or clean up resources before and after a request is served.
Types ¶
type AppConfig ¶
type AppConfig interface { // The application name. // // This is used to identify the application. // // An application cannot be registered twice - the name MUST be unique. Name() string // Dependencies for the application. // // This can be used to define dependencies for the application. // // All of theses dependencies must be registered before the application is initialized. Dependencies() []string // Commands for the application. // // These commands can be used to run tasks from the command line. // // The commands are registered in the Django command registry. Commands() []command.Command // BuildRouting is used to define the routes for the application. // It can also be used to define middleware for the application. // // A Mux object is passed to the function which can be used to define routes. BuildRouting(mux Mux) // Initialize your application. // // This can be used to retrieve variables / objects from settings (like a database). // // Generally we recommend you use this method for your applications // as opposed to doing stuff in toplevel init(). // // Depending on the order of the registered applications, apps can depend on one- another. // // For example, this is used internally for authentication. // // I.E.: The 'sessions' app must always be registered before 'auth' in order for the auth app to work. Initialize(settings Settings) error Processors() []func(tpl.RequestContext) Templates() *tpl.Config // All apps have been initialized before OnReady() is called. OnReady() error }
AppConfig is the interface that must be implemented by all Django applications.
The AppConfig interface is used to define the structure of a Django application.
It can be used to define routes, middleware, templates, and other options / handlers.
The implementation of this interface can be found in django/apps/apps.go.
type Application ¶
type Application struct { Settings Settings Apps *orderedmap.OrderedMap[string, AppConfig] Mux *mux.Mux Log logger.Log Commands command.Registry // contains filtered or unexported fields }
The global application struct.
This is a singleton object.
It can only be configured once, any calls to the initialization function will return the old instance.
This allows for any registered application to freely call the initializer function to work with the application instance.
The application object should only be initialized once by calling `(*Application).Initialize()`
func App ¶
func App(opts ...Option) *Application
func (*Application) App ¶
func (a *Application) App(name string) AppConfig
func (*Application) AppInstalled ¶
func (a *Application) AppInstalled(name string) bool
func (*Application) Config ¶
func (a *Application) Config(key string) interface{}
Config returns the value of the key from the settings Shortcut for Application.Settings.Get(key)
func (*Application) Flagged ¶
func (a *Application) Flagged(flag AppFlag) bool
func (*Application) Initialize ¶
func (a *Application) Initialize() error
func (*Application) Quit ¶
func (a *Application) Quit() error
func (*Application) Register ¶
func (a *Application) Register(apps ...any)
func (*Application) Serve ¶
func (a *Application) Serve() error
func (*Application) ServerError ¶
func (a *Application) ServerError(err error, w http.ResponseWriter, r *http.Request)
func (*Application) Static ¶
func (a *Application) Static(path string) string
func (*Application) Task ¶
func (a *Application) Task(description string, fn func(*Application) error) error
type DjangoHook ¶
type DjangoHook func(*Application) error
type Mux ¶
type Mux interface { Use(middleware ...mux.Middleware) Handle(method string, path string, handler mux.Handler, name ...string) *mux.Route AddRoute(route *mux.Route) Any(path string, handler mux.Handler, name ...string) *mux.Route Get(path string, handler mux.Handler, name ...string) *mux.Route Post(path string, handler mux.Handler, name ...string) *mux.Route Put(path string, handler mux.Handler, name ...string) *mux.Route Patch(path string, handler mux.Handler, name ...string) *mux.Route Delete(path string, handler mux.Handler, name ...string) *mux.Route }
The interface for our multiplexer
This is a wrapper around the nigel2392/mux.Mux interface
type NosurfSetupHook ¶
type NosurfSetupHook func(app *Application, handler *nosurf.CSRFHandler)
type Option ¶
type Option func(*Application) error
type ServerErrorHook ¶
type ServerErrorHook func(w http.ResponseWriter, r *http.Request, app *Application, err except.ServerError)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
contrib
|
|
admin
templ: version: v0.2.707
|
templ: version: v0.2.707 |
admin/components
templ: version: v0.2.707
|
templ: version: v0.2.707 |
admin/components/menu
templ: version: v0.2.707
|
templ: version: v0.2.707 |
blocks
templ: version: v0.2.707
|
templ: version: v0.2.707 |
editor
templ: version: v0.2.707
|
templ: version: v0.2.707 |
editor/features
templ: version: v0.2.707
|
templ: version: v0.2.707 |
pages
templ: version: v0.2.707
|
templ: version: v0.2.707 |
pagination
templ: version: v0.2.707
|
templ: version: v0.2.707 |
widgets
templ: version: v0.2.707
|
templ: version: v0.2.707 |
list
templ: version: v0.2.707
|
templ: version: v0.2.707 |