summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChloe Kudryavtsev <toast@toast.cafe>2019-11-24 13:33:14 -0500
committerChloe Kudryavtsev <toast@toast.cafe>2019-11-24 13:33:14 -0500
commit680e1e476c0be4eb375c3c5789bda66a7a648b10 (patch)
treea3a6c42b7ff7fac9810c5d18c44a008cbc07b922
parentDocument new storage selection option (diff)
Documentation pass
- document Get - document Index - document Put - unexport global settings from main
-rw-r--r--http/get.go1
-rw-r--r--http/index.go1
-rw-r--r--http/put.go1
-rw-r--r--main.go18
4 files changed, 12 insertions, 9 deletions
diff --git a/http/get.go b/http/get.go
index 016173f..903b5b2 100644
--- a/http/get.go
+++ b/http/get.go
@@ -6,6 +6,7 @@ import (
"toast.cafe/x/brpaste/v2/template"
)
+// Get generates a handler for the /:key[/:lang] endpoint
func Get(store storage.CHR) handler {
return func(ctx *fasthttp.RequestCtx) {
ukey := ctx.UserValue("key")
diff --git a/http/index.go b/http/index.go
index 124e172..792e64a 100644
--- a/http/index.go
+++ b/http/index.go
@@ -5,6 +5,7 @@ import (
"toast.cafe/x/brpaste/v2/template"
)
+// Index handles the / endpoint
func Index(ctx *fasthttp.RequestCtx) {
ctx.SuccessString("text/html", template.Index()) // render template
}
diff --git a/http/put.go b/http/put.go
index bc49e74..6f581bf 100644
--- a/http/put.go
+++ b/http/put.go
@@ -9,6 +9,7 @@ import (
"toast.cafe/x/brpaste/v2/storage"
)
+// Put generates a handler for the POST / and PUT /:key endpoints
func Put(store storage.CHR, put bool) handler {
return func(ctx *fasthttp.RequestCtx) {
data := ctx.FormValue("data")
diff --git a/main.go b/main.go
index b398fc5..270b3e9 100644
--- a/main.go
+++ b/main.go
@@ -11,7 +11,7 @@ import (
"toast.cafe/x/brpaste/v2/storage"
)
-var S settings
+var s settings
type settings struct {
Bind string
@@ -21,25 +21,25 @@ type settings struct {
func main() {
// ---- Flags
- flag.StringVar(&S.Bind, "bind", ":8080", "address to bind to")
- flag.StringVar(&S.Redis, "redis", "redis://localhost:6379", "redis connection string")
- flag.StringVar(&S.Storage, "storage", "redis", "type of storage to use")
+ flag.StringVar(&s.Bind, "bind", ":8080", "address to bind to")
+ flag.StringVar(&s.Redis, "redis", "redis://localhost:6379", "redis connection string")
+ flag.StringVar(&s.Storage, "storage", "redis", "type of storage to use")
flag.Parse()
// ---- Storage system
var store storage.CHR
- switch S.Storage {
+ switch s.Storage {
case "redis":
- redisOpts, err := redis.ParseURL(S.Redis)
+ redisOpts, err := redis.ParseURL(s.Redis)
if err != nil {
- fmt.Fprintf(os.Stderr, "Could not parse redis connection string %s\n", S.Redis)
+ fmt.Fprintf(os.Stderr, "Could not parse redis connection string %s\n", s.Redis)
os.Exit(1)
}
client := redis.NewClient(redisOpts)
store = (*storage.Redis)(client)
default:
- fmt.Fprintf(os.Stderr, "Could not figure out which storage system to use, tried %s\n", S.Storage)
+ fmt.Fprintf(os.Stderr, "Could not figure out which storage system to use, tried %s\n", s.Storage)
os.Exit(1)
}
@@ -51,5 +51,5 @@ func main() {
// ---- Start!
handler := http.GenHandler(store)
- fasthttp.ListenAndServe(S.Bind, handler)
+ fasthttp.ListenAndServe(s.Bind, handler)
}