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