update
This commit is contained in:
@@ -15,19 +15,19 @@ import (
|
||||
"management/internal/pkg/render"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
type app struct {
|
||||
render render.Renderer
|
||||
configService systemService.ConfigService
|
||||
}
|
||||
|
||||
func NewApp(render render.Renderer, configService systemService.ConfigService) *App {
|
||||
return &App{
|
||||
func newApp(render render.Renderer, configService systemService.ConfigService) *app {
|
||||
return &app{
|
||||
render: render,
|
||||
configService: configService,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) list(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) list(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
ctx := r.Context()
|
||||
@@ -57,12 +57,12 @@ func (a *App) list(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) add(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) add(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
a.render.Render(ctx, w, config.Edit(ctx, &view.EditSysConfig{Config: &systemModel.Config{}}))
|
||||
}
|
||||
|
||||
func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) edit(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
vars := r.URL.Query()
|
||||
id := convertor.QueryInt[int32](vars, "id", 0)
|
||||
@@ -77,7 +77,7 @@ func (a *App) edit(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.Render(ctx, w, config.Edit(ctx, vm))
|
||||
}
|
||||
|
||||
func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) save(w http.ResponseWriter, r *http.Request) {
|
||||
id := convertor.ConvertInt[int32](r.PostFormValue("ID"), 0)
|
||||
key := r.PostFormValue("Key")
|
||||
value := r.PostFormValue("Value")
|
||||
@@ -125,7 +125,7 @@ func (a *App) save(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
key := r.FormValue("key")
|
||||
err := a.configService.RefreshCache(r.Context(), strings.ToLower(key))
|
||||
if err != nil {
|
||||
@@ -136,7 +136,7 @@ func (a *App) refreshCache(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "刷新成功")
|
||||
}
|
||||
|
||||
func (a *App) resetPear(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) resetPear(w http.ResponseWriter, r *http.Request) {
|
||||
err := a.configService.ResetPear(r.Context())
|
||||
if err != nil {
|
||||
a.render.JSONErr(w, err.Error())
|
||||
@@ -145,7 +145,7 @@ func (a *App) resetPear(w http.ResponseWriter, r *http.Request) {
|
||||
a.render.JSONOk(w, "重置成功")
|
||||
}
|
||||
|
||||
func (a *App) pear(w http.ResponseWriter, r *http.Request) {
|
||||
func (a *app) pear(w http.ResponseWriter, r *http.Request) {
|
||||
pear, err := a.configService.Pear(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -19,7 +19,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
func Routes(r chi.Router, cfg Config) {
|
||||
app := NewApp(cfg.Render, cfg.ConfigService)
|
||||
app := newApp(cfg.Render, cfg.ConfigService)
|
||||
|
||||
r.Get("/pear.json", app.pear)
|
||||
r.Route("/config", func(r chi.Router) {
|
||||
|
||||
Reference in New Issue
Block a user