From 2f0e142c92419995c6d15b4e577998b35f7e2c87 Mon Sep 17 00:00:00 2001 From: spsobole Date: Mon, 18 Jan 2021 20:11:07 -0700 Subject: [PATCH] update readme --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index 00a3626..6b8a3b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,51 @@ # snap +Typical layout for snap servers + +``` + web/ + templates/ + static/ + app/ + js/... + skin1/... + skin2/... + favicon.ico +``` + +# Example: +```golang +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.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) +} +``` \ No newline at end of file