No Description

spsobole 8151a24cc3 Add some nice code cleanup 2 years ago
auth 8151a24cc3 Add some nice code cleanup 2 years ago
examples f583b02d88 Cleanup and autobuild file 3 years ago
pkg 8151a24cc3 Add some nice code cleanup 2 years ago
test 75c29093b3 Add test code 3 years ago
.gitignore 6a63c7cc76 Add options for themes and templates 6 years ago
LICENSE a12f64d256 Initial commit 6 years ago
README.md 2f0e142c92 update readme 3 years ago
build.yaml f583b02d88 Cleanup and autobuild file 3 years ago
context.go 8151a24cc3 Add some nice code cleanup 2 years ago
debug.go eab56d649f Cleanup the API a bit add debug functions 5 years ago
go.mod 813df834ab auth/auth.go 3 years ago
go.sum 767811eec6 Fix auth user on non auth paths 3 years ago
route.go 8151a24cc3 Add some nice code cleanup 2 years ago
server.go 8151a24cc3 Add some nice code cleanup 2 years ago
server_test.go 6f29b1e86d Use http.Filesystem 3 years ago
utility.go e59a973228 Small fixes 3 years ago

README.md

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)
}