provider

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2016 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const SecretReplacement = "********"

SecretReplacement is a constant used to replace secrets in data-structures when required. 8 stars.

Variables

View Source
var ErrNoSecrets = errors.New("no secrets in database")

ErrNoSecrets is returned if no secret is found in the database.

Functions

func Callback

func Callback(section string, w http.ResponseWriter, r *http.Request) error

Callback passes parameters to the given section callback, the returned error indicates success.

func Command

func Command(section string, ctx *Context, w http.ResponseWriter, r *http.Request) bool

Command passes parameters to the given section id, the returned bool indicates success.

func List

func List() map[string]Provider

List returns available types

func Refresh

func Refresh(section string, ctx *Context, config, data string) (string, bool)

Refresh returns the latest data for a section.

func Register

func Register(name string, p Provider)

Register makes document section type available

func Render

func Render(section string, ctx *Context, config, data string) (string, bool)

Render runs that operation for the given section id, the returned bool indicates success.

func WriteEmpty

func WriteEmpty(w http.ResponseWriter)

WriteEmpty returns just OK to HTTP response.

func WriteError

func WriteError(w http.ResponseWriter, section string, err error)

WriteError write given error to HTTP response.

func WriteForbidden

func WriteForbidden(w http.ResponseWriter)

WriteForbidden write 403 to HTTP response.

func WriteJSON

func WriteJSON(w http.ResponseWriter, v interface{})

WriteJSON writes data as JSON to HTTP response.

func WriteMarshalError

func WriteMarshalError(w http.ResponseWriter, err error)

WriteMarshalError write JSON marshalling error to HTTP response.

func WriteMessage

func WriteMessage(w http.ResponseWriter, section, msg string)

WriteMessage write string to HTTP response.

func WriteString

func WriteString(w http.ResponseWriter, data string)

WriteString writes string tp HTTP response.

Types

type Context

type Context struct {
	OrgID  string
	UserID string
	// contains filtered or unexported fields
}

Context describes the environment the section code runs in

func NewContext

func NewContext(orgid, userid string) *Context

NewContext is a convenience function.

func (*Context) GetSecrets

func (c *Context) GetSecrets(JSONpath string) string

GetSecrets for the current context user/org. For example (see SaveSecrets example): thisContext.GetSecrets("mysecret") JSONpath format is defined at https://dev.mysql.com/doc/refman/5.7/en/json-path-syntax.html . An empty JSONpath returns the whole JSON object, as JSON. Errors return the empty string.

func (*Context) MarshalSecrets

func (c *Context) MarshalSecrets(sec interface{}) error

MarshalSecrets to the database. Parameter the same as for json.Marshal().

func (*Context) SaveSecrets

func (c *Context) SaveSecrets(JSONobj string) error

SaveSecrets for the current user/org combination. The secrets must be in the form of a JSON format string, for example `{"mysecret":"lover"}`. An empty string signifies no valid secrets for this user/org combination. Note that this function can only be called within the Command method of a section.

func (*Context) UnmarshalSecrets

func (c *Context) UnmarshalSecrets(v interface{}) error

UnmarshalSecrets from the database. Parameter the same as for "v" in json.Unmarshal().

type Provider

type Provider interface {
	Meta() TypeMeta                                               // Meta returns section details
	Command(ctx *Context, w http.ResponseWriter, r *http.Request) // Command is general-purpose method that can return data to UI
	Render(ctx *Context, config, data string) string              // Render converts section data into presentable HTML
	Refresh(ctx *Context, config, data string) string             // Refresh returns latest data
}

Provider represents a 'page' in a document.

type TypeMeta

type TypeMeta struct {
	ID          string                                         `json:"id"`
	Order       int                                            `json:"order"`
	ContentType string                                         `json:"contentType"`
	Title       string                                         `json:"title"`
	Description string                                         `json:"description"`
	Preview     bool                                           `json:"preview"` // coming soon!
	Callback    func(http.ResponseWriter, *http.Request) error `json:"-"`
}

TypeMeta details a "smart section" that represents a "page" in a document.

func GetSectionMeta

func GetSectionMeta() []TypeMeta

GetSectionMeta returns a list of smart sections.

func (*TypeMeta) ConfigHandle

func (t *TypeMeta) ConfigHandle() string

ConfigHandle returns the key name for database config table

Jump to

Keyboard shortcuts

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