1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package server
- import (
- cert "cfTest/cloudflareApi/certificate"
- "fmt"
- "github.com/cloudflare/cloudflare-go"
- "time"
- )
- func Go2ProtoCertificate(goCertificate cloudflare.ZoneCustomSSL) *cert.ZoneCustomSSL {
- return &cert.ZoneCustomSSL{
- Id: goCertificate.ID,
- Hosts: goCertificate.Hosts,
- Issuer: goCertificate.Issuer,
- Signature: goCertificate.Signature,
- Status: goCertificate.Status,
- BundleMethod: goCertificate.BundleMethod,
- ZoneId: goCertificate.ZoneID,
- UploadedOn: timeConvert(goCertificate.UploadedOn.String()),
- ModifiedOn: timeConvert(goCertificate.ModifiedOn.String()),
- ExpiresOn: timeConvert(goCertificate.ExpiresOn.String()),
- Priority: int32(goCertificate.Priority),
- }
- }
- func timeConvert(input string) string {
- // API返回的时间字符串
- // 解析时间字符串,注意这里的布局字符串要与API返回的格式相匹配
- layout := "2006-01-02 15:04:05 -0700 MST"
- t, err := time.Parse(layout, input)
- if err != nil {
- fmt.Println("时间解析错误:", err)
- return input
- }
- // 转换为东八区时区
- location, err := time.LoadLocation("Asia/Shanghai")
- if err != nil {
- fmt.Println("时区加载错误:", err)
- return input
- }
- t = t.In(location)
- // 格式化时间为"2006-01-02 15:04:05"格式
- formattedTime := t.Format("2006-01-02 15:04:05")
- return formattedTime
- }
|