helper.go 618 B

1234567891011121314151617181920212223242526272829
  1. package controller
  2. import (
  3. "strconv"
  4. "time"
  5. "github.com/gin-gonic/gin"
  6. )
  7. const timeFormat = "2006-01-02T15:04:05Z07:00"
  8. // parseUintParam 将路径参数转换为 uint64。
  9. func parseUintParam(c *gin.Context, name string) (uint64, error) {
  10. value := c.Param(name)
  11. return strconv.ParseUint(value, 10, 64)
  12. }
  13. // formatTimeValue 按统一格式输出时间字符串。
  14. func formatTimeValue(t time.Time) string {
  15. return t.Format(timeFormat)
  16. }
  17. // formatTimePointer 在指针为空时返回空字符串。
  18. func formatTimePointer(t *time.Time) string {
  19. if t == nil {
  20. return ""
  21. }
  22. return t.Format(timeFormat)
  23. }