1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor: split utility functions into utils and helpers

This commit is contained in:
Ferdinand Mütsch
2022-12-01 10:57:07 +01:00
parent c5fda02900
commit 21f6809f05
35 changed files with 259 additions and 236 deletions

20
helpers/http.go Normal file
View File

@@ -0,0 +1,20 @@
package helpers
import (
"encoding/json"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/utils"
"net/http"
)
func ExtractCookieAuth(r *http.Request) (username *string, err error) {
return utils.ExtractCookieAuth(r, config.Get().Security.SecureCookie)
}
func RespondJSON(w http.ResponseWriter, r *http.Request, status int, object interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(object); err != nil {
config.Log().Request(r).Error("error while writing json response: %v", err)
}
}