@@ -18,46 +18,23 @@ package main
18
18
import (
19
19
"context"
20
20
"fmt"
21
- "io"
22
21
23
22
vision "cloud.google.com/go/vision/apiv1"
24
23
"google.golang.org/api/option"
25
- visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1"
26
24
)
27
25
28
26
// setEndpoint changes your endpoint.
29
- func setEndpoint (w io. Writer , endpoint string ) error {
27
+ func setEndpoint (ctx context. Context , endpoint string ) ( * vision. ImageAnnotatorClient , error ) {
30
28
// endpoint := "eu-vision.googleapis.com:443"
31
29
32
- // Create a client with a custom endpoint.
33
- ctx := context .Background ()
30
+ // ctx := context.Background()
34
31
client , err := vision .NewImageAnnotatorClient (ctx , option .WithEndpoint (endpoint ))
35
32
if err != nil {
36
- return fmt .Errorf ("NewImageAnnotatorClient: %v" , err )
33
+ return nil , fmt .Errorf ("NewImageAnnotatorClient: %v" , err )
37
34
}
38
- defer client .Close ()
35
+ // defer client.Close()
39
36
40
- // Use the client with custom endpoint to detect texts on an image.
41
- image := & visionpb.Image {
42
- Source : & visionpb.ImageSource {
43
- GcsImageUri : "gs://cloud-samples-data/vision/text/screen.jpg" ,
44
- },
45
- }
46
- maxResults := 3
47
- texts , err := client .DetectTexts (ctx , image , nil , maxResults )
48
- if err != nil {
49
- return fmt .Errorf ("DetectTexts: %v" , err )
50
- }
51
-
52
- fmt .Fprintf (w , "Texts:\n " )
53
- for _ , text := range texts {
54
- fmt .Fprintf (w , "%v\n " , text .GetDescription ())
55
- for _ , vertex := range text .GetBoundingPoly ().GetVertices () {
56
- fmt .Fprintf (w , " bounding vertex: %v, %v\n " , vertex .GetX (), vertex .GetY ())
57
- }
58
- }
59
-
60
- return nil
37
+ return client , nil
61
38
}
62
39
63
40
// [END vision_set_endpoint]
0 commit comments