Struct field tag not compatible with reflect.StructTag.Get: bad syntax for struct tag pair

I’ve the below code:

package main

import (

type User struct {
	Name string `name`
	Age  int64  `age`

func main() {
	var u User = User{"bob", 10}

	res, err := JSONEncode(u)
	if err != nil {


func JSONEncode(v interface{}) ([]byte, error) {
	refObjVal := reflect.ValueOf(v)
	refObjTyp := reflect.TypeOf(v)
	buf := bytes.Buffer{}
	if refObjVal.Kind() != reflect.Struct {
		return buf.Bytes(), fmt.Errorf(
			"val of kind %s is not supported",
	pairs := []string{}
	for i := 0; i < refObjVal.NumField(); i++ {
		structFieldRefObj := refObjVal.Field(i)
		structFieldRefObjTyp := refObjTyp.Field(i)

		switch structFieldRefObj.Kind() {
		case reflect.String:
			strVal := structFieldRefObj.Interface().(string)
			pairs = append(pairs, `"`+string(structFieldRefObjTyp.Tag)+`":"`+strVal+`"`)
		case reflect.Int64:
			intVal := structFieldRefObj.Interface().(int64)
			pairs = append(pairs, `"`+string(structFieldRefObjTyp.Tag)+`":`+strconv.FormatInt(intVal, 10))
			return buf.Bytes(), fmt.Errorf(
				"struct field with name %s and kind %s is not supprted",

	buf.WriteString(strings.Join(pairs, ","))

	return buf.Bytes(), nil

It works perfectly, and give output as:


But as VS code, it gives me the below problems:

enter image description here

What could be the issue?

I aware that Struct tag supposed to be a key:"value", field:"name", and tried:

type User struct {
    Name string `field:"name"`
    Age  int64  `field:"age"`

But the output this time was wrong, I got:


You have to specify tags using the correct syntax (pair quotes and simicolons):

type User struct {
	Name string `name:"welcome"`
	Age  int64  `age:"hello"`

I got the answer at stackoverflow , and copying it here for the benefit of the community.

Note that that’s just a warning telling you that you’re not following convention. The code, as you already know, compiles and runs and outputs the result you want: Go Playground - The Go Programming Language.

To avoid the warning, disable your linter, or, better yet, follow the convention by using key:"value" in the struct tags and then extract the value by using the Get method: Go Playground - The Go Programming Language.

A StructTag is the tag string in a struct field.

By convention, tag strings are a concatenation of optionally
space-separated key:“value” pairs.
Each key is a non-empty string
consisting of non-control characters other than space (U+0020 ’ '),
quote (U+0022 ‘"’), and colon (U+003A ‘:’). Each value is quoted using
U+0022 ‘"’ characters and Go string literal syntax.