pkg

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

NewEmbedFileSystem will create a new EmbedFileSystem that will serve the given embed.FS under the given URL path. stripPrefix will be added to the beginning of all paths when looking up files in the embed.FS.

func (*EmbedFileSystem) Exists

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

Exists will check if the given path exists in the embed.FS. The path will be prefixed with the stripPrefix that was given when creating the EmbedFileSystem, while prefix will be removed from the path.

func (*EmbedFileSystem) Open

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

Open will open the file with the given name from the embed.FS. The name will be prefixed with the stripPrefix that was given when creating the EmbedFileSystem.

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 Server

type Server struct {
	Router *gin.Engine

	StaticPaths     []StaticPath
	TemplateLookups []render.TemplateLookup

	Port    uint16
	Address string
}

Server is the main class that parka uses to serve static and templated content. It is a wrapper around gin.Engine.

It is meant to be quite flexible, allowing you to add static paths and template lookups that can provide different fs and template backends.

Router is the gin.Engine that is used to serve the content, and it is exposed so that you can use it as just a gin.Engine if you want to.

func NewServer

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

NewServer will create a new Server with the given options. This loads a fixed set of files and templates from the embed.FS. These files provide tailwind support for Markdown rendering and a standard index and base page template. NOTE(manuel, 2023-04-16) This is definitely ripe to be removed.

func (*Server) HandleSimpleFormCommand added in v0.2.4

func (s *Server) HandleSimpleFormCommand(
	cmd cmds.GlazeCommand,
	options ...glazed.HandleOption,
) gin.HandlerFunc

func (*Server) HandleSimpleQueryCommand added in v0.2.4

func (s *Server) HandleSimpleQueryCommand(
	cmd cmds.GlazeCommand,
	options ...glazed.HandleOption,
) 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(ctx context.Context) error

Run will start the server and listen on the given address and port.

type ServerOption

type ServerOption = func(*Server)

func WithAddress added in v0.2.6

func WithAddress(address string) ServerOption

WithAddress will set the address that the server will listen on.

func WithAppendTemplateLookups added in v0.2.6

func WithAppendTemplateLookups(lookups ...render.TemplateLookup) ServerOption

WithAppendTemplateLookups will append the given template lookups to the list of lookups, but they will be found after whatever templates might already be in the list. This is great for providing fallback templates.

func WithPort added in v0.2.6

func WithPort(port uint16) ServerOption

WithPort will set the port that the server will listen on.

func WithPrependTemplateLookups added in v0.2.6

func WithPrependTemplateLookups(lookups ...render.TemplateLookup) ServerOption

WithPrependTemplateLookups will prepend the given template lookups to the list of lookups, ensuring that they will be found before whatever templates might already be in the list.

func WithReplaceTemplateLookups added in v0.2.6

func WithReplaceTemplateLookups(lookups ...render.TemplateLookup) ServerOption

WithReplaceTemplateLookups will replace any existing template lookups with the given ones.

func WithStaticPaths

func WithStaticPaths(paths ...StaticPath) ServerOption

WithStaticPaths will add the given static paths to the list of static paths. If a path with the same URL path already exists, it will be replaced.

type StaticPath

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

StaticPath allows you to serve static files from a http.FileSystem under a given URL path urlPath.

func NewStaticPath

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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