go-playground/validator · error

tag '%s'不能用於struct類型.

Error message

tag '%s'不能用於struct類型.

What it means

Raised inside the Traditional Chinese 'lt' translation registration when the field under translation is a struct. Because lt is only meaningful for numbers, strings, slices/maps/arrays and time.Time, an arbitrary struct cannot be compared and the translator emits this error. It fires when a struct field other than time.Time carries the lt tag.

Source

Thrown at translations/zh_tw/zh_tw.go:481

				case reflect.Slice, reflect.Map, reflect.Array:
					var c string

					err = fn()
					if err != nil {
						goto END
					}

					c, err = ut.C("lt-items-item", f64, digits, ut.FmtNumber(f64, digits))
					if err != nil {
						goto END
					}

					t, err = ut.T("lt-items", fe.Field(), c)

				case reflect.Struct:
					if fe.Type() != reflect.TypeOf(time.Time{}) {
						err = fmt.Errorf("tag '%s'不能用於struct類型.", fe.Tag())
					} else {
						t, err = ut.T("lt-datetime", fe.Field())
					}

				default:
					err = fn()
					if err != nil {
						goto END
					}

					t, err = ut.T("lt-number", fe.Field(), ut.FmtNumber(f64, digits))
				}

			END:
				if err != nil {
					fmt.Printf("警告: 翻譯欄位錯誤: %s", err)
					return fe.(error).Error()
				}

View on GitHub (pinned to facf128d2e)

Solutions

  1. Remove the lt tag from the struct field
  2. Apply lt to the struct's comparable sub-fields
  3. Register a struct-level validation function for custom rules
  4. Ensure datetime fields are exactly time.Time
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at translations/zh_tw/zh_tw.go:481 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of go-playground/validator@facf128d2e (2026-09-02). Data as JSON: /api/errors/c10198f4d3389c42. Report an issue: GitHub.