MCPcopy Index your code
hub / github.com/TruthHun/BookStack / GetIP

Function GetIP

utils/util.go:960–983  ·  view source on GitHub ↗

获取ip地址

(ctx *context.Context, field string)

Source from the content-addressed store, hash-verified

958
959// 获取ip地址
960func GetIP(ctx *context.Context, field string) (ip string) {
961 ip = ctx.Request.Header.Get(field)
962 if ip != "" {
963 return
964 }
965 ip = ctx.Request.Header.Get("X-Real-Ip")
966 if ip != "" {
967 return
968 }
969 ip = ctx.Request.Header.Get("X-Forwarded-For")
970 if ip != "" {
971 return
972 }
973 ip = ctx.Request.Header.Get("Remote-Addr")
974 if ip != "" {
975 return
976 }
977
978 slice := strings.Split(ctx.Request.RemoteAddr, ":")
979 if len(slice) == 2 && !strings.Contains(ctx.Request.RemoteAddr, ",") {
980 return slice[0]
981 }
982 return
983}
984
985func IsMobile(userAgent string) bool {
986 return user_agent.New(userAgent).Mobile()

Callers 1

RegisterMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected