You can't because in Go types do not have constructors.
Instead, have either an explicit initializer function (or method on the pointer receiver) or a constructor/factory function (these are conventionally called New<TypeName>
so yours would be NewFileData
) which would return an initialized value of your type.
All-in-all, I have a feeling this looks like an XY problem. From your question, it appears you want to have a default value on one of your fields if nothing was unmarshaled.
If so, just post-process the values of this type unmarshaled from JSON and if nothing was unmarshaled to Encodning
set it to whatever default you want.
Alternatively you might consider this approach:
-
Have a custom type for your field.
Something like type EncodingMethod string
should do.
Have a custom JSON unmarshaling method for this type which would do whatever handling it wants.