aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Stevens <nilix@nilfm.cc>2022-01-09 20:16:30 -0700
committerDerek Stevens <nilix@nilfm.cc>2022-01-09 20:16:30 -0700
commit2f6c88c7f3b1332ff754c4c32707b3209052cf53 (patch)
treefce526effdc74ced095a4f70128f74abd0d0bd68
parent34c8b2e65616b4b57c0bb03815d7c136471e01fc (diff)
add README and LICENSE, and refactor IndentalUserDB to support Data map
-rw-r--r--LICENSE7
-rw-r--r--README.md45
-rw-r--r--indentalUserDB/indentalUserDB.go74
-rw-r--r--quartzgun.pngbin0 -> 275613 bytes
4 files changed, 103 insertions, 23 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..a4e4e4b
--- /dev/null
+++ b/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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..60633f4
--- /dev/null
+++ b/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.
diff --git a/indentalUserDB/indentalUserDB.go b/indentalUserDB/indentalUserDB.go
index a8131fd..a3784d0 100644
--- a/indentalUserDB/indentalUserDB.go
+++ b/indentalUserDB/indentalUserDB.go
@@ -125,44 +125,68 @@ func readDB(filePath string) (map[string]*auth.User, error) {
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 @@ func writeDB(filePath string, users map[string]*auth.User) error {
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
diff --git a/quartzgun.png b/quartzgun.png
new file mode 100644
index 0000000..ddc8bf0
--- /dev/null
+++ b/quartzgun.png
Binary files differ