cFunc

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

README

常用函数

Documentation

Index

Constants

View Source
const TIME_STR = "2006-01-02 15:04:05"
View Source
const TIME_STRS = "2006-01-02 15:04"

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 Date

func Date(phpFormat string, stamp int64) string

Date 支持最常用的 Y-m-d H:i:s 2006-01-02 15:04:05 2006-01-02 15:04:05000 stamp 时间戳 如果为0则处理为当前时间

func GBK2UTF8

func GBK2UTF8(str []byte) ([]byte, error)

GBK2UTF8 gbk编码 转 utf8编码

func GetAppDir

func GetAppDir() string

GetAppDir 获取到可执行文件的绝对地址 调试环境下返回 源码的路径 正式环境下返回 可执行文件的路径 区分 go run 下执行 还是 go build 之后的可执行文件 按系统区分

func GetPost

func GetPost(method string, sUrl string, data map[string]string, head map[string]string, cookie []*http.Cookie) (string, error)

GetPost 发送get 或 post请求 获取数据

func GetPostRequest

func GetPostRequest(method string, sUrl string, data map[string]string, head map[string]string, cookie []*http.Cookie, redirect bool) (*http.Response, error)

GetPostRequest 发送get 或 post请求 获取数据 返回response和error

func Go added in v0.0.17

func Go(x func())

Go 用于开启一个goroutine

func InnerIP

func InnerIP(ip string) bool

InnerIP 判断是否为内网ip

func LocalIPV4

func LocalIPV4() string

LocalIPV4 获取本地IPv4地址

func Md5

func Md5(s string) string

func Mod

func Mod(id int64) int64

Mod 给数据库分表计算

func RandInt

func RandInt(start, end int64) (int64, error)

RandInt 生成随机数[n - m)

func RandInt2 added in v0.0.9

func RandInt2(start, end int64) int64

RandInt2 生成随机数[n - m)

func SignPost

func SignPost(domain string, key string, secret string, control string, method string, data map[string]string) (string, error)

SignPost 加密发送post请求到接口

func SortBuildQuery added in v0.0.17

func SortBuildQuery(data map[string]interface{}) string

SortBuildQuery 只支持一级 生成url 查询字符串

func StampToTimeStamp

func StampToTimeStamp(stamp int64, phpFormat string) int64

StampToTimeStamp 将时间戳 按指定格式 转换为新的时间戳 仅支持最常用的 Y-m-d H:i:s 仅支持最常用的 Y-m-d stamp 时间戳 如果为0则处理为当前时间

func StrToTime

func StrToTime(phpFormat string, timeStr string) int64

StrToTime 将时间字符串 转换为 时间戳 将时间戳 转换为 指定时间格式 对应的 时间戳 仅支持最常用的 Y-m-d H:i:s 仅支持最常用的 Y-m-d stamp 时间戳 如果为0则处理为当前时间

func Time

func Time() int64

Time 时间函数 参考PHP返回 Go的记起来有点累

func UTF82GBK

func UTF82GBK(str []byte) ([]byte, error)

UTF82GBK utf8编码 转 gbk编码

func WriteFile

func WriteFile(fileName string, content []byte) error

WriteFile 追加写入文件内容给 如果fileName为绝对路径则直接使用 如果为相对路径则获取当前程序路径

Types

This section is empty.

Jump to

Keyboard shortcuts

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