snap/README.md

51 lines
958 B
Markdown
Raw Permalink Normal View History

2018-01-24 02:24:26 +00:00
# snap
2021-01-19 03:11:07 +00:00
Typical layout for snap servers
```
web/
templates/
static/
app/
js/...
skin1/...
skin2/...
favicon.ico
```
# Example:
```golang
package main
import (
2023-05-23 14:09:57 +00:00
"git.twelvetwelve.org/library/snap"
"git.twelvetwelve.org/library/snap/auth"
2021-01-19 03:11:07 +00:00
)
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)
}
```