snap/examples/simple/main.go

33 lines
602 B
Go
Raw Normal View History

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.AuthManager) {
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)
}