31 lines
615 B
Go
31 lines
615 B
Go
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) {
|
|
srv := snap.New("127.0.0.1:9000", "./", nil)
|
|
srv.SetDebug(true)
|
|
|
|
srv.HandleFunc("/", handler)
|
|
srv.HandleFuncCustomAuth(auth, "/auth", "", handlerAuthenticated)
|
|
|
|
srv.Serve()
|
|
}
|
|
|
|
func main() {
|
|
auth := auth.NewAuth("basic")
|
|
auth.AddUser("admin", "admin", "password")
|
|
mustRunServer(auth)
|
|
}
|