1 Star 11 Fork 3

ZX/php-code-generator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
function.go 1003 Bytes
一键复制 编辑 原始数据 按行查看 历史
ZX 提交于 2023-09-16 14:26 +08:00 . 增加goravel工具库
package utils
import (
"github.com/goravel/framework/contracts/http"
"goravel/app/utils/local"
"hash/crc32"
"strings"
"time"
)
func ErrorToString(r interface{}) string {
switch v := r.(type) {
case error:
return v.Error()
default:
return r.(string)
}
}
func CRC32(input string) uint32 {
bytes := []byte(input)
return crc32.ChecksumIEEE(bytes)
}
func GetIP(ctx http.Context) string {
ip := strings.TrimSpace(ctx.Request().Header("X-Forwarded-For", "127.0.0.1"))
if ip != "" {
return ip
}
ip = strings.TrimSpace(ctx.Request().Header("X-Real-Ip", "127.0.0.1"))
if ip != "" {
return ip
}
ip = strings.TrimSpace(ctx.Request().Ip())
if ip != "" {
return ip
}
return "127.0.0.1"
}
func TimeToLocalTime(t time.Time) (res local.LocalTime, err error) {
return local.LocalTime(t), nil
}
func LocalTimeToTime(t local.LocalTime) (res time.Time, err error) {
time, err := time.Parse("2006-01-02 15:04:05", t.String())
if err != nil {
return res, err
}
return time, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/open-php/php-code-generator.git
git@gitee.com:open-php/php-code-generator.git
open-php
php-code-generator
php-code-generator
v0.1.0

搜索帮助