fix: get userAgent and IP from custom header
This commit is contained in:
parent
0c8133c802
commit
8d7500610e
@ -7,7 +7,6 @@ import (
|
|||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
@ -58,17 +57,11 @@ func CreateLogAds(
|
|||||||
specReq.UserID = &userDetail.ID
|
specReq.UserID = &userDetail.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := r.RemoteAddr
|
if ip := r.Header.Get("X-Ip-Address"); ip != "" {
|
||||||
|
|
||||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
|
||||||
ip = strings.Split(forwarded, ",")[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ip != "" {
|
|
||||||
specReq.IP = &ip
|
specReq.IP = &ip
|
||||||
}
|
}
|
||||||
|
|
||||||
if userAgent := r.UserAgent(); userAgent != "" {
|
if userAgent := r.Header.Get("X-User-Agent"); userAgent != "" {
|
||||||
specReq.UserAgent = &userAgent
|
specReq.UserAgent = &userAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import (
|
|||||||
"legalgo-BE-go/internal/utilities/response"
|
"legalgo-BE-go/internal/utilities/response"
|
||||||
"legalgo-BE-go/internal/utilities/utils"
|
"legalgo-BE-go/internal/utilities/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
@ -45,17 +44,11 @@ func GetBySlug(
|
|||||||
specReq.UserID = &userDetail.ID
|
specReq.UserID = &userDetail.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := r.RemoteAddr
|
if ip := r.Header.Get("X-Ip-Address"); ip != "" {
|
||||||
|
|
||||||
if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" {
|
|
||||||
ip = strings.Split(forwarded, ",")[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ip != "" {
|
|
||||||
specReq.IP = &ip
|
specReq.IP = &ip
|
||||||
}
|
}
|
||||||
|
|
||||||
if userAgent := r.UserAgent(); userAgent != "" {
|
if userAgent := r.Header.Get("X-User-Agent"); userAgent != "" {
|
||||||
specReq.UserAgent = &userAgent
|
specReq.UserAgent = &userAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user