utils

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

go-utils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func GetResponseBodyFormUrl

func GetResponseBodyFormUrl(method, reqUrl string, customHeader map[string]string, reqBody io.Reader, useProxy bool) ([]byte, error)

func HttpProxyClient

func HttpProxyClient() *http.Client

func JsonUnmarshalByJsonFile

func JsonUnmarshalByJsonFile(jsonPath string, v any) error

JsonUnmarshalByJsonFile 从JSON文件中反序列化JSON数据

func JsonUnmarshalByURL

func JsonUnmarshalByURL(method, reqUrl string, customHeader map[string]string, reqBody io.Reader, useProxy bool, v any) error

JsonUnmarshalByURL 从URL请求中反序列化JSON数据

func RemoteIP

func RemoteIP(r *http.Request) string

RemoteIP 通过 RemoteAddr 获取 IP 地址, 只是一个快速解析方法。

func UniqueSlice

func UniqueSlice[T string | ~int](repeatedSlice []T) []T

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL