router

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

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

Router is the main router struct.

func NewRouter

func NewRouter() *Router

Initialize a new router.

func (*Router) Error

func (r *Router) Error(code int, msg string) rterr.RouterError

Throw an error in the router with a message.

func (*Router) GetRoute

func (r *Router) GetRoute(name string) *routes.Route

Get a route by name. If it does not directly exist, it will search in the subroutes.

func (*Router) HandlePath

func (r *Router) HandlePath(path string)

Handle a path.

func (*Router) Match

func (r *Router) Match(path string) (*routes.Route, vars.Vars, bool)

Match a raw path.

func (*Router) OnError

func (r *Router) OnError(cb func(err error))

Decide what to do on errors.

func (*Router) Redirect

func (r *Router) Redirect(path string)

Handle a path in the form of a redirect. NYI.

func (*Router) RedirectNamed

func (r *Router) RedirectNamed(name string, varMap vars.Vars)

Redirect to a route by name.

func (*Router) Register

func (r *Router) Register(name, path string, callable func(v vars.Vars, u *url.URL)) *routes.Route

Register a new route. If the route name already exists, it will panic.

func (*Router) SkipTrailingSlash

func (r *Router) SkipTrailingSlash()

SkipTrailingSlash will skip the trailing slash in the path.

func (*Router) String

func (r *Router) String() string

Display nicely formatted URLs

func (*Router) Throw

func (r *Router) Throw(code int)

Throw an error in the router with predefined error code messages.

func (*Router) Use

func (r *Router) Use(middleware func(vars.Vars, *url.URL, *routes.Route, rterr.ErrorThrower) bool)

Add a middleware to the router.

type URLs

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

A url map element

func NewURLs

func NewURLs() *URLs

Create a new url map

func (*URLs) Delete

func (u *URLs) Delete(key string)

Delete a url element from the map, and remove it from the DOM

func (*URLs) ForEach

func (u *URLs) ForEach(f func(k string, elem *elements.Element), reverse ...bool)

Loop through all key, value urls in order

func (*URLs) FromElements

func (u *URLs) FromElements(raw bool, elems ...*elements.Element)

Fill up the URLs map from a slice of Elements

func (*URLs) FromMap

func (u *URLs) FromMap(maps ...map[string]interface{})

Generate the urls from a slice of maps Each map has the following attributes:

  • (string) name: the name of the url
  • (string) href: the href of the url
  • (string) text: the text of the url
  • (bool) external: whether the url is external or not
  • (bool) Hide: whether the url is hidden or not
  • ([]string) class: the classes of the url (optional)
  • (string) id: the id of the url (optional)
  • ([]string) style: the style of the url (optional)

func (*URLs) Get

func (u *URLs) Get(key string) *elements.Element

Get a url element from the map

func (*URLs) Hide

func (u *URLs) Hide(urlname ...string)

Set display to none for all urls, or for a list of urls

func (*URLs) InOrder

func (u *URLs) InOrder(reverse ...bool) []*elements.Element

Loop through all urls in order

func (*URLs) Keys

func (u *URLs) Keys() []string

Get the underlying slice of ordered keys

func (*URLs) Len

func (u *URLs) Len() int

Length of the underlying map of URLs

func (*URLs) Map

func (u *URLs) Map() map[string]*elements.Element

Get the underlying map of URLs

func (*URLs) OnClick

func (u *URLs) OnClick(f func(*elements.Element, jsext.Value))

On click action for URLs Takes a function that takes a URL element and the event.target | this

func (*URLs) Set

func (u *URLs) Set(key string, value *elements.Element, external ...bool)

Set a url element in the map

func (*URLs) SetRaw

func (u *URLs) SetRaw(key string, value *elements.Element)

func (*URLs) Show

func (u *URLs) Show(display string, urlname ...string)

Set display to param_display for all urls, or for a list of urls

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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