Closed bashtian closed 7 years ago
We have a struct field tag which may solve your issue in the cloud.google.com/go/datastore package, datastore:",omitempty"
. If you can migrate you code over to using that package instead, this might work well for you.
Otherwise, I suggest implementing the PropertyLoadSaver interface yourself. You could use the default implementations of Load and Save, and to fall back to your special implementation when you get the "no such struct field" error.
datastore:",omitempty"
would be perfect, unfortunately changing the package is not an option at the moment. Are there plans to port this to the appengine/datastore package?
just out of curiosity, is cloud.google.com/go/xxx
going to replace these packages? aka. are they the preferred packages to use, even when working with appengine standard?
@fredr While cloud.google.com/go may largely run on App Engine Standard, for best performance and compatibility we recommend using the libraries at google.golang.org/appengine. These libraries are, and will continue to be, fully supported on this environment.
@bashtian we do not have plans to port datastore:",omitempty"
to the appengine datastore package due to lack of engineering resources. However, if you have the time and want to submit a pull request yourself, we'd welcome it! Check out the CONTRIBUTING.md at the root of this project.
For reference, the cloud.google.com/go/datastore package is almost identical in implementation to this package, and the relevant commit in cloud.google.com/go/datastore is https://github.com/GoogleCloudPlatform/google-cloud-go/commit/94f177402d59546c5639e015376f04a6a92b02
Right now a struct field needs to have the tag
datastore:"-"
to disable saving in the datastore. The problem is that it also disables loading of the field, which makes migrations hard because now I always get the error "no such struct field".A better way would be to only disable saving of field, e.g. with
datastore:",nosave"
ordatastore:",deprecated"
. This would make migrations a lot easier because I don't have to check for the error everywhere I load the struct.