Good day, Ashok,
I was able to submit a Dataflow job using this code snippet. Change the
bracketed <> values with what makes sense to your Google Cloud
environment. Could you let me know if this works for you?
Best,
Damon
params := &dataflow.LaunchTemplateParameters{
Environment: &dataflow.RuntimeEnvironment{
Network: "<network>",
ServiceAccountEmail:
"<service-account-id>@<google-cloud-project-id>.iam.gserviceaccount.com",
Subnetwork: "regions/<region>/subnetworks/<subnetwork>",
},
JobName: "<job-name>",
Parameters: map[string]string{
"inputFile": "gs://dataflow-samples/shakespeare/kinglear.txt",
"output": "gs://<bucket>/wordcount/output",
},
}
resp, err := svc.Projects.Templates.Launch("<project>",
params).GcsPath("gs://dataflow-templates/latest/Word_Count").Do()
if err != nil {
// do something with err
}
On Wed, Feb 15, 2023 at 7:04 AM Bruno Volpato via dev <[email protected]>
wrote:
> Hello,
>
> The most similar to the mentioned Python APIs is through
> https://github.com/googleapis/google-api-go-client.
>
> There are some docs that include Go examples:
> - Flex Templates:
> https://cloud.google.com/dataflow/docs/samples/dataflow-v1beta3-generated-FlexTemplatesService-LaunchFlexTemplate-sync
> - Classic Templates:
> https://cloud.google.com/dataflow/docs/samples/dataflow-v1beta3-generated-TemplatesService-LaunchTemplate-sync
>
> Best,
> Bruno
>
>
>
> On Wed, Feb 15, 2023 at 9:29 AM Jack McCluskey via user <
> [email protected]> wrote:
>
>> As far as I know, Shivam's solution is the correct one for launching a
>> template from Go. You're just routing your calls through a
>> Dataflow-specific API library rather than going through the API discovery
>> service.
>>
>> On Wed, Feb 15, 2023 at 9:16 AM Kerry Donny-Clark <[email protected]>
>> wrote:
>>
>>> Jack added the Go templates capabilities, he should be able to help you
>>> out.
>>>
>>> On Wed, Feb 15, 2023, 12:37 AM Ashok KS <[email protected]> wrote:
>>>
>>>> Hi Shivam,
>>>>
>>>> Thanks a lot for your response. I did check the http request. But I
>>>> wanted to see if I can use the Google API client Library.
>>>> The docs show a Python example for it shown below. I wanted to know if
>>>> there is something similar with Go.
>>>>
>>>> from googleapiclient.discovery import build
>>>>
>>>> # project = 'your-gcp-project'
>>>> # job = 'unique-job-name'
>>>> # template = 'gs://dataflow-templates/latest/Word_Count'
>>>> # parameters = {
>>>> # 'inputFile': 'gs://dataflow-samples/shakespeare/kinglear.txt',
>>>> # 'output': 'gs://<your-gcs-bucket>/wordcount/outputs',
>>>> # }
>>>>
>>>> dataflow = build('dataflow', 'v1b3')
>>>> request = dataflow.projects().templates().launch(
>>>> projectId=project,
>>>> gcsPath=template,
>>>> body={
>>>> 'jobName': job,
>>>> 'parameters': parameters,
>>>> }
>>>> )
>>>>
>>>> response
>>>>
>>>>