concept

package module
v0.0.0-...-fd78fd2 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ApplicationComponent is the kind of an application providing HTTP endpoints.
	ApplicationComponent = iota
	// ExtensionComponent is the kind of an extension installing hooks into applications and the system.
	ExtensionComponent = iota
)

Variables

View Source
var Errors = map[int]string{
	404: "gitlab.com/alexbuzzbee/concept.Error404",
	500: "gitlab.com/alexbuzzbee/concept.Error500",
}

Errors contains the server's built-in error pages.

Functions

func AddHook

func AddHook(name string, f HookFunc) error

AddHook adds a new function to a hook.

func CallHook

func CallHook(name string, param interface{}) (returns []interface{}, err error)

CallHook invokes all the functions in a hook, returning a slice of their return values.

func CreateEndpoint

func CreateEndpoint(path string, handler EndpointHandler) error

CreateEndpoint creates and sets up an endpoint.

func CreateLayout

func CreateLayout(name string, tmpl template.Template, parent string)

CreateLayout creates and registers a layout. A layout's name should be a fully-qualified Go package name (e.g. gitlab.com/alexbuzzbee/concept-admin) followed by a period and the unqualified name (e.g. ConfigPage).

func GetConf

func GetConf(key string, def interface{}) (value interface{}, err error)

GetConf reads a configuration key. Returns def (default) if value not found.

func Load

func Load(name string) (err error)

Load loads a Concept plugin and installs its components.

func NewHook

func NewHook(name string) error

NewHook creates a new hook. The name should be in the format Plugin.Component.name.

func Render

func Render(layout, content, title, tags, author, desc string, extra map[string]interface{}) (result string, err error)

Render renders a page using a layout with a title, author, description, some tags, and optionally extra data.

func RunLayout

func RunLayout(name string, content template.HTML, context map[string]interface{}) (result string, err error)

RunLayout executes a layout, wrapping it in its parent layout(s), if any.

func Serve

func Serve(address string) error

Serve starts an HTTP server providing access to registered endpoints.

Types

type Component

type Component struct {
	// The name identifies the component. It should be a fully-qualified Go package name (e.g. gitlab.com/alexbuzzbee/concept-admin) followed by a period and the unqualified name (e.g. App).
	Name     string
	Kind     ComponentKind
	Exported []interface{}
}

A Component provides new functionality to Concept.

type ComponentKind

type ComponentKind int

ComponentKind indicates the type of a component.

type Endpoint

type Endpoint struct {
	// The Path is the endpoint's path; it may contain wildcards.
	Path    string
	Handler EndpointHandler
}

An Endpoint is an actual endpoint.

type EndpointHandler

type EndpointHandler func(path string, params map[string][]string) (content string, extra ResponseData, err error)

An EndpointHandler is a function that handles endpoints.

type ExtensionHook

type ExtensionHook struct {
	Name string
	F    HookFunc
}

An ExtensionHook is a hook exported by an extension.

type HookFunc

type HookFunc func(param interface{}) interface{}

A HookFunc is a function that can be put into a hook.

type ResponseData

type ResponseData struct {
	ResponseCode     int
	RedirectLocation string
}

A ResponseData contains extra information about a dispatch result besides its content and/or error.

func DispatchEndpoint

func DispatchEndpoint(requestedPath string, params map[string][]string) (content string, extra ResponseData, err error)

DispatchEndpoint calls the correct endpoint handler for the specified path.

func DispatchError

func DispatchError(path string, code int, err error) (content string, extra ResponseData, _err error)

DispatchError renders an error page.

Directories

Path Synopsis
A plugin for Concept that provides a basic demonstration application.
A plugin for Concept that provides a basic demonstration application.

Jump to

Keyboard shortcuts

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