mirror of
https://codeberg.org/scip/anydb.git
synced 2026-02-04 09:20:58 +01:00
replace fiber with http.ServeMux
This commit is contained in:
@@ -569,7 +569,7 @@ Some curl example calls to the API:
|
||||
Post a new key:
|
||||
curl -X PUT localhost:8787/anydb/v1/ \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"key":"foo","val":"bar"}'
|
||||
-d '{"key":"foo","data":"bar"}'
|
||||
|
||||
Retrieve the value:
|
||||
|
||||
@@ -579,6 +579,11 @@ List all keys:
|
||||
|
||||
curl localhost:8787/anydb/v1/
|
||||
|
||||
Delete an entry:
|
||||
|
||||
curl -s -X DELETE http://localhost:8787/anydb/v1/foo
|
||||
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
In order to report a bug, unexpected behavior, feature requests
|
||||
|
||||
11
app/attr.go
11
app/attr.go
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2024 Thomas von Dein
|
||||
Copyright © 2024-2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -28,6 +28,7 @@ type DbAttr struct {
|
||||
Key string
|
||||
Preview string
|
||||
Val []byte
|
||||
Data string // alias
|
||||
Args []string
|
||||
Tags []string
|
||||
File string
|
||||
@@ -63,6 +64,12 @@ func (attr *DbAttr) ParseKV() error {
|
||||
}
|
||||
}
|
||||
|
||||
attr.SetPreview()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (attr *DbAttr) SetPreview() {
|
||||
switch {
|
||||
case attr.Binary:
|
||||
attr.Preview = "<binary-content>"
|
||||
@@ -82,8 +89,6 @@ func (attr *DbAttr) ParseKV() error {
|
||||
attr.Preview = string(attr.Val)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (attr *DbAttr) GetFileValue() error {
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
"github.com/tlinden/yadu"
|
||||
)
|
||||
|
||||
var Version string = "v0.2.6"
|
||||
var Version string = "v0.3.0"
|
||||
|
||||
type BucketConfig struct {
|
||||
Encrypt bool
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2024 Thomas von Dein
|
||||
Copyright © 2024-2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"codeberg.org/scip/anydb/app"
|
||||
"codeberg.org/scip/anydb/cfg"
|
||||
"codeberg.org/scip/anydb/output"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func Set(conf *cfg.Config) *cobra.Command {
|
||||
|
||||
1
go.mod
1
go.mod
@@ -20,6 +20,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alecthomas/repr v0.5.2 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,3 +1,5 @@
|
||||
github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs=
|
||||
github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
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=
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2024 Thomas von Dein
|
||||
Copyright © 2024-2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -122,6 +122,13 @@ func RestSet(resp http.ResponseWriter, req *http.Request, conf *cfg.Config) {
|
||||
return
|
||||
}
|
||||
|
||||
// attr.Data is a string, thus the decoder doesn't expect it to be
|
||||
// base64 encoded. However, internally we need []byte, therefore
|
||||
// we copy a cast to .Val. We also need to setup the .Preview
|
||||
// value here.
|
||||
attr.Val = []byte(attr.Data)
|
||||
attr.SetPreview()
|
||||
|
||||
err = conf.DB.Set(attr)
|
||||
if err != nil {
|
||||
JsonStatus(resp, http.StatusForbidden, "Unable to set key: "+err.Error())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright © 2024 Thomas von Dein
|
||||
Copyright © 2024-2025 Thomas von Dein
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -36,15 +36,16 @@ func Runserver(conf *cfg.Config, args []string) error {
|
||||
// setup api server
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
|
||||
// just in case someone tries to access the non-api url
|
||||
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
Home(w)
|
||||
})
|
||||
|
||||
mux.HandleFunc("GET "+apiprefix, func(w http.ResponseWriter, r *http.Request) {
|
||||
mux.HandleFunc("GET "+apiprefix+"{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
RestList(w, r, conf)
|
||||
})
|
||||
|
||||
mux.HandleFunc("POST "+apiprefix, func(w http.ResponseWriter, r *http.Request) {
|
||||
mux.HandleFunc("POST "+apiprefix+"{$}", func(w http.ResponseWriter, r *http.Request) {
|
||||
RestList(w, r, conf)
|
||||
})
|
||||
|
||||
@@ -59,7 +60,7 @@ func Runserver(conf *cfg.Config, args []string) error {
|
||||
})
|
||||
|
||||
mux.HandleFunc("PUT "+apiprefix, func(w http.ResponseWriter, r *http.Request) {
|
||||
RestList(w, r, conf)
|
||||
RestSet(w, r, conf)
|
||||
})
|
||||
|
||||
logger := LogHandler()
|
||||
|
||||
Reference in New Issue
Block a user