| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package rawdatastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "math" | 10 "math" |
| 11 "reflect" | 11 "reflect" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "github.com/luci/gae/service/blobstore" | 14 "github.com/luci/gae/service/blobstore" |
| 15 ) | 15 ) |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // occur, error will be a MultiError containing one or more ErrFieldMism
atch | 324 // occur, error will be a MultiError containing one or more ErrFieldMism
atch |
| 325 // objects. | 325 // objects. |
| 326 Load(PropertyMap) error | 326 Load(PropertyMap) error |
| 327 | 327 |
| 328 // Save returns the current property as a PropertyMap. if withMeta is tr
ue, | 328 // Save returns the current property as a PropertyMap. if withMeta is tr
ue, |
| 329 // then the PropertyMap contains all the metadata (e.g. '$meta' fields) | 329 // then the PropertyMap contains all the metadata (e.g. '$meta' fields) |
| 330 // which was held by this PropertyLoadSaver. | 330 // which was held by this PropertyLoadSaver. |
| 331 Save(withMeta bool) (PropertyMap, error) | 331 Save(withMeta bool) (PropertyMap, error) |
| 332 | 332 |
| 333 // GetMeta will get information about the field which has the struct tag
in | 333 // GetMeta will get information about the field which has the struct tag
in |
| 334 » // the form of `gae:"$<key>[,<value>]?"`. | 334 » // the form of `gae:"$<key>[,<default>]?"`. |
| 335 // | 335 // |
| 336 » // string and int64 fields will return the <value> in the struct tag, | 336 » // Supported metadata types are: |
| 337 » // converted to the appropriate type, if the field has the zero value. | 337 » // int64 - may have default (ascii encoded base-10) |
| 338 » // string - may have default |
| 339 » // Toggle - MUST have default ("true" or "false") |
| 340 » // Key - NO default allowed |
| 338 // | 341 // |
| 342 // Struct fields of type Toggle (which is an Auto/On/Off) require you to |
| 343 // specify a value of 'true' or 'false' for the default value of the str
uct |
| 344 // tag, and GetMeta will return the combined value as a regular boolean
true |
| 345 // or false value. |
| 339 // Example: | 346 // Example: |
| 340 // type MyStruct struct { | 347 // type MyStruct struct { |
| 341 // CoolField int64 `gae:"$id,1"` | 348 // CoolField int64 `gae:"$id,1"` |
| 342 // } | 349 // } |
| 343 // val, err := helper.GetPLS(&MyStruct{}).GetMeta("id") | 350 // val, err := helper.GetPLS(&MyStruct{}).GetMeta("id") |
| 344 // // val == 1 | 351 // // val == 1 |
| 345 // // err == nil | 352 // // err == nil |
| 346 // | 353 // |
| 347 // val, err := helper.GetPLS(&MyStruct{10}).GetMeta("id") | 354 // val, err := helper.GetPLS(&MyStruct{10}).GetMeta("id") |
| 348 // // val == 10 | 355 // // val == 10 |
| 349 // // err == nil | 356 // // err == nil |
| 350 // | 357 // |
| 351 // Struct fields of type Toggle (which is an Auto/On/Off) allow you to | |
| 352 // specify a value of 'true' or 'false' for the default value of the str
uct | |
| 353 // tag, and GetMeta will return the combined value as a regular boolean
true | |
| 354 // or false value. If a field is Toggle, a <value> MUST be specified. | |
| 355 // | |
| 356 // Example: | |
| 357 // type MyStruct struct { | 358 // type MyStruct struct { |
| 358 // TFlag Toggle `gae:"$flag1,true"` // defaults to true | 359 // TFlag Toggle `gae:"$flag1,true"` // defaults to true |
| 359 // FFlag Toggle `gae:"$flag2,false"` // defaults to false | 360 // FFlag Toggle `gae:"$flag2,false"` // defaults to false |
| 360 // // BadFlag Toggle `gae:"$flag3"` // ILLEGAL | 361 // // BadFlag Toggle `gae:"$flag3"` // ILLEGAL |
| 361 // } | 362 // } |
| 362 GetMeta(key string) (interface{}, error) | 363 GetMeta(key string) (interface{}, error) |
| 363 | 364 |
| 364 // SetMeta allows you to set the current value of the meta-keyed field. | 365 // SetMeta allows you to set the current value of the meta-keyed field. |
| 365 SetMeta(key string, val interface{}) error | 366 SetMeta(key string, val interface{}) error |
| 366 | 367 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 return err | 443 return err |
| 443 } | 444 } |
| 444 pm["$"+key] = []Property{prop} | 445 pm["$"+key] = []Property{prop} |
| 445 return nil | 446 return nil |
| 446 } | 447 } |
| 447 | 448 |
| 448 // Problem implements PropertyLoadSaver.Problem. It ALWAYS returns nil. | 449 // Problem implements PropertyLoadSaver.Problem. It ALWAYS returns nil. |
| 449 func (pm PropertyMap) Problem() error { | 450 func (pm PropertyMap) Problem() error { |
| 450 return nil | 451 return nil |
| 451 } | 452 } |
| OLD | NEW |