gofmt.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package tfelem
  2. import (
  3. "time"
  4. )
  5. const (
  6. GFL_ISO8601Date = "2006-01-02"
  7. GFL_ISO8601Time = "15:04:05"
  8. GFL_ISO8601Full = "2006-01-02T15:04:05-0700"
  9. GFL_CommonDatetime = "2006-01-02 15:04:05"
  10. GFL_NginxDefault = "02/Jan/2006:15:04:05 -0700"
  11. )
  12. type GoFormatElement struct {
  13. GoFmtLayout string
  14. }
  15. func (this *GoFormatElement) ExpectedSize() int {
  16. return len(this.GoFmtLayout)
  17. }
  18. func (this *GoFormatElement) PrintElement(t time.Time) string {
  19. return t.Format(this.GoFmtLayout)
  20. }
  21. func NewGoFormatElement(layout string) *GoFormatElement {
  22. return &GoFormatElement{
  23. GoFmtLayout: layout,
  24. }
  25. }
  26. func NewISO8601DateElement() *GoFormatElement {
  27. return &GoFormatElement{
  28. GoFmtLayout: GFL_ISO8601Date,
  29. }
  30. }
  31. func NewISO8601TimeElement() *GoFormatElement {
  32. return &GoFormatElement{
  33. GoFmtLayout: GFL_ISO8601Time,
  34. }
  35. }
  36. func NewISO8601FullElement() *GoFormatElement {
  37. return &GoFormatElement{
  38. GoFmtLayout: GFL_ISO8601Full,
  39. }
  40. }
  41. func NewCommonDatetimeElement() *GoFormatElement {
  42. return &GoFormatElement{
  43. GoFmtLayout: GFL_CommonDatetime,
  44. }
  45. }
  46. func NewRFC3339Element() *GoFormatElement {
  47. return &GoFormatElement{
  48. GoFmtLayout: time.RFC3339,
  49. }
  50. }
  51. func NewRFC3339NanoElement() *GoFormatElement {
  52. return &GoFormatElement{
  53. GoFmtLayout: time.RFC3339Nano,
  54. }
  55. }
  56. func NewNginxDefaultElement() *GoFormatElement {
  57. return &GoFormatElement{
  58. GoFmtLayout: GFL_NginxDefault,
  59. }
  60. }