spsobole 8151a24cc3 Add some nice code cleanup | 2 years ago | |
---|---|---|
auth | 2 years ago | |
examples | 3 years ago | |
pkg | 2 years ago | |
test | 3 years ago | |
.gitignore | 6 years ago | |
LICENSE | 6 years ago | |
README.md | 3 years ago | |
build.yaml | 3 years ago | |
context.go | 2 years ago | |
debug.go | 5 years ago | |
go.mod | 3 years ago | |
go.sum | 3 years ago | |
route.go | 2 years ago | |
server.go | 2 years ago | |
server_test.go | 3 years ago | |
utility.go | 3 years ago |
Typical layout for snap servers
web/
templates/
static/
app/
js/...
skin1/...
skin2/...
favicon.ico
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)
}