2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

feat: 数据库管理优化2

This commit is contained in:
耗子
2024-11-27 01:45:58 +08:00
parent cd8a10d799
commit 3677d0317c
12 changed files with 90 additions and 6 deletions

View File

@@ -39,6 +39,7 @@ func Success(w http.ResponseWriter, data any) {
func Error(w http.ResponseWriter, code int, format string, args ...any) {
render := chix.NewRender(w)
defer render.Release()
render.Header(chix.HeaderContentType, chix.MIMEApplicationJSONCharsetUTF8) // must before Status()
render.Status(code)
render.JSON(&ErrorResponse{
Message: fmt.Sprintf(format, args...),
@@ -49,6 +50,7 @@ func Error(w http.ResponseWriter, code int, format string, args ...any) {
func ErrorSystem(w http.ResponseWriter) {
render := chix.NewRender(w)
defer render.Release()
render.Header(chix.HeaderContentType, chix.MIMEApplicationJSONCharsetUTF8) // must before Status()
render.Status(http.StatusInternalServerError)
render.JSON(&ErrorResponse{
Message: "系统内部错误",

View File

@@ -68,3 +68,18 @@ func (s *Database) Delete(w http.ResponseWriter, r *http.Request) {
Success(w, nil)
}
func (s *Database) Comment(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.DatabaseComment](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}
if err = s.databaseRepo.Comment(req); err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}
Success(w, nil)
}