// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Code generated by protoc-gen-go_gapic. DO NOT EDIT.

package language_test

import (
	"context"

	language "cloud.google.com/go/language/apiv1"
	languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"
)

func ExampleNewClient() {
	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use client.
	_ = c
}

func ExampleClient_AnalyzeSentiment() {
	// import languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"

	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}

	req := &languagepb.AnalyzeSentimentRequest{
		// TODO: Fill request struct fields.
	}
	resp, err := c.AnalyzeSentiment(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func ExampleClient_AnalyzeEntities() {
	// import languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"

	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}

	req := &languagepb.AnalyzeEntitiesRequest{
		// TODO: Fill request struct fields.
	}
	resp, err := c.AnalyzeEntities(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func ExampleClient_AnalyzeEntitySentiment() {
	// import languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"

	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}

	req := &languagepb.AnalyzeEntitySentimentRequest{
		// TODO: Fill request struct fields.
	}
	resp, err := c.AnalyzeEntitySentiment(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func ExampleClient_AnalyzeSyntax() {
	// import languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"

	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}

	req := &languagepb.AnalyzeSyntaxRequest{
		// TODO: Fill request struct fields.
	}
	resp, err := c.AnalyzeSyntax(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func ExampleClient_ClassifyText() {
	// import languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"

	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}

	req := &languagepb.ClassifyTextRequest{
		// TODO: Fill request struct fields.
	}
	resp, err := c.ClassifyText(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

func ExampleClient_AnnotateText() {
	// import languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"

	ctx := context.Background()
	c, err := language.NewClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}

	req := &languagepb.AnnotateTextRequest{
		// TODO: Fill request struct fields.
	}
	resp, err := c.AnnotateText(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}
