snap

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: GPL-3.0 Imports: 21 Imported by: 0

README

snap

Typical layout for snap servers

    web/
        templates/
        static/
              app/
                 js/...
              skin1/...
              skin2/...
              favicon.ico              

Example:

package main

import (
	"git.thirdmartini.com/pub/snap"
	"git.thirdmartini.com/pub/snap/auth"
)

func handler(c *snap.Context) {
	c.Reply("snap/example/simple 1.0")
}

func handlerAuthenticated(c *snap.Context) {
	c.Reply("snap/example/simple 1.0 (authenticated)")
}

func mustRunServer(auth auth.Authenticator) {
	s := snap.New("localhost:9000", "web", auth)
	s.SetDebug(true)
	s.SetTemplatePath("web/templates")
	s.WithStaticFiles("/static", "web/static" )
	s.WithTheme("skin1")
	
	s.HandleFunc("/", handler)
	s.HandleFuncAuthenticated("/auth", "", handlerAuthenticated)

	s.Serve()
}

func main() {
	auth := auth.NewAuth("basic")
	auth.AddUser("admin", "admin", "password")
	mustRunServer(auth)
}	

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redirect added in v1.0.0

func Redirect(to string) func(c *Context)

func Walk added in v1.0.0

func Walk(fs http.FileSystem, base string, walkFunc func(path string, info os.FileInfo, err error) error) error

Types

type Context

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

func (*Context) Error

func (c *Context) Error(code int, msg string)

func (*Context) ErrorObject added in v1.0.0

func (c *Context) ErrorObject(code int, obj interface{})

func (*Context) FormValue

func (c *Context) FormValue(k string) string

func (*Context) FormValueAsSlice added in v1.0.0

func (c *Context) FormValueAsSlice(k string, delim string) []string

func (*Context) FormValueUint64

func (c *Context) FormValueUint64(k string) uint64

func (*Context) GetObject

func (c *Context) GetObject(obj interface{}) error

func (*Context) GetRequest

func (c *Context) GetRequest() *http.Request

func (*Context) GetUser

func (c *Context) GetUser() string

func (*Context) GetVar

func (c *Context) GetVar(k string) (string, bool)

func (*Context) GetVarAsSlice added in v1.0.0

func (c *Context) GetVarAsSlice(k string, delim string, def []string) []string

func (*Context) GetVarDefault

func (c *Context) GetVarDefault(k string, def string) string

func (*Context) ParseForm

func (c *Context) ParseForm() error

func (*Context) QueryHas added in v1.0.0

func (c *Context) QueryHas(key string) bool

func (*Context) QueryValue

func (c *Context) QueryValue(key string) string

func (*Context) QueryValueWithDefault

func (c *Context) QueryValueWithDefault(key string, def string) string

func (*Context) Redirect

func (c *Context) Redirect(url string)

func (*Context) Render

func (c *Context) Render(tmpl string, content interface{})

func (*Context) RenderEx

func (c *Context) RenderEx(tmpl string, content interface{})

func (*Context) RenderWithMeta added in v1.0.0

func (c *Context) RenderWithMeta(tmpl string, meta map[string]string, content interface{})

func (*Context) Reply

func (c *Context) Reply(msg string)

func (*Context) ReplyObject

func (c *Context) ReplyObject(obj interface{})

func (*Context) ReplyWithHeaders added in v1.0.0

func (c *Context) ReplyWithHeaders(msg string, kv map[string]string)

func (*Context) Writer

func (c *Context) Writer() http.ResponseWriter

type RouteBuilder added in v1.0.1

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

func NewRouteBuilder added in v1.0.1

func NewRouteBuilder() *RouteBuilder

func (*RouteBuilder) BuildRoute added in v1.0.1

func (r *RouteBuilder) BuildRoute(s *Server) http.HandlerFunc

func (*RouteBuilder) WithAuth added in v1.0.1

func (r *RouteBuilder) WithAuth(auth auth.Authenticator) *RouteBuilder

func (*RouteBuilder) WithContent added in v1.0.1

func (r *RouteBuilder) WithContent(contentHandler func(c *Context)) *RouteBuilder

func (*RouteBuilder) WithLoginHandler added in v1.0.1

func (r *RouteBuilder) WithLoginHandler(loginHandler func(c *Context) bool) *RouteBuilder

type Server

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

func New

func New(address string, path string, auth auth.Authenticator) *Server

func (*Server) AddRoute added in v1.0.1

func (s *Server) AddRoute(path string, r *RouteBuilder) *mux.Route

func (*Server) Dump added in v0.2.0

func (s *Server) Dump()

func (*Server) EnableStatus

func (s *Server) EnableStatus(path string)

func (*Server) EnableTestMode added in v1.0.0

func (s *Server) EnableTestMode(enable bool) *Server

func (*Server) HandleFunc

func (s *Server) HandleFunc(path string, f func(c *Context)) *mux.Route

func (*Server) HandleFuncAuthenticated

func (s *Server) HandleFuncAuthenticated(path, redirect string, f func(c *Context)) *mux.Route

func (*Server) HandleFuncAuthenticatedWithLogin added in v1.0.0

func (s *Server) HandleFuncAuthenticatedWithLogin(path string, loginHandler func(c *Context) bool, contentHandler func(c *Context)) *mux.Route

func (*Server) HandleFuncCustomAuth

func (s *Server) HandleFuncCustomAuth(auth auth.Authenticator, path, redirect string, f func(c *Context)) *mux.Route

func (*Server) LoadTemplatesFS added in v1.0.0

func (s *Server) LoadTemplatesFS(fs http.FileSystem, base string) (*template.Template, error)

func (*Server) Router

func (s *Server) Router() *mux.Router

func (*Server) Serve

func (s *Server) Serve() error

Serve serve content forever

func (*Server) ServeTLS

func (s *Server) ServeTLS(keyPath string, certPath string) error

func (*Server) ServeTLSRedirect added in v1.0.1

func (s *Server) ServeTLSRedirect(address string) error

func (*Server) SetDebug

func (s *Server) SetDebug(enable bool)

func (*Server) SetTemplatePath

func (s *Server) SetTemplatePath(tmplPath string)

func (*Server) SetTheme

func (s *Server) SetTheme(themePath string)

func (*Server) WithAuth added in v1.0.0

func (s *Server) WithAuth(auth auth.Authenticator) *Server

func (*Server) WithDebug

func (s *Server) WithDebug(debugURL string) *Server

func (*Server) WithHealthCheck added in v1.0.0

func (s *Server) WithHealthCheck(version, date string, status func() (bool, string))

func (*Server) WithMetadata added in v1.0.0

func (s *Server) WithMetadata(meta map[string]string) *Server

func (*Server) WithRootFileSystem added in v1.0.0

func (s *Server) WithRootFileSystem(fs http.FileSystem) *Server

func (*Server) WithStaticFiles

func (s *Server) WithStaticFiles(prefix string) *Server

func (*Server) WithTemplateFuncs added in v1.0.0

func (s *Server) WithTemplateFuncs(funcs template.FuncMap) *Server

func (*Server) WithTheme

func (s *Server) WithTheme(themeURL string) *Server

type SnapBaseContent

type SnapBaseContent struct {
	Theme   string
	Content interface{}
}

type SnapContent

type SnapContent struct {
	User           string
	UserProperties map[string]string
	Theme          string
	Meta           map[string]string
	Content        interface{}
}

Directories

Path Synopsis
examples
pkg

Jump to

Keyboard shortcuts

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