add README and LICENSE, and refactor IndentalUserDB to support Data map
This commit is contained in:
parent
34c8b2e656
commit
2f6c88c7f3
4 changed files with 103 additions and 23 deletions
7
LICENSE
Normal file
7
LICENSE
Normal file
|
@ -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.
|
45
README.md
Normal file
45
README.md
Normal file
|
@ -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.
|
|
@ -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
|
||||
|
|
BIN
quartzgun.png
Normal file
BIN
quartzgun.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 269 KiB |
Loading…
Reference in a new issue