Add fiber http backend
This commit is contained in:
@@ -2,4 +2,20 @@ module stinkinator
|
|||||||
|
|
||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
require github.com/mattn/go-sqlite3 v1.14.24
|
require (
|
||||||
|
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.24
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||||
|
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
|
github.com/valyala/fasthttp v1.55.0 // indirect
|
||||||
|
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||||
|
golang.org/x/sys v0.21.0 // indirect
|
||||||
|
)
|
||||||
|
@@ -1,2 +1,35 @@
|
|||||||
|
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||||
|
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gofiber/fiber/v3 v3.0.0-beta.3 h1:7Q2I+HsIqnIEEDB+9oe7Gadpakh6ZLhXpTYz/L20vrg=
|
||||||
|
github.com/gofiber/fiber/v3 v3.0.0-beta.3/go.mod h1:kcMur0Dxqk91R7p4vxEpJfDWZ9u5IfvrtQc8Bvv/JmY=
|
||||||
|
github.com/gofiber/utils/v2 v2.0.0-beta.4 h1:1gjbVFFwVwUb9arPcqiB6iEjHBwo7cHsyS41NeIW3co=
|
||||||
|
github.com/gofiber/utils/v2 v2.0.0-beta.4/go.mod h1:sdRsPU1FXX6YiDGGxd+q2aPJRMzpsxdzCXo9dz+xtOY=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||||
|
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
||||||
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
|
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
|
||||||
|
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
|
||||||
|
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||||
|
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||||
|
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/gofiber/fiber/v3"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -36,10 +36,6 @@ var ns NoteService
|
|||||||
var as AssociationService
|
var as AssociationService
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
inputFile := flag.String("if", "input", "Input file")
|
|
||||||
flag.Parse()
|
|
||||||
log.Printf("Input file: %s", *inputFile)
|
|
||||||
|
|
||||||
db = DB{
|
db = DB{
|
||||||
path: "data/db.db",
|
path: "data/db.db",
|
||||||
}
|
}
|
||||||
@@ -55,24 +51,41 @@ func main() {
|
|||||||
ns = NoteService{db: &db}
|
ns = NoteService{db: &db}
|
||||||
as = AssociationService{db: &db}
|
as = AssociationService{db: &db}
|
||||||
|
|
||||||
inputData, err := os.ReadFile(*inputFile)
|
app := fiber.New()
|
||||||
if err != nil {
|
|
||||||
Error.Printf("Failed reading input file: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Printf("%#v", string(inputData))
|
|
||||||
|
|
||||||
note, err := ParseNote(string(inputData))
|
app.Post("/note/new", CreateNote)
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":3000"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateNote(c fiber.Ctx) error {
|
||||||
|
data := c.Body()
|
||||||
|
res := Response{}
|
||||||
|
|
||||||
|
note, err := ParseNote(string(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Failed parsing note: %v", err)
|
Error.Printf("Failed parsing note: %v", err)
|
||||||
return
|
res.Success = false
|
||||||
|
res.Message = err.Error()
|
||||||
|
return c.Status(400).JSON(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbnote, ass, err := PersistNoteData(note)
|
if note.Player == "" {
|
||||||
|
Error.Printf("No player specified in note: %v", note)
|
||||||
|
res.Success = false
|
||||||
|
res.Message = "No player specified"
|
||||||
|
return c.Status(400).JSON(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
dbnote, _, err := PersistNoteData(note)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Failed persisting note: %v", err)
|
Error.Printf("Failed persisting note: %v", err)
|
||||||
return
|
res.Success = false
|
||||||
|
res.Message = err.Error()
|
||||||
|
return c.Status(500).JSON(res)
|
||||||
}
|
}
|
||||||
log.Printf("%#v", dbnote)
|
|
||||||
log.Printf("%#v", ass)
|
res.Data = dbnote
|
||||||
|
res.Message = "OK"
|
||||||
|
return c.Status(200).JSON(res)
|
||||||
}
|
}
|
||||||
|
@@ -8,9 +8,9 @@ type (
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
Player struct {
|
Player struct {
|
||||||
ID int64
|
ID int64
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Guild Guild `json:"guild"`
|
Guild Guild `json:"guild"`
|
||||||
}
|
}
|
||||||
Association struct {
|
Association struct {
|
||||||
ID int64
|
ID int64
|
||||||
@@ -36,4 +36,10 @@ type NoteData struct {
|
|||||||
type NoteAssociationData struct {
|
type NoteAssociationData struct {
|
||||||
Player string
|
Player string
|
||||||
Note string
|
Note string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Success bool
|
||||||
|
Message string
|
||||||
|
Data interface{}
|
||||||
|
}
|
||||||
|
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -40,6 +41,7 @@ func BuildWhereQuery(params interface{}) string {
|
|||||||
|
|
||||||
var associationRe = regexp.MustCompile(`r:(\w+)(?:\(([^)]+)\))?`)
|
var associationRe = regexp.MustCompile(`r:(\w+)(?:\(([^)]+)\))?`)
|
||||||
func ParseNote(data string) (NoteData, error) {
|
func ParseNote(data string) (NoteData, error) {
|
||||||
|
log.Printf("Parsing note: %q", data)
|
||||||
res := NoteData{}
|
res := NoteData{}
|
||||||
lines := strings.Split(data, "\n")
|
lines := strings.Split(data, "\n")
|
||||||
note := []string{}
|
note := []string{}
|
||||||
|
Reference in New Issue
Block a user