Codebase list golang-google-appengine / 0c7f7a8
run gofmt with go1.19 release candidate (#282) Zev Goldstein authored 1 year, 10 months ago GitHub committed 1 year, 10 months ago
48 changed file(s) with 119 addition(s) and 90 deletion(s). Raw diff Collapse all Expand all
0 //go:build appengine
01 // +build appengine
12
23 package aetest
1213 var aeOpts *aetest.Options
1314 if opts != nil {
1415 aeOpts = &aetest.Options{
15 AppID: opts.AppID,
16 AppID: opts.AppID,
1617 StronglyConsistentDatastore: opts.StronglyConsistentDatastore,
1718 }
1819 }
0 //go:build !appengine
01 // +build !appengine
12
23 package aetest
3434 //
3535 // Main is designed so that the app's main package looks like this:
3636 //
37 // package main
37 // package main
3838 //
39 // import (
40 // "google.golang.org/appengine"
39 // import (
40 // "google.golang.org/appengine"
4141 //
42 // _ "myapp/package0"
43 // _ "myapp/package1"
44 // )
42 // _ "myapp/package0"
43 // _ "myapp/package1"
44 // )
4545 //
46 // func main() {
47 // appengine.Main()
48 // }
46 // func main() {
47 // appengine.Main()
48 // }
4949 //
5050 // The "myapp/packageX" packages are expected to register HTTP handlers
5151 // in their init functions.
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package appengine
88 This package does not work in App Engine "flexible environment".
99
1010 Example:
11
1112 if !capability.Enabled(c, "datastore_v3", "write") {
1213 // show user a different page
1314 }
1313
1414 A Go MySQL driver that has been tested to work well with Cloud SQL
1515 is the go-sql-driver:
16
1617 import "database/sql"
1718 import _ "github.com/go-sql-driver/mysql"
1819
1920 db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname")
2021
22 Another driver that works well with Cloud SQL is the mymysql driver:
2123
22 Another driver that works well with Cloud SQL is the mymysql driver:
2324 import "database/sql"
2425 import _ "github.com/ziutek/mymysql/godrv"
2526
2627 db, err := sql.Open("mymysql", "cloudsql:instance-name*dbname/user/password")
27
2828
2929 Using either of these drivers, you can perform a standard SQL query.
3030 This example assumes there is a table named 'users' with
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appengine
45 // +build appengine
56
67 package cloudsql
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package cloudsql
77 // A main func is synthesized if one does not exist.
88 //
99 // A sample Dockerfile to be used with this bundler could look like this:
10 // FROM gcr.io/google-appengine/go-compat
11 // ADD . /app
12 // RUN GOPATH=/app/_gopath go build -tags appenginevm -o /app/_ah/exe
10 //
11 // FROM gcr.io/google-appengine/go-compat
12 // ADD . /app
13 // RUN GOPATH=/app/_gopath go build -tags appenginevm -o /app/_ah/exe
1314 package main
1415
1516 import (
44 /*
55 Package datastore provides a client for App Engine's datastore service.
66
7
8 Basic Operations
7 # Basic Operations
98
109 Entities are the unit of storage and are associated with a key. A key
1110 consists of an optional parent key, a string application ID, a string kind
7372 Delete functions. They take a []*Key instead of a *Key, and may return an
7473 appengine.MultiError when encountering partial failure.
7574
76
77 Properties
75 # Properties
7876
7977 An entity's contents can be represented by a variety of types. These are
8078 typically struct pointers, but can also be any type that implements the
136134 J int `datastore:",noindex" json:"j"`
137135 }
138136
139
140 Structured Properties
137 # Structured Properties
141138
142139 If the struct pointed to contains other structs, then the nested or embedded
143140 structs are flattened. For example, given these definitions:
178175 If an outer struct is tagged "noindex" then all of its implicit flattened
179176 fields are effectively "noindex".
180177
181
182 The PropertyLoadSaver Interface
178 # The PropertyLoadSaver Interface
183179
184180 An entity's contents can also be represented by any type that implements the
185181 PropertyLoadSaver interface. This type may be a struct pointer, but it does
229225 The *PropertyList type implements PropertyLoadSaver, and can therefore hold an
230226 arbitrary entity's contents.
231227
232
233 Queries
228 # Queries
234229
235230 Queries retrieve entities based on their properties or key's ancestry. Running
236231 a query yields an iterator of results: either keys or (key, entity) pairs.
283278 io.Copy(w, b)
284279 }
285280
286
287 Transactions
281 # Transactions
288282
289283 RunInTransaction runs a function in a transaction.
290284
322316 fmt.Fprintf(w, "Count=%d", count)
323317 }
324318
325
326 Metadata
319 # Metadata
327320
328321 The datastore package provides access to some of App Engine's datastore
329322 metadata. This metadata includes information about the entity groups,
4949 // The properties are returned as a map of property names to a slice of the
5050 // representation types. The representation types for the supported Go property
5151 // types are:
52 // "INT64": signed integers and time.Time
53 // "DOUBLE": float32 and float64
54 // "BOOLEAN": bool
55 // "STRING": string, []byte and ByteString
56 // "POINT": appengine.GeoPoint
57 // "REFERENCE": *Key
58 // "USER": (not used in the Go runtime)
52 //
53 // "INT64": signed integers and time.Time
54 // "DOUBLE": float32 and float64
55 // "BOOLEAN": bool
56 // "STRING": string, []byte and ByteString
57 // "POINT": appengine.GeoPoint
58 // "REFERENCE": *Key
59 // "USER": (not used in the Go runtime)
5960 func KindProperties(ctx context.Context, kind string) (map[string][]string, error) {
6061 // TODO(djd): Support range queries.
6162 kindKey := NewKey(ctx, kindKind, kind, 0, nil)
475475 // The keys returned by GetAll will be in a 1-1 correspondence with the entities
476476 // added to dst.
477477 //
478 // If q is a ``keys-only'' query, GetAll ignores dst and only returns the keys.
478 // If q is a “keys-only” query, GetAll ignores dst and only returns the keys.
479479 //
480480 // The running time and number of API calls made by GetAll scale linearly with
481481 // the sum of the query's offset and limit. Unless the result count is
99 in a top-level assignment context, passing it an arbitrary string key
1010 and a function whose first argument is of type context.Context.
1111 The key is used to look up the function so it can be called later.
12
1213 var laterFunc = delay.Func("key", myFunc)
14
1315 It is also possible to use a function literal.
16
1417 var laterFunc = delay.Func("key", func(c context.Context, x string) {
1518 // ...
1619 })
1720
1821 To call a function, invoke its Call method.
22
1923 laterFunc.Call(c, "something")
24
2025 A function may be called any number of times. If the function has any
2126 return arguments, and the last one is of type error, the function may
2227 return a non-nil error to signal that the function should be retried.
3641 with pending function invocations should safe as long as the relevant
3742 functions have the (filename, key) combination preserved. The filename is
3843 parsed according to these rules:
39 * Paths in package main are shortened to just the file name (github.com/foo/foo.go -> foo.go)
40 * Paths are stripped to just package paths (/go/src/github.com/foo/bar.go -> github.com/foo/bar.go)
41 * Module versions are stripped (/go/pkg/mod/github.com/foo/bar@v0.0.0-20181026220418-f595d03440dc/baz.go -> github.com/foo/bar/baz.go)
44 - Paths in package main are shortened to just the file name (github.com/foo/foo.go -> foo.go)
45 - Paths are stripped to just package paths (/go/src/github.com/foo/bar.go -> github.com/foo/bar.go)
46 - Module versions are stripped (/go/pkg/mod/github.com/foo/bar@v0.0.0-20181026220418-f595d03440dc/baz.go -> github.com/foo/bar/baz.go)
4247
4348 There is some inherent risk of pending function invocations being lost during
4449 an update that contains large changes. For example, switching from using GOPATH
207212 }
208213
209214 // Call invokes a delayed function.
210 // err := f.Call(c, ...)
215 //
216 // err := f.Call(c, ...)
217 //
211218 // is equivalent to
212 // t, _ := f.Task(...)
213 // _, err := taskqueue.Add(c, t, "")
219 //
220 // t, _ := f.Task(...)
221 // _, err := taskqueue.Add(c, t, "")
214222 func (f *Function) Call(c context.Context, args ...interface{}) error {
215223 t, err := f.Task(args...)
216224 if err != nil {
22 // license that can be found in the LICENSE file.
33
44 // This example only works on App Engine "flexible environment".
5 //go:build !appengine
56 // +build !appengine
67
78 package main
22 // license that can be found in the LICENSE file.
33
44 // This example only works on App Engine "flexible environment".
5 //go:build !appengine
56 // +build !appengine
67
78 package main
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appengine
45 // +build appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build race
45 // +build race
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appengine
45 // +build appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appenginevm
45 // +build appenginevm
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appengine
45 // +build appengine
56
67 package internal
0 //go:build !appengine
01 // +build !appengine
12
23 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package internal
3737 5: "OAUTH_ERROR",
3838 }
3939 var UserServiceError_ErrorCode_value = map[string]int32{
40 "OK": 0,
40 "OK": 0,
4141 "REDIRECT_URL_TOO_LONG": 1,
4242 "NOT_ALLOWED": 2,
4343 "OAUTH_INVALID_TOKEN": 3,
66 from within an App Engine application.
77
88 Example:
9
910 c := appengine.NewContext(r)
1011 query := &log.Query{
1112 AppLogs: true,
66 App Engine application.
77
88 Example:
9
910 msg := &mail.Message{
1011 Sender: "romeo@montague.com",
1112 To: []string{"Juliet <juliet@capulet.org>"},
44 /*
55 Package search provides a client for App Engine's search service.
66
7
8 Basic Operations
7 # Basic Operations
98
109 Indexes contain documents. Each index is identified by its name: a
1110 human-readable ASCII string.
5352 return err
5453 }
5554
56
57 Search and Listing Documents
55 # Search and Listing Documents
5856
5957 Indexes have two methods for retrieving multiple documents at once: Search and
6058 List.
9795 fmt.Fprintf(w, "%s -> %#v\n", id, doc)
9896 }
9997
100
101 Fields and Facets
98 # Fields and Facets
10299
103100 A document's contents can be represented by a variety of types. These are
104101 typically struct pointers, but they can also be represented by any type
144141 I float64 `search:",facet" json:"i"`
145142 }
146143
147
148 The FieldLoadSaver Interface
144 # The FieldLoadSaver Interface
149145
150146 A document's contents can also be represented by any type that implements the
151147 FieldLoadSaver interface. This type may be a struct pointer, but it
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appengine
45 // +build appengine
56
67 package socket
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package socket
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appengine
45 // +build appengine
56
67 package user
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package user
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build !appengine
45 // +build !appengine
56
67 package user
3434 //
3535 // Main is designed so that the app's main package looks like this:
3636 //
37 // package main
37 // package main
3838 //
39 // import (
40 // "google.golang.org/appengine/v2"
39 // import (
40 // "google.golang.org/appengine/v2"
4141 //
42 // _ "myapp/package0"
43 // _ "myapp/package1"
44 // )
42 // _ "myapp/package0"
43 // _ "myapp/package1"
44 // )
4545 //
46 // func main() {
47 // appengine.Main()
48 // }
46 // func main() {
47 // appengine.Main()
48 // }
4949 //
5050 // The "myapp/packageX" packages are expected to register HTTP handlers
5151 // in their init functions.
88 This package does not work in App Engine "flexible environment".
99
1010 Example:
11
1112 if !capability.Enabled(c, "datastore_v3", "write") {
1213 // show user a different page
1314 }
77 // A main func is synthesized if one does not exist.
88 //
99 // A sample Dockerfile to be used with this bundler could look like this:
10 // FROM gcr.io/google-appengine/go-compat
11 // ADD . /app
12 // RUN GOPATH=/app/_gopath go build -tags appenginevm -o /app/_ah/exe
10 //
11 // FROM gcr.io/google-appengine/go-compat
12 // ADD . /app
13 // RUN GOPATH=/app/_gopath go build -tags appenginevm -o /app/_ah/exe
1314 package main
1415
1516 import (
44 /*
55 Package datastore provides a client for App Engine's datastore service.
66
7
8 Basic Operations
7 # Basic Operations
98
109 Entities are the unit of storage and are associated with a key. A key
1110 consists of an optional parent key, a string application ID, a string kind
7372 Delete functions. They take a []*Key instead of a *Key, and may return an
7473 appengine.MultiError when encountering partial failure.
7574
76
77 Properties
75 # Properties
7876
7977 An entity's contents can be represented by a variety of types. These are
8078 typically struct pointers, but can also be any type that implements the
136134 J int `datastore:",noindex" json:"j"`
137135 }
138136
139
140 Structured Properties
137 # Structured Properties
141138
142139 If the struct pointed to contains other structs, then the nested or embedded
143140 structs are flattened. For example, given these definitions:
178175 If an outer struct is tagged "noindex" then all of its implicit flattened
179176 fields are effectively "noindex".
180177
181
182 The PropertyLoadSaver Interface
178 # The PropertyLoadSaver Interface
183179
184180 An entity's contents can also be represented by any type that implements the
185181 PropertyLoadSaver interface. This type may be a struct pointer, but it does
229225 The *PropertyList type implements PropertyLoadSaver, and can therefore hold an
230226 arbitrary entity's contents.
231227
232
233 Queries
228 # Queries
234229
235230 Queries retrieve entities based on their properties or key's ancestry. Running
236231 a query yields an iterator of results: either keys or (key, entity) pairs.
283278 io.Copy(w, b)
284279 }
285280
286
287 Transactions
281 # Transactions
288282
289283 RunInTransaction runs a function in a transaction.
290284
322316 fmt.Fprintf(w, "Count=%d", count)
323317 }
324318
325
326 Metadata
319 # Metadata
327320
328321 The datastore package provides access to some of App Engine's datastore
329322 metadata. This metadata includes information about the entity groups,
4949 // The properties are returned as a map of property names to a slice of the
5050 // representation types. The representation types for the supported Go property
5151 // types are:
52 // "INT64": signed integers and time.Time
53 // "DOUBLE": float32 and float64
54 // "BOOLEAN": bool
55 // "STRING": string, []byte and ByteString
56 // "POINT": appengine.GeoPoint
57 // "REFERENCE": *Key
58 // "USER": (not used in the Go runtime)
52 //
53 // "INT64": signed integers and time.Time
54 // "DOUBLE": float32 and float64
55 // "BOOLEAN": bool
56 // "STRING": string, []byte and ByteString
57 // "POINT": appengine.GeoPoint
58 // "REFERENCE": *Key
59 // "USER": (not used in the Go runtime)
5960 func KindProperties(ctx context.Context, kind string) (map[string][]string, error) {
6061 // TODO(djd): Support range queries.
6162 kindKey := NewKey(ctx, kindKind, kind, 0, nil)
475475 // The keys returned by GetAll will be in a 1-1 correspondence with the entities
476476 // added to dst.
477477 //
478 // If q is a ``keys-only'' query, GetAll ignores dst and only returns the keys.
478 // If q is a “keys-only” query, GetAll ignores dst and only returns the keys.
479479 //
480480 // The running time and number of API calls made by GetAll scale linearly with
481481 // the sum of the query's offset and limit. Unless the result count is
219219 }
220220
221221 // Call invokes a delayed function.
222 // err := f.Call(c, ...)
222 //
223 // err := f.Call(c, ...)
224 //
223225 // is equivalent to
224 // t, _ := f.Task(...)
225 // _, err := taskqueue.Add(c, t, "")
226 //
227 // t, _ := f.Task(...)
228 // _, err := taskqueue.Add(c, t, "")
226229 func (f *Function) Call(c context.Context, args ...interface{}) error {
227230 t, err := f.Task(args...)
228231 if err != nil {
446446 MustRegister("invalid", func() {})
447447 }
448448
449
450449 func TestGetRequestHeadersFromContext(t *testing.T) {
451450 for _, testTarget := range []*Function{requestFunc, requestRegister} {
452451 c := newFakeContext()
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build race
45 // +build race
56
67 package internal
11 // Use of this source code is governed by the Apache 2.0
22 // license that can be found in the LICENSE file.
33
4 //go:build appenginevm
45 // +build appenginevm
56
67 package internal
66 App Engine application.
77
88 Example:
9
910 msg := &mail.Message{
1011 Sender: "romeo@montague.com",
1112 To: []string{"Juliet <juliet@capulet.org>"},
66 to and from users of XMPP-compatible services.
77
88 To send a message,
9
910 m := &xmpp.Message{
1011 To: []string{"kaylee@example.com"},
1112 Body: `Hi! How's the carrot?`,
1314 err := m.Send(c)
1415
1516 To receive messages,
17
1618 func init() {
1719 xmpp.Handle(handleChat)
1820 }