This commit is contained in:
Enver Bisevac 2024-11-12 09:17:36 +02:00 committed by GitHub
commit 4dc3437861
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 2 deletions

View File

@ -318,7 +318,11 @@ func typeToStructTags(typ *runtime.Type) runtime.StructTags {
if runtime.IsIgnoredStructField(field) {
continue
}
tags = append(tags, runtime.StructTagFromField(field))
structTag := runtime.StructTagFromField(field)
if structTag.IsReadonly {
continue
}
tags = append(tags, structTag)
}
return tags
}

View File

@ -813,7 +813,11 @@ func (c *Compiler) typeToStructTags(typ *runtime.Type) runtime.StructTags {
if runtime.IsIgnoredStructField(field) {
continue
}
tags = append(tags, runtime.StructTagFromField(field))
structTag := runtime.StructTagFromField(field)
if structTag.IsWriteonly {
continue
}
tags = append(tags, structTag)
}
return tags
}

View File

@ -34,6 +34,8 @@ type StructTag struct {
IsTaggedKey bool
IsOmitEmpty bool
IsString bool
IsWriteonly bool
IsReadonly bool
Field reflect.StructField
}
@ -82,6 +84,10 @@ func StructTagFromField(field reflect.StructField) *StructTag {
switch opt {
case "omitempty":
st.IsOmitEmpty = true
case "readOnly":
st.IsReadonly = true
case "writeOnly":
st.IsWriteonly = true
case "string":
st.IsString = true
}