/
manage_handler.go
49 lines (44 loc) · 1.11 KB
/
manage_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package handler
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"github.com/no-src/gofs/conf"
"github.com/no-src/gofs/contract"
"github.com/no-src/gofs/logger"
"github.com/no-src/gofs/server"
)
type manageHandler struct {
logger *logger.Logger
conf conf.Config
}
// NewManageHandlerFunc returns a gin.HandlerFunc that shows the application config
func NewManageHandlerFunc(logger *logger.Logger, conf conf.Config) gin.HandlerFunc {
return (&manageHandler{
logger: logger,
conf: conf,
}).Handle
}
func (h *manageHandler) Handle(c *gin.Context) {
format := strings.ToLower(c.Query(server.ParamFormat))
config := h.conf
mask := "******"
if len(config.Users) > 0 {
config.Users = mask
}
if len(config.SessionConnection) > 0 {
config.SessionConnection = mask
}
if len(config.EncryptSecret) > 0 {
config.EncryptSecret = mask
}
if len(config.DecryptSecret) > 0 {
config.DecryptSecret = mask
}
result := server.NewApiResult(contract.Success, contract.SuccessDesc, config)
if format == conf.YamlFormat.Name() {
c.YAML(http.StatusOK, result)
} else {
c.PureJSON(http.StatusOK, result)
}
}