gws

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

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

Go to latest
Published: Nov 3, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

GWS: Go Web Server

This project aims to be a web server I can use between multiple Go projects. It may or may not be useful to you.

Requirements

  • Templates in ./web/templates/
  • Base template named base.html
  • Static files (css, js) in ./web/static/
  • No important files in ./web/staticfiles/

Features

  • If server in production mode, load all templates on startup
  • If server in development mode, load templates on demand
  • Hashes and compresses static files in ./web/static/ to ./web/staticfiles/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseTemplateName = "base.html"
	TemplateDir      = "web/templates/"
	StaticDir        = "web/static/"      // static file source
	StaticFilesDir   = "web/staticfiles/" // hashed/compressed static files
)
View Source
var StaticFiles = make(map[string]string)

Functions

func LoadStaticFile

func LoadStaticFile(path string) error

func LoadStaticFiles

func LoadStaticFiles() error

func Static

func Static(file string) string

Types

type Server

type Server struct {
	Development      bool
	Port             string
	Mux              *http.ServeMux
	TemplateDir      string
	Templates        map[string]*template.Template
	BaseTemplateName string
	FuncMap          template.FuncMap
	StaticDir        string
}

func NewServer

func NewServer(port string, mux *http.ServeMux, development bool) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) LoadTemplate

func (s *Server) LoadTemplate(tmpl string) *template.Template

func (*Server) LoadTemplates

func (s *Server) LoadTemplates()

func (*Server) RenderTemplate

func (s *Server) RenderTemplate(w http.ResponseWriter, tmpl string, data map[string]any)

func (*Server) RenderTemplateFragment

func (s *Server) RenderTemplateFragment(w http.ResponseWriter, tmpl string, fragment string, data map[string]any)

type StaticHandler

type StaticHandler struct{}

func (*StaticHandler) ServeHTTP

func (sh *StaticHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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