Ai
3 Star 11 Fork 3

os-lee/easy-paas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
func.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
lee 提交于 2024-10-05 10:28 +08:00 . 使用docker获取节点和容器信息
package common
import (
"crypto/md5"
"fmt"
"io"
"net/url"
"reflect"
"time"
)
// MD5 md5加密
func MD5(s string) string {
h := md5.New()
io.WriteString(h, s)
return fmt.Sprintf("%x", h.Sum(nil))
}
// ProtocolConverter 协议转换器
func ProtocolConverter(protocolType int) string {
var schema string
switch protocolType {
case ProtocolTypeHttp:
schema = "http://"
case ProtocolTypeHttps:
schema = "https://"
case ProtocolTypeWebSocket:
schema = "ws://"
default:
schema = ""
}
return schema
}
func MustParseURL(s string) *url.URL {
u, err := url.Parse(s)
if err != nil {
panic(err)
}
return u
}
func SumArray(numbers []int64) int64 {
var sum int64
for _, number := range numbers {
sum += number
}
return sum
}
// DiffTime 计算两个时间点之间的差异,并返回天数、小时数、分钟数和秒数。
func DiffTime(t1, t2 time.Time) (days int, hours int, minutes int, seconds int) {
diff := t2.Sub(t1)
// 计算总秒数
totalSeconds := int(diff.Seconds())
// 计算天数
days = totalSeconds / (24 * 60 * 60)
// 计算剩余的秒数
remainingSeconds := totalSeconds % (24 * 60 * 60)
// 计算小时数
hours = remainingSeconds / (60 * 60)
// 计算剩余的秒数
remainingSeconds %= 60 * 60
// 计算分钟数
minutes = remainingSeconds / 60
// 计算剩余的秒数
seconds = remainingSeconds % 60
return days, hours, minutes, seconds
}
func PrintFields(s interface{}) {
v := reflect.ValueOf(s)
if v.Kind() == reflect.Ptr {
v = v.Elem()
}
if v.Kind() != reflect.Struct {
fmt.Println("Not a struct")
return
}
t := v.Type()
for i := 0; i < v.NumField(); i++ {
f := v.Field(i)
fmt.Printf("%s: %v\n", t.Field(i).Name, f.Interface())
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/os-lee/easy-paas.git
git@gitee.com:os-lee/easy-paas.git
os-lee
easy-paas
easy-paas
6cf1638f64c0

搜索帮助