api-server/api/network/service/network_service.go

31 lines
776 B
Go
Raw Normal View History

2024-09-24 05:31:28 +00:00
package service
import (
"api/api/network/model/resp"
"github.com/gin-gonic/gin"
)
// NetWorkService 网络服务
type NetWorkService struct{}
func (NetWorkService) GetHeaders(c *gin.Context) resp.HeadersResp {
// 获取所有的请求头
request := c.Request
headers := request.Header
clientIP := c.ClientIP()
// 将请求头转换为 map[string]string
headersMap := make(map[string]string)
for key, value := range headers {
headersMap[key] = value[0] // 注意,这里假设每个键只有一个值,你可以根据实际情况修改逻辑
}
headersMap["platform"] = headers.Get("Sec-CH-UA-Platform")
headersMap["model"] = headers.Get("Sec-CH-UA-Model")
result := resp.HeadersResp{}
result.IP = clientIP
result.Headers = headersMap
return result
}