Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsanaei <ho3ein.sanaei@gmail.com>2025-09-20 10:35:50 +0300
committermhsanaei <ho3ein.sanaei@gmail.com>2025-09-20 10:35:50 +0300
commit6ced549deaecb42b9bb93ea9efcb4c1bbaabe8a4 (patch)
tree28d8d82530476cf607e4d05ca189ae05868711e6 /web/controller/util.go
parentf60682a6b7cb749fee403c84e2587c3ad7e7ced0 (diff)
docs: add comments for all functions
Diffstat (limited to 'web/controller/util.go')
-rw-r--r--web/controller/util.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/web/controller/util.go b/web/controller/util.go
index e180b1fe..b11203bd 100644
--- a/web/controller/util.go
+++ b/web/controller/util.go
@@ -12,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
)
+// getRemoteIp extracts the real IP address from the request headers or remote address.
func getRemoteIp(c *gin.Context) string {
value := c.GetHeader("X-Real-IP")
if value != "" {
@@ -27,14 +28,17 @@ func getRemoteIp(c *gin.Context) string {
return ip
}
+// jsonMsg sends a JSON response with a message and error status.
func jsonMsg(c *gin.Context, msg string, err error) {
jsonMsgObj(c, msg, nil, err)
}
+// jsonObj sends a JSON response with an object and error status.
func jsonObj(c *gin.Context, obj any, err error) {
jsonMsgObj(c, "", obj, err)
}
+// jsonMsgObj sends a JSON response with a message, object, and error status.
func jsonMsgObj(c *gin.Context, msg string, obj any, err error) {
m := entity.Msg{
Obj: obj,
@@ -52,6 +56,7 @@ func jsonMsgObj(c *gin.Context, msg string, obj any, err error) {
c.JSON(http.StatusOK, m)
}
+// pureJsonMsg sends a pure JSON message response with custom status code.
func pureJsonMsg(c *gin.Context, statusCode int, success bool, msg string) {
c.JSON(statusCode, entity.Msg{
Success: success,
@@ -59,6 +64,7 @@ func pureJsonMsg(c *gin.Context, statusCode int, success bool, msg string) {
})
}
+// html renders an HTML template with the provided data and title.
func html(c *gin.Context, name string, title string, data gin.H) {
if data == nil {
data = gin.H{}
@@ -81,6 +87,7 @@ func html(c *gin.Context, name string, title string, data gin.H) {
c.HTML(http.StatusOK, name, getContext(data))
}
+// getContext adds version and other context data to the provided gin.H.
func getContext(h gin.H) gin.H {
a := gin.H{
"cur_ver": config.GetVersion(),
@@ -91,6 +98,7 @@ func getContext(h gin.H) gin.H {
return a
}
+// isAjax checks if the request is an AJAX request.
func isAjax(c *gin.Context) bool {
return c.GetHeader("X-Requested-With") == "XMLHttpRequest"
}