Certificate_convert.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package server
  2. import (
  3. cert "cfTest/cloudflareApi/certificate"
  4. "fmt"
  5. "github.com/cloudflare/cloudflare-go"
  6. "time"
  7. )
  8. func Go2ProtoCertificate(goCertificate cloudflare.ZoneCustomSSL) *cert.ZoneCustomSSL {
  9. return &cert.ZoneCustomSSL{
  10. Id: goCertificate.ID,
  11. Hosts: goCertificate.Hosts,
  12. Issuer: goCertificate.Issuer,
  13. Signature: goCertificate.Signature,
  14. Status: goCertificate.Status,
  15. BundleMethod: goCertificate.BundleMethod,
  16. ZoneId: goCertificate.ZoneID,
  17. UploadedOn: timeConvert(goCertificate.UploadedOn.String()),
  18. ModifiedOn: timeConvert(goCertificate.ModifiedOn.String()),
  19. ExpiresOn: timeConvert(goCertificate.ExpiresOn.String()),
  20. Priority: int32(goCertificate.Priority),
  21. }
  22. }
  23. func timeConvert(input string) string {
  24. // API返回的时间字符串
  25. // 解析时间字符串,注意这里的布局字符串要与API返回的格式相匹配
  26. layout := "2006-01-02 15:04:05 -0700 MST"
  27. t, err := time.Parse(layout, input)
  28. if err != nil {
  29. fmt.Println("时间解析错误:", err)
  30. return input
  31. }
  32. // 转换为东八区时区
  33. location, err := time.LoadLocation("Asia/Shanghai")
  34. if err != nil {
  35. fmt.Println("时区加载错误:", err)
  36. return input
  37. }
  38. t = t.In(location)
  39. // 格式化时间为"2006-01-02 15:04:05"格式
  40. formattedTime := t.Format("2006-01-02 15:04:05")
  41. return formattedTime
  42. }