web

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: MIT Imports: 13 Imported by: 0

README

Web

GoDoc

About

Web is a go library that I created for packaging up common bits of code that I use when creating a web application. It's opinionated and it works for me but others will very likely have different requirements.

Documentation

Index

Constants

This section is empty.

Variables

DefaultMiddleware is an array of basic middleware that are likely to be used in most applications.

Functions

This section is empty.

Types

type Config

type Config struct {
	IP                   string   // IP address to listen on. If blank listen on any
	Port                 int      // Port number to listen on. If blank it's dynamic?
	AutoTLS              bool     // Setup TLS automatically using let's encrypt
	AutoTLSDomains       []string // The acceptable domains for let's encrypt certs
	PublicDir            string   // The path to the public directory
	Secret               string   // The secret for secure cookies and CSRF
	TemplateDir          string   // The location of template files
	CacheTemplates       bool     // If true templates are cached which is faster in production
	UseDefaultMiddleware bool     // If true the default middleware is loaded
	Database             string   // mysql or sqlite3
	DatabaseDSN          string   //  The Database DSN. For example: file:test.db?_fk=1
}

Config holds all of the possible variables for configuring a web server

func NewConfig

func NewConfig() *Config

NewConfig returns an empty Config

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a very basic configuration that might be ok for development but is not usable for most production deployments.

func (*Config) LoadTOML

func (c *Config) LoadTOML(file string) error

LoadTOML reads a config file and loads it into Config

func (*Config) SaveTOML

func (c *Config) SaveTOML(file string) error

SaveTOML saves the configuration into a TOML config file

type Server

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

Server holds the various components needed for a web server

func NewServer

func NewServer(c *Config) (*Server, error)

NewServer initializes a new Server struct based on the Config that is passed in. If Config is nil then the Config returned by NewDefaultConfig is used.

func (*Server) Config

func (s *Server) Config() *Config

Config returns the Server configuration struct

func (*Server) DecodeForm added in v0.1.4

func (s *Server) DecodeForm(v interface{}, r *http.Request) error

DecodeForm taks a value and a *http.Request, parses the form and tries to populate the form values into v.

func (*Server) Decoder

func (s *Server) Decoder() *form.Decoder

Decoder returns the decoder used for forms. This can be used to add custom behavior. In common cases it shouldn't be needed.

func (*Server) HTML added in v0.1.2

func (s *Server) HTML(w io.Writer, file string, ctx pongo2.Context) error

HTML renders the template and writes the response to the client. In this case file will be relative to the templates directory. For example if you have a template like templates/users/new.html you can pass users/new.html as the file.

func (*Server) Router

func (s *Server) Router() *chi.Mux

Router returns the main router

func (*Server) Start

func (s *Server) Start() error

Start begins the web server and returns an error if one is encountered.

func (*Server) Template

func (s *Server) Template() *pongo2.TemplateSet

Template returns the template engine used for this server.

Jump to

Keyboard shortcuts

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