mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-07 10:37:39 +08:00
first draft version
This commit is contained in:
33
server/setting.go
Normal file
33
server/setting.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"polaris/log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
||||
type setSettingIn struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
func (s *Server) SetSetting(c *gin.Context) (interface{}, error) {
|
||||
var in setSettingIn
|
||||
if err := c.ShouldBindJSON(&in); err != nil {
|
||||
return nil, errors.Wrap(err, "bind json")
|
||||
}
|
||||
err := s.db.SetSetting(in.Key, in.Value)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (s *Server) GetSetting(c *gin.Context) (interface{}, error) {
|
||||
q := c.Query("key")
|
||||
log.Infof("query key: %v", q)
|
||||
if q == "" {
|
||||
return nil, nil
|
||||
}
|
||||
v := s.db.GetSetting(q)
|
||||
log.Infof("get value for key %v: %v", q, v)
|
||||
return v, nil
|
||||
}
|
||||
Reference in New Issue
Block a user