pkg

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadTemplateFS

func LoadTemplateFS(_fs fs.FS, baseDir string, patterns ...string) (*template.Template, error)

func NewGinHandlerFromParkaHandlers added in v0.2.4

func NewGinHandlerFromParkaHandlers(
	cmd cmds.GlazeCommand,
	handlers ...ParkaHandlerFunc,
) gin.HandlerFunc

func RenderMarkdownTemplateToHTML

func RenderMarkdownTemplateToHTML(t *template.Template, data interface{}) (string, error)

func RenderMarkdownToHTML

func RenderMarkdownToHTML(rendered string) (string, error)

Types

type EmbedFileSystem

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

EmbedFileSystem is a helper to make an embed FS work as a http.FS, which allows us to serve embed.FS using gin's `Static` middleware.

func NewEmbedFileSystem

func NewEmbedFileSystem(f fs.FS, stripPrefix string) *EmbedFileSystem

func (*EmbedFileSystem) Exists

func (e *EmbedFileSystem) Exists(prefix string, path string) bool

func (*EmbedFileSystem) Open

func (e *EmbedFileSystem) Open(name string) (http.File, error)

type HTMLTemplateHandler added in v0.2.6

type HTMLTemplateHandler struct {
	Template *template.Template
}

HTMLTemplateHandler is a handler that renders a template and also provides affordances to control what input parameters are passed downstream Its main purpose is to be used as a fragment renderer for htmx calls

type JSONMarshaler

type JSONMarshaler interface {
	MarshalJSON() ([]byte, error)
}

type ParameterDefinitionParser added in v0.2.6

type ParameterDefinitionParser func(
	c *gin.Context,
	ps map[string]interface{},
	pds map[string]*parameters.ParameterDefinition,
) (map[string]*parameters.ParameterDefinition, error)

ParameterDefinitionParser can be used to intercept parsing certain values. If a parameter shouldn't be handled by a follow up step, return a new hashmap with the key deleted

func NewStaticLayerParameterDefinitionParser added in v0.2.6

func NewStaticLayerParameterDefinitionParser(l layers.ParameterLayer) ParameterDefinitionParser

func NewStaticParameterDefinitionParser added in v0.2.6

func NewStaticParameterDefinitionParser(ps map[string]interface{}) ParameterDefinitionParser

type ParkaContext added in v0.2.4

type ParkaContext struct {
	// Cmd is the command that will be executed
	Cmd cmds.GlazeCommand
	// ParsedLayers contains the map of parsed layers parsed so far
	ParsedLayers map[string]*layers.ParsedParameterLayer
	// ParsedParameters contains the map of parsed parameters parsed so far
	ParsedParameters map[string]interface{}
}

ParkaContext keeps the context for execution of a parka command, and can be worked upon by ParkaHandlerFuncs.

func NewParkaContext added in v0.2.4

func NewParkaContext(cmd cmds.GlazeCommand) *ParkaContext

type ParkaHandlerFunc added in v0.2.4

type ParkaHandlerFunc func(*gin.Context, *ParkaContext) error

func HandlePrepopulatedParameters added in v0.2.4

func HandlePrepopulatedParameters(ps map[string]interface{}) ParkaHandlerFunc

func HandlePrepopulatedParsedLayers added in v0.2.4

func HandlePrepopulatedParsedLayers(layers_ map[string]*layers.ParsedParameterLayer) ParkaHandlerFunc

func WithCommandParser added in v0.2.6

func WithCommandParser(cmd cmds.GlazeCommand, parserHandler *ParserHandler) ParkaHandlerFunc

type ParserHandler added in v0.2.6

type ParserHandler struct {
	ParameterDefinitionParsers  []ParameterDefinitionParser
	ParameterLayerParsersBySlug map[string][]ParameterDefinitionParser
}

func NewFormParserHandler added in v0.2.6

func NewFormParserHandler(cmd cmds.GlazeCommand, options ...ParserHandlerOption) *ParserHandler

func NewParserHandler added in v0.2.6

func NewParserHandler(options ...ParserHandlerOption) *ParserHandler

func NewQueryParserHandler added in v0.2.6

func NewQueryParserHandler(cmd cmds.GlazeCommand, options ...ParserHandlerOption) *ParserHandler

type ParserHandlerOption added in v0.2.6

type ParserHandlerOption func(*ParserHandler)

func WithCustomizedParameterLayerParser added in v0.2.6

func WithCustomizedParameterLayerParser(l layers.ParameterLayer, overrides map[string]interface{}) ParserHandlerOption

func WithGlazeOutputParserOption added in v0.2.6

func WithGlazeOutputParserOption(gl *cli.GlazedParameterLayers, output string, tableFormat string) ParserHandlerOption

func WithPostParameterDefinitionParser added in v0.2.6

func WithPostParameterDefinitionParser(ps ...ParameterDefinitionParser) ParserHandlerOption

func WithPostParameterLayerParser added in v0.2.6

func WithPostParameterLayerParser(slug string, ps ...ParameterDefinitionParser) ParserHandlerOption

func WithPreParameterDefinitionParsers added in v0.2.6

func WithPreParameterDefinitionParsers(ps ...ParameterDefinitionParser) ParserHandlerOption

func WithPreParameterLayerParser added in v0.2.6

func WithPreParameterLayerParser(slug string, ps ...ParameterDefinitionParser) ParserHandlerOption

func WithReplaceParameterDefinitionParser added in v0.2.6

func WithReplaceParameterDefinitionParser(ps ...ParameterDefinitionParser) ParserHandlerOption

func WithReplaceParameterLayerParser added in v0.2.6

func WithReplaceParameterLayerParser(slug string, ps ...ParameterDefinitionParser) ParserHandlerOption

type Server

type Server struct {
	Router *gin.Engine

	StaticPaths     []StaticPath
	TemplateLookups []TemplateLookup

	Port    uint16
	Address string
}

func NewServer

func NewServer(options ...ServerOption) (*Server, error)

func (*Server) HandleSimpleFormCommand added in v0.2.4

func (s *Server) HandleSimpleFormCommand(
	cmd cmds.GlazeCommand,
	handlers ...ParkaHandlerFunc,
) gin.HandlerFunc

func (*Server) HandleSimpleQueryCommand added in v0.2.4

func (s *Server) HandleSimpleQueryCommand(
	cmd cmds.GlazeCommand,
	parserOptions []ParserHandlerOption,
	handlers ...ParkaHandlerFunc,
) gin.HandlerFunc

func (*Server) LookupTemplate

func (s *Server) LookupTemplate(name ...string) (*template.Template, error)

LookupTemplate will iterate through the template lookups until it finds one of the templates given in name.

func (*Server) Run

func (s *Server) Run() error

type ServerOption

type ServerOption = func(*Server)

func WithAddress added in v0.2.6

func WithAddress(address string) ServerOption

func WithAppendTemplateLookups added in v0.2.6

func WithAppendTemplateLookups(lookups ...TemplateLookup) ServerOption

func WithPort added in v0.2.6

func WithPort(port uint16) ServerOption

func WithPrependTemplateLookups added in v0.2.6

func WithPrependTemplateLookups(lookups ...TemplateLookup) ServerOption

func WithReplaceTemplateLookups added in v0.2.6

func WithReplaceTemplateLookups(lookups ...TemplateLookup) ServerOption

func WithStaticPaths

func WithStaticPaths(paths ...StaticPath) ServerOption

type StaticPath

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

func NewStaticPath

func NewStaticPath(fs http.FileSystem, urlPath string) StaticPath

type TemplateLookup

type TemplateLookup func(name ...string) (*template.Template, error)

func LookupTemplateFromDirectory

func LookupTemplateFromDirectory(dir string) TemplateLookup

LookupTemplateFromDirectory will load a template at runtime. This is useful for testing local changes to templates without having to recompile the app.

func LookupTemplateFromFS

func LookupTemplateFromFS(_fs fs.FS, baseDir string, patterns ...string) (TemplateLookup, error)

Jump to

Keyboard shortcuts

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