-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_test.go
50 lines (41 loc) · 1.2 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package encore_test
import (
"fmt"
"time"
"encore.dev"
)
type Client interface{}
var client Client
func NewRedshiftClient() Client { return nil }
func NewBigQueryClient() Client { return nil }
func LocalFileWriter(dir string) Client { return nil }
// Change the implementation of some code based on which cloud provider is being used.
func ExampleMeta() {
switch encore.Meta().Environment.Cloud {
case encore.CloudAWS:
client = NewRedshiftClient()
case encore.CloudGCP:
client = NewBigQueryClient()
case encore.CloudLocal:
client = LocalFileWriter("/tmp/app-writes.txt")
default:
panic("unsupported cloud provider")
}
}
// Check if the application is running in production
func ExampleMeta_2() {
if encore.Meta().Environment.Type != encore.EnvProduction {
fmt.Println("running in development")
} else {
fmt.Println("running in production")
}
// Output: running in development
}
func ExampleCurrentRequest() {
req := encore.CurrentRequest()
elapsed := time.Since(req.Started)
if req.Type == encore.APICall {
fmt.Printf("%s.%s has been running for %.3f seconds", req.Service, req.Endpoint, elapsed.Seconds())
}
// Output: myservice.api has been running for 0.543 seconds
}