snap/examples/simple/main.go

31 lines
607 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)")
}
2021-01-19 03:00:46 +00:00
func mustRunServer(auth auth.Authenticator) {
srv := snap.New("127.0.0.1:9000", "./", nil)
srv.SetDebug(true)
srv.HandleFunc("/", handler)
2021-01-19 03:23:52 +00:00
srv.HandleFuncCustomAuth(auth, "/auth", "", handlerAuthenticated)
srv.Serve()
}
func main() {
auth := auth.NewAuth("basic")
auth.AddUser("admin", "admin", "password")
mustRunServer(auth)
}