You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
4.7 KiB

  1. # Go App Engine packages
  2. [![Build Status](https://travis-ci.org/golang/appengine.svg)](https://travis-ci.org/golang/appengine)
  3. This repository supports the Go runtime on *App Engine standard*.
  4. It provides APIs for interacting with App Engine services.
  5. Its canonical import path is `google.golang.org/appengine`.
  6. See https://cloud.google.com/appengine/docs/go/
  7. for more information.
  8. File issue reports and feature requests on the [GitHub's issue
  9. tracker](https://github.com/golang/appengine/issues).
  10. ## Upgrading an App Engine app to the flexible environment
  11. This package does not work on *App Engine flexible*.
  12. There are many differences between the App Engine standard environment and
  13. the flexible environment.
  14. See the [documentation on upgrading to the flexible environment](https://cloud.google.com/appengine/docs/flexible/go/upgrading).
  15. ## Directory structure
  16. The top level directory of this repository is the `appengine` package. It
  17. contains the
  18. basic APIs (e.g. `appengine.NewContext`) that apply across APIs. Specific API
  19. packages are in subdirectories (e.g. `datastore`).
  20. There is an `internal` subdirectory that contains service protocol buffers,
  21. plus packages required for connectivity to make API calls. App Engine apps
  22. should not directly import any package under `internal`.
  23. ## Updating from legacy (`import "appengine"`) packages
  24. If you're currently using the bare `appengine` packages
  25. (that is, not these ones, imported via `google.golang.org/appengine`),
  26. then you can use the `aefix` tool to help automate an upgrade to these packages.
  27. Run `go get google.golang.org/appengine/cmd/aefix` to install it.
  28. ### 1. Update import paths
  29. The import paths for App Engine packages are now fully qualified, based at `google.golang.org/appengine`.
  30. You will need to update your code to use import paths starting with that; for instance,
  31. code importing `appengine/datastore` will now need to import `google.golang.org/appengine/datastore`.
  32. ### 2. Update code using deprecated, removed or modified APIs
  33. Most App Engine services are available with exactly the same API.
  34. A few APIs were cleaned up, and there are some differences:
  35. * `appengine.Context` has been replaced with the `Context` type from `golang.org/x/net/context`.
  36. * Logging methods that were on `appengine.Context` are now functions in `google.golang.org/appengine/log`.
  37. * `appengine.Timeout` has been removed. Use `context.WithTimeout` instead.
  38. * `appengine.Datacenter` now takes a `context.Context` argument.
  39. * `datastore.PropertyLoadSaver` has been simplified to use slices in place of channels.
  40. * `delay.Call` now returns an error.
  41. * `search.FieldLoadSaver` now handles document metadata.
  42. * `urlfetch.Transport` no longer has a Deadline field; set a deadline on the
  43. `context.Context` instead.
  44. * `aetest` no longer declares its own Context type, and uses the standard one instead.
  45. * `taskqueue.QueueStats` no longer takes a maxTasks argument. That argument has been
  46. deprecated and unused for a long time.
  47. * `appengine.BackendHostname` and `appengine.BackendInstance` were for the deprecated backends feature.
  48. Use `appengine.ModuleHostname`and `appengine.ModuleName` instead.
  49. * Most of `appengine/file` and parts of `appengine/blobstore` are deprecated.
  50. Use [Google Cloud Storage](https://godoc.org/cloud.google.com/go/storage) if the
  51. feature you require is not present in the new
  52. [blobstore package](https://google.golang.org/appengine/blobstore).
  53. * `appengine/socket` is not required on App Engine flexible environment / Managed VMs.
  54. Use the standard `net` package instead.
  55. ## Key Encode/Decode compatibiltiy to help with datastore library migrations
  56. Key compatibility updates have been added to help customers transition from google.golang.org/appengine/datastore to cloud.google.com/go/datastore.
  57. The `EnableKeyConversion` enables automatic conversion from a key encoded with cloud.google.com/go/datastore to google.golang.org/appengine/datastore key type.
  58. ### Enabling key conversion
  59. Enable key conversion by calling `EnableKeyConversion(ctx)` in the `/_ah/start` handler for basic and manual scaling or any handler in automatic scaling.
  60. #### 1. Basic or manual scaling
  61. This start handler will enable key conversion for all handlers in the service.
  62. ```
  63. http.HandleFunc("/_ah/start", func(w http.ResponseWriter, r *http.Request) {
  64. datastore.EnableKeyConversion(appengine.NewContext(r))
  65. })
  66. ```
  67. #### 2. Automatic scaling
  68. `/_ah/start` is not supported for automatic scaling and `/_ah/warmup` is not guaranteed to run, so you must call `datastore.EnableKeyConversion(appengine.NewContext(r))`
  69. before you use code that needs key conversion.
  70. You may want to add this to each of your handlers, or introduce middleware where it's called.
  71. `EnableKeyConversion` is safe for concurrent use. Any call to it after the first is ignored.