app

package
v0.0.0-...-3a60eae Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAbsolutePath

func GetAbsolutePath(dir string) (string, error)

getAbsolutePath returns the absolute path to dir. If the dir is relative, then we add the current working directory. Checks are made to ensure the directory exist. In case of any error, an empty string is returned.

func StaticServer

func StaticServer(cfg *config.Config) (string, bool, http.Handler)

StaticServer implements StaticServerFunc.

This uses the http.Filesystem to handle static assets. The routes prefixed with /static/ are static asset routes by default.

Types

type App

type App struct {
	Router       *router.Router
	Config       *config.Config
	View         view.View
	Log          logger.Logger
	Model        *models.Model
	ConfigPath   string
	StaticServer StaticServerFunc
	SessionStore sessions.Store
	// contains filtered or unexported fields
}

App is the main utron application.

func NewApp

func NewApp() *App

NewApp creates a new bare-bone utron application. To use the MVC components, you should call the Init method before serving requests.

func NewMVC

func NewMVC(cfg ...string) (*App, error)

NewMVC creates a new MVC utron app. If cfg is passed, it should be a directory to look for the configuration files. The App returned is initialized.

func (*App) AddController

func (a *App) AddController(ctrlfn func() controller.Controller, middlewares ...interface{})

AddController registers a controller, and middlewares if any is provided.

func (*App) Init

func (a *App) Init() error

Init initializes the MVC App.

func (*App) LoadConfig

func (a *App) LoadConfig() error

func (*App) ServeHTTP

func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves http requests. It can be used with other http.Handler implementations.

func (*App) SetConfigPath

func (a *App) SetConfigPath(dir string)

SetConfigPath sets the directory path to search for the config files.

func (*App) SetNotFoundHandler

func (a *App) SetNotFoundHandler(h http.Handler) error

SetNotFoundHandler this sets the hadler that is will execute when the route is not found.

func (*App) SetView

func (a *App) SetView(vw view.View)

type StaticServerFunc

type StaticServerFunc func(*config.Config) (prefix string, strip bool, h http.Handler)

StaticServerFunc is a function that returns the static assetsfiles server.

The first argument retrued is the path prefix for the static assets. If strp is set to true then the prefix is going to be stripped.

Jump to

Keyboard shortcuts

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