blob: ea2a9d863822816df3e5722516f39cae55f51778 [file] [log] [blame]
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file contains the test for canonical struct tags.
package main
import (
// checkField checks a struct field tag.
func (f *File) checkCanonicalFieldTag(field *ast.Field) {
if field.Tag == nil {
tag, err := strconv.Unquote(field.Tag.Value)
if err != nil {
f.Warnf(field.Pos(), "unable to read struct tag %s", field.Tag.Value)
// Check tag for validity by appending
// new key:value to end and checking that
// the tag parsing code can find it.
if reflect.StructTag(tag+` _gofix:"_magic"`).Get("_gofix") != "_magic" {
f.Warnf(field.Pos(), "struct field tag %s not compatible with reflect.StructTag.Get", field.Tag.Value)