phx

package module
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 22 Imported by: 0

README ΒΆ

🐦 Phx

A little, highly opinated framework to create complete web apps.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func GetUser ΒΆ added in v0.0.6

func GetUser(req *http.Request) session.User

func ParseForm ΒΆ

func ParseForm(req *http.Request, dst interface{})

ParseForm parses req.Form and then serializes the form data to the dst struct using reflection. The form names should match to the 'html' tag or, if its not setted, to the field name. ParseForm only supports serializing data to one-depth structs. Example, using this struct as target:

type MyStruct struct {
		A bool,
		B int `html:"pagination.currentPage"`
}

And having this serialized form:

"A=false&pagination.currentPage=2"

Calling ParseForm like this (NOTE THAT A POINTER TO THE STRUCT IS BEING PASSED):

var s MyStruct phx.ParseForm(req, &s)

It will result to this fullfilled struct:

{ A = false, B: 2 }

The supported field types are: int, int8, int16, int32, int64, float32, float64, bool and string

func PrintLogo(logoFile string)

PrintLogo takes a file path and prints your fancy ascii logo. It will fail if your file is not found.

func Redirect ΒΆ

func Redirect(to string) func() http.HandlerFunc

Types ΒΆ

type Builder ΒΆ

type Builder interface{}

Builder is a function that expects anything and retuns the type that builds. The type cant be func() interface{} cause some errors appears in runtime. So it's represented as an interface.

type HtmlRenderer ΒΆ

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

func NewHtmlRenderer ΒΆ

func NewHtmlRenderer(files embed.FS, csrf csrf.Csrf, localizer localizer.LocalizerStore) HtmlRenderer

func NewHtmlRendererWithExtraFuncs ΒΆ

func NewHtmlRendererWithExtraFuncs(files embed.FS, csrf csrf.Csrf, localizer localizer.LocalizerStore, extra template.FuncMap) HtmlRenderer

func (HtmlRenderer) CreateView ΒΆ

func (r HtmlRenderer) CreateView(req *http.Request, tmpl *template.Template, model interface{}) View

func (HtmlRenderer) Parse ΒΆ

func (r HtmlRenderer) Parse(patterns ...string) *template.Template

func (HtmlRenderer) ParseAlone ΒΆ

func (r HtmlRenderer) ParseAlone(file string) *template.Template

func (HtmlRenderer) ParsePartial ΒΆ

func (r HtmlRenderer) ParsePartial(defName string, patterns ...string) *template.Template

func (HtmlRenderer) ParseWithShared ΒΆ

func (r HtmlRenderer) ParseWithShared(patterns ...string) *template.Template

type Injector ΒΆ

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

Injector is an automated dependency injector inspired in Sping's DI. It will detect which builder to call using its return type. If the builder haver params, it will fullfill that params calling other builders that provides its types.

func NewInjector ΒΆ

func NewInjector() *Injector

NewInjector with default values

func (Injector) Add ΒΆ

func (injector Injector) Add(builder Builder)

Add a builder to the dependency injector.

func (Injector) CallBuilder ΒΆ

func (injector Injector) CallBuilder(builder Builder) interface{}

CallBuilder injecting all parameters with provided builders. If some parameter type cannot be found, it will panic

func (Injector) Get ΒΆ

func (injector Injector) Get(name interface{}) interface{}

Get returns a builded dependency

func (Injector) GetByType ΒΆ

func (injector Injector) GetByType(name reflect.Type) interface{}

GetByType returns a builded dependency identified by type

func (Injector) PopulateStruct ΒΆ

func (injector Injector) PopulateStruct(userStruct interface{})

PopulateStruct fills a struct with the implementations that the injector can create. Make sure you pass a reference and not a value

func (Injector) ResolveHandler ΒΆ

func (injector Injector) ResolveHandler(builder Builder) http.HandlerFunc

ResolveHandler created by a builder

func (Injector) ShowAvailableBuilders ΒΆ

func (injector Injector) ShowAvailableBuilders()

ShowAvailableBuilders prints all registered builders.

type Middleware ΒΆ

type Middleware func(http.HandlerFunc) http.HandlerFunc

type Mux ΒΆ

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

func NewMux ΒΆ

func NewMux() Mux

func NewMuxEmpty ΒΆ

func NewMuxEmpty() Mux

func NewMuxFrom ΒΆ

func NewMuxFrom(other Mux) Mux

func (*Mux) Add ΒΆ

func (mux *Mux) Add(builder Builder)

func (*Mux) Any ΒΆ

func (mux *Mux) Any(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) Delete ΒΆ

func (mux *Mux) Delete(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) FileServer ΒΆ

func (mux *Mux) FileServer(pattern, root string)

FileServer creates using a router, a url path and a file path a file server.

func (*Mux) FileServerStatic ΒΆ

func (mux *Mux) FileServerStatic(path string)

FileServerStatic creates a file server with your desired path a file server that serves files in ./static folder.

func (*Mux) Get ΒΆ

func (mux *Mux) Get(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) Head ΒΆ

func (mux *Mux) Head(pattern string, builder Builder, middlewares ...Middleware)

func (Mux) ListenAndServe ΒΆ

func (mux Mux) ListenAndServe(address string)

func (*Mux) Mount ΒΆ

func (mux *Mux) Mount(pattern string, inner *Mux)

func (*Mux) Options ΒΆ

func (mux *Mux) Options(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) Patch ΒΆ

func (mux *Mux) Patch(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) PopulateStruct ΒΆ

func (mux *Mux) PopulateStruct(s interface{})

func (*Mux) Post ΒΆ

func (mux *Mux) Post(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) Put ΒΆ

func (mux *Mux) Put(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) ShowAvailableBuilders ΒΆ

func (mux *Mux) ShowAvailableBuilders()

func (*Mux) Trace ΒΆ

func (mux *Mux) Trace(pattern string, builder Builder, middlewares ...Middleware)

func (*Mux) Use ΒΆ

func (mux *Mux) Use(middleware Middleware)

type Render ΒΆ

type Render func(data interface{}, err error)

func NewJsonRenderer ΒΆ

func NewJsonRenderer(w http.ResponseWriter, req *http.Request) Render

type View ΒΆ

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

func (View) Execute ΒΆ

func (view View) Execute(w io.Writer) error

func (*View) FillFormErrors ΒΆ added in v0.0.8

func (view *View) FillFormErrors(e map[string]string)

func (View) RenderLocalized ΒΆ

func (view View) RenderLocalized(w io.Writer, req *http.Request, localizerKey string) error

type ViewModel ΒΆ

type ViewModel struct {
	Model      interface{}
	Localizer  localizer.Localizer
	FormErrors map[string]string
	CsrfToken  string
}

func (ViewModel) GetFormError ΒΆ

func (vm ViewModel) GetFormError(key string) string

func (ViewModel) HaveFormError ΒΆ

func (vm ViewModel) HaveFormError(key string) bool

func (ViewModel) Localize ΒΆ

func (vm ViewModel) Localize(key string) string

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

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