mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
- Introduced `usage-statistics-enabled` configuration to control in-memory usage aggregation. - Updated API to include handlers for managing `usage-statistics-enabled` and `logging-to-file` options. - Enhanced `watcher` to log changes to both configurations dynamically. - Updated documentation and examples to reflect new configuration options.
54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package management
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (h *Handler) GetConfig(c *gin.Context) {
|
|
c.JSON(200, h.cfg)
|
|
}
|
|
|
|
// Debug
|
|
func (h *Handler) GetDebug(c *gin.Context) { c.JSON(200, gin.H{"debug": h.cfg.Debug}) }
|
|
func (h *Handler) PutDebug(c *gin.Context) { h.updateBoolField(c, func(v bool) { h.cfg.Debug = v }) }
|
|
|
|
// UsageStatisticsEnabled
|
|
func (h *Handler) GetUsageStatisticsEnabled(c *gin.Context) {
|
|
c.JSON(200, gin.H{"usage-statistics-enabled": h.cfg.UsageStatisticsEnabled})
|
|
}
|
|
func (h *Handler) PutUsageStatisticsEnabled(c *gin.Context) {
|
|
h.updateBoolField(c, func(v bool) { h.cfg.UsageStatisticsEnabled = v })
|
|
}
|
|
|
|
// UsageStatisticsEnabled
|
|
func (h *Handler) GetLoggingToFile(c *gin.Context) {
|
|
c.JSON(200, gin.H{"logging-to-file": h.cfg.LoggingToFile})
|
|
}
|
|
func (h *Handler) PutLoggingToFile(c *gin.Context) {
|
|
h.updateBoolField(c, func(v bool) { h.cfg.LoggingToFile = v })
|
|
}
|
|
|
|
// Request log
|
|
func (h *Handler) GetRequestLog(c *gin.Context) { c.JSON(200, gin.H{"request-log": h.cfg.RequestLog}) }
|
|
func (h *Handler) PutRequestLog(c *gin.Context) {
|
|
h.updateBoolField(c, func(v bool) { h.cfg.RequestLog = v })
|
|
}
|
|
|
|
// Request retry
|
|
func (h *Handler) GetRequestRetry(c *gin.Context) {
|
|
c.JSON(200, gin.H{"request-retry": h.cfg.RequestRetry})
|
|
}
|
|
func (h *Handler) PutRequestRetry(c *gin.Context) {
|
|
h.updateIntField(c, func(v int) { h.cfg.RequestRetry = v })
|
|
}
|
|
|
|
// Proxy URL
|
|
func (h *Handler) GetProxyURL(c *gin.Context) { c.JSON(200, gin.H{"proxy-url": h.cfg.ProxyURL}) }
|
|
func (h *Handler) PutProxyURL(c *gin.Context) {
|
|
h.updateStringField(c, func(v string) { h.cfg.ProxyURL = v })
|
|
}
|
|
func (h *Handler) DeleteProxyURL(c *gin.Context) {
|
|
h.cfg.ProxyURL = ""
|
|
h.persist(c)
|
|
}
|