Commit 2aca2e4c authored by Artemis's avatar Artemis

Base commit

parents
# Top-most editorconfig file
root = true
[*]
end_of_line=lf
insert_final_newline=true
charset=utf-8
indent_style=space
indent_size=4
[Makefile]
indent_style=tab
.idea/
*.iml
build/
This diff is collapsed.
paste
---
.. image:: https://pix.watch/62tBpX/PURcI2.png
:target: https://www.buymeacoffee.com/Artemis
Small temp redis-based pastebin server
package main
import (
"fmt"
"github.com/elgs/gostrgen"
"github.com/husobee/vestigo"
"log"
"net/http"
)
func GetNewKey() (error, string) {
key, err := gostrgen.RandGen(6, gostrgen.LowerUpper, "", "")
if err != nil {
fmt.Print(err)
return err, ""
}
return nil, key
}
//func (b Backend) Store(paste string) (error, string) {
// err, key := GetNewKey()
// if err == nil { return err, "" }
//
// res := b.client.Set(key, paste, time.Hour)
// if err := res.Err(); err != nil { return err, "" }
//
// return nil, key
//}
func main() {
//backend := redis.NewClient(&redis.Options{})
//res := backend.Ping()
//if err := res.Err(); err != nil { panic(err) }
r := vestigo.NewRouter()
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
_, _ = fmt.Fprint(w, "TODO homepage")
})
r.Post("/", func(w http.ResponseWriter, req *http.Request) {
err, key := GetNewKey()
if err != nil {
w.WriteHeader(500)
fmt.Println(err)
return
}
_, _ = fmt.Fprintln(w, key)
})
r.Get("/s/:key", func(w http.ResponseWriter, req *http.Request) {
key := vestigo.Param(req, "key")
_, _ = fmt.Fprintf(w, "TODO doc retrieval, got key %s", key)
})
r.Get("/r/:key", func(w http.ResponseWriter, req *http.Request) {
key := vestigo.Param(req, "key")
_, _ = fmt.Fprintf(w, "TODO direct raw retrieval, got key %s", key)
})
log.Fatal(http.ListenAndServe(":1234", r))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment