all repos — quartzgun @ 2f6c88c7f3b1332ff754c4c32707b3209052cf53

lightweight web framework in go

add README and LICENSE, and refactor IndentalUserDB to support Data map
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmHbpQ4ACgkQO3+8IhRO
Y5iicA//dciiiQEwZMsjUptJTu2UwqWn7ShyX45Yi+idmR50RhPJbBv8k9tGwvxG
FXZtLvez2mm0HGSB8V8VN4Igt4IVJW5sbXAllxFfzDZeL3by+uCfoTJk6mdDjWAB
eAjtqlLUVsf7yoqs4YeoNU6L1/o44LOTTkgZ7pHjR3gZFxvqMh/BX8K8Tk9NBVEL
qHwQlDC1UdO4bYAtK2XbNeXO64rM2mqXMd6NM3EA0YND9lQ52Zsq2dAR45soVqam
kRU68f8qlOL9dPMwvrJcFRoSx9oGvG8FFQaSKrSvfHFH0l1PS2k7ZDGc2Un+g07d
PPXACkQ8vMmIbdmC5mt//UUVXVWJPuTW+ggT0pkV2TWh8IJJinIhzrxPpolfTlNO
A0zRsJP4yAXeSnlDejJjcSU/4VCKEnDIr8hr2xVjyGgndvBoKswnxOJbI9kvnuM/
+TQc2acdn/wUg9sZiR2JN/WTJXWFiMAASe4Gt+l+h5BZx/JqSuStcT0yBfkaj5SS
vxhVOjCQVMdsuh6wUR1bbej7qROJtH7au9WDPWZR8OXH7rYnt+dARVT4mGhH5mC6
bJjUQb4j7iJB/9PbZfhZmxR6n0DJPtAbkBoup48hQS3GpjD8j1jpx6Qq2d6EbmMj
iMHhrfM6CIWmwSsPbCPe3sKjj+ijPslsWQzqsJaJyYDJLSL5f5Y=
=IDm+
-----END PGP SIGNATURE-----
commit

2f6c88c7f3b1332ff754c4c32707b3209052cf53

parent

34c8b2e65616b4b57c0bb03815d7c136471e01fc

4 files changed, 103 insertions(+), 23 deletions(-)

jump to
A LICENSE

@@ -0,0 +1,7 @@

+Copyright 2021 Derek Stevens <nilix@nilfm.cc> + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
A README.md

@@ -0,0 +1,45 @@

+# quartzgun + +A lightweight web framework for Go + +![Quartz Gun effect from Eureka Seven AO, showing a tree of light spanning down to the earth with its root in low orbit](./quartzgun.png) + +## philosophy/design + +`quartzgun` is designed to enable speedy development of efficient web sites and APIs in Go. There are no dependencies outside of the standard library except for `bcrypt`, and the library is modular -- you can use any part of it independently. The router uses the `func(http.Handler) http.Handler` middleware pattern so that you can plug and play existing middleware. + +There are pre-made `renderers` which are designed as plug and play endpoints in your middleware chains. They are used for providing the basic functionality of the route, rendering an HTML template in the case of a normal page, or JSON or XML for API endpoints. + +The `auth` system is designed from scratch to provide a modular system where new authentication/authorization backends can be added easily by satisfying the `auth.UserStore` interface. + +### about the name + +The [Quartz Gun](https://eurekaseven.fandom.com/wiki/Quartz_Gun) is a weapon in the anime Eureka Seven AO; it's fueled by a sentient entity known as Quartz, and instead of being used in a traditional sense as a weapon, it alters the timeline when fired. Thinking about URL routes reminded me of the tree of light it emits when fired, so I named the library `quartzgun`. + +## usage + +A more complete usage guide will be forthcoming when the library is more complete, but for now you can check out the [quartzgun_test.go](https://nilfm.cc/git/quartzgun/tree/quartzgun_test.go) file for an overview of how to use it. + +## roadmap/features + +### core functionality + +* [x] router (static service trees, paramaterized routes, and per-method handlers on routes) +* [x] basic renderers (HTML template, JSON, XML) + +### auth + +* [ ] top-level wrapper for attaching `UserStore` backends to cookie handler +* [x] POC [indental](https://wiki.xxiivv.com/site/indental.html) `UserStore` implementation + +### etc + +* [ ] generic DAL wrapper? might be unneccessary + +## license + +`quartzgun` is licensed under the MIT license -- see the [LICENSE](./LICENSE) file for details but the long and short of it is you can use/modify it for any reason, but give me (and other authors where applicable) credit for writing it. + +## contributing + +Send patches to [nilix@nilfm.cc](mailto:nilix@nilfm.cc) using `git format-patch -s HEAD~<however many commits>`. The `-s` flag ensures that your name makes it into the commit log.
M indentalUserDB/indentalUserDB.goindentalUserDB/indentalUserDB.go

@@ -125,44 +125,68 @@ if err != nil {

return nil, err } - data := string(f[:]) + fileData := string(f[:]) users := map[string]*auth.User{} - lines := strings.Split(data, "\n") + lines := strings.Split(fileData, "\n") + + indentLevel := "" + var name string var pass string var session string var loginTime time.Time var lastSeen time.Time - procFields := 0 + var data map[string]interface{} + for _, l := range lines { - if !strings.HasPrefix(l, " ") { - name = l - procFields++ - } else { - kvp := strings.Split(l, ":") - k := strings.TrimSpace(kvp[0]) - v := strings.TrimSpace(kvp[1]) - switch k { - case "pass": - pass = v - case "session": - session = v - case "loginTime": - loginTime, _ = time.Parse(timeFmt, v) - case "lastSeen": - lastSeen, _ = time.Parse(timeFmt, v) + if strings.HasPrefix(l, indentLevel) { + switch indentLevel { + case "": + name = l + indentLevel = "\t" + + case "\t": + if strings.Contains(l, ":") { + kvp := strings.Split(l, ":") + k := strings.TrimSpace(kvp[0]) + v := strings.TrimSpace(kvp[1]) + switch k { + case "pass": + pass = v + case "session": + session = v + case "loginTime": + loginTime, _ = time.Parse(timeFmt, v) + case "lastSeen": + lastSeen, _ = time.Parse(timeFmt, v) + } + } else { + data = map[string]interface{}{} + indentLevel = "\t\t" + } + + case "\t\t": + if strings.Contains(l, ":") { + kvp := strings.Split(l, ":") + k := strings.TrimSpace(kvp[0]) + v := strings.TrimSpace(kvp[1]) + data[k] = v + } } - procFields++ - if procFields == 5 { + } else { + if indentLevel != "\t\t" { + panic("Malformed indental file") + } else { users[name] = &auth.User{ Name: name, Pass: pass, Session: session, LoginTime: loginTime, LastSeen: lastSeen, + Data: data, } - procFields = 0 + indentLevel = "" } } }

@@ -178,12 +202,16 @@

defer f.Close() for _, user := range users { - f.WriteString(fmt.Sprintf("%s\n pass: %s\n session: %s\n loginTime: %s\n lastSeen: %s\n", + f.WriteString(fmt.Sprintf("%s\n\tpass: %s\n\tsession: %s\n\tloginTime: %s\n\tlastSeen: %s\n\tdata\n", user.Name, user.Pass, user.Session, user.LoginTime, user.LastSeen)); + for k, v := range user.Data { + f.WriteString(fmt.Sprintf("\t\t%s: %s\n", k, v)) + } + f.WriteString("\n") } f.Sync() return nil