Go to file
spsobole 377fcd0230 Sync versions of core 2024-04-16 11:54:34 -06:00
auth Clean up some extranouss prints 2023-08-17 21:30:47 -06:00
examples/simple Update post move 2023-05-23 08:09:57 -06:00
pkg/autocert Add some nice code cleanup 2021-06-18 13:43:52 -06:00
test Add test code 2021-01-18 20:02:59 -07:00
.gitignore Add options for themes and templates 2018-03-24 11:31:10 -06:00
LICENSE Initial commit 2018-01-23 19:24:26 -07:00
README.md Update post move 2023-05-23 08:09:57 -06:00
build.yaml Update post move 2023-05-23 08:09:57 -06:00
context.go Clean up some extranouss prints 2023-08-17 21:30:47 -06:00
debug.go Cleanup the API a bit add debug functions 2019-01-03 17:38:02 -07:00
go.mod Sync versions of core 2024-04-16 11:54:34 -06:00
go.sum Sync versions of core 2024-04-16 11:54:34 -06:00
options.go Add ability to shutdown the server 2024-03-21 12:09:05 -06:00
route.go Make authentication a bit more flexible 2023-05-28 10:34:12 -06:00
server.go Add default name to logger 2024-04-16 11:35:00 -06:00
server_test.go Update post move 2023-05-23 08:09:57 -06:00
service.go Clean up some extranouss prints 2023-08-17 21:30:47 -06:00
service_request.go Clean up some extranouss prints 2023-08-17 21:30:47 -06:00
utility.go Small fixes 2021-05-29 15:14:15 -06:00

README.md

snap

Typical layout for snap servers

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

Example:

package main

import (
	"git.twelvetwelve.org/library/snap"
	"git.twelvetwelve.org/library/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)
}