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:
@@ -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