From f4a48dfa09e34009d59ec077dce5783c73e179ac Mon Sep 17 00:00:00 2001 From: Andrei Markin Date: Mon, 14 Sep 2026 17:29:54 +0400 Subject: [PATCH] feat(go-sdk): add CLI tool * Add functions for reading workflows and config from local files * Add support for source in Execute method --- sdk/go/cmd/execute.go | 54 ++++++++++++++++++++++++++++++++++++++++ sdk/go/cmd/root.go | 52 +++++++++++++++++++++++++++++++++++++++ sdk/go/cmd/run.go | 56 ++++++++++++++++++++++++++++++++++++++++++ sdk/go/cmd/workflow.go | 33 +++++++++++++++++++++++++ sdk/go/garf/garf.go | 35 ++++++++++++++++++++++++-- sdk/go/go.mod | 12 +++++++++ sdk/go/go.sum | 29 ++++++++++++++++++++++ sdk/go/main.go | 24 ++++++++---------- 8 files changed, 279 insertions(+), 16 deletions(-) create mode 100644 sdk/go/cmd/execute.go create mode 100644 sdk/go/cmd/root.go create mode 100644 sdk/go/cmd/run.go create mode 100644 sdk/go/cmd/workflow.go diff --git a/sdk/go/cmd/execute.go b/sdk/go/cmd/execute.go new file mode 100644 index 00000000..1e262eb4 --- /dev/null +++ b/sdk/go/cmd/execute.go @@ -0,0 +1,54 @@ +// Copyright 2026 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. + +package cmd + +import ( + "fmt" + "log" + "os" + "path/filepath" + "strings" + + "github.com/google/garf/sdk/go/garf" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var executeCmd = &cobra.Command{ + Use: "execute", + Short: "Executes queries", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + garfEndpoint := viper.GetString("endpoint") + g := garf.New(garfEndpoint) + p := filepath.Clean(args[0]) + queryData, err := os.ReadFile(args[0]) + if err != nil { + log.Fatal("File not found") + } + ext := filepath.Ext(p) + title := strings.TrimSuffix(filepath.Base(p), ext) + writer, _ := cmd.Flags().GetString("writer") + source, _ := cmd.Flags().GetString("source") + results := g.Execute(source, title, string(queryData), writer) + fmt.Println(results) + }, +} + +func init() { + rootCmd.AddCommand(executeCmd) + executeCmd.Flags().StringP("source", "s", "fake", "Type of API source") + executeCmd.Flags().StringP("writer", "w", "json", "Name of writer") +} diff --git a/sdk/go/cmd/root.go b/sdk/go/cmd/root.go new file mode 100644 index 00000000..3ceb0981 --- /dev/null +++ b/sdk/go/cmd/root.go @@ -0,0 +1,52 @@ +// Copyright 2026 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. + +package cmd + +import ( + "os" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var ( + EnableCache bool + GarfEndpoint string +) + +var rootCmd = &cobra.Command{ + Use: "garf", + Short: "Interact with garf", + Version: "0.0.1", +} + +func Execute() { + err := rootCmd.Execute() + if err != nil { + os.Exit(1) + } +} + +func init() { + viper.AutomaticEnv() + replacer := strings.NewReplacer("-", "_") + rootCmd.PersistentFlags().StringVarP(&GarfEndpoint, "endpoint", "", "", "Garf server address") + rootCmd.PersistentFlags().BoolVarP(&EnableCache, "enable-cache", "", false, "Whether to enable cache") + viper.SetEnvKeyReplacer(replacer) + viper.SetEnvPrefix("GARF") + viper.BindPFlag("endpoint", rootCmd.PersistentFlags().Lookup("endpoint")) + viper.BindPFlag("enable-cache", rootCmd.PersistentFlags().Lookup("enable-cache")) +} diff --git a/sdk/go/cmd/run.go b/sdk/go/cmd/run.go new file mode 100644 index 00000000..b5b4637d --- /dev/null +++ b/sdk/go/cmd/run.go @@ -0,0 +1,56 @@ +// Copyright 2026 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. + +package cmd + +import ( + "fmt" + "log" + + "github.com/google/garf/sdk/go/garf" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var runCmd = &cobra.Command{ + Use: "run", + Short: "Runs workflow from a file", + Run: func(cmd *cobra.Command, args []string) { + garfEndpoint := viper.GetString("endpoint") + g := garf.New(garfEndpoint) + var err error + workflowPath, _ := cmd.Flags().GetString("file") + configPath, _ := cmd.Flags().GetString("config") + config := &garf.Config{} + if configPath != "" { + config, err = garf.ReadConfigFromFile(configPath) + if err != nil { + log.Fatalf("Problem reading config: %v", err) + } + } + workflow, err := garf.ReadWorkflowFromFile(workflowPath) + if err != nil { + log.Fatalf("Problem reading workflow: %v", err) + } + + resultsFileWorkflow := g.ExecuteWorkflow(workflow, config, &garf.ExecutionContext{}) + fmt.Println(resultsFileWorkflow) + }, +} + +func init() { + workflowCmd.AddCommand(runCmd) + runCmd.Flags().StringP("file", "f", "", "Path to garf workflow") + runCmd.Flags().StringP("config", "c", "", "Path to garf config") +} diff --git a/sdk/go/cmd/workflow.go b/sdk/go/cmd/workflow.go new file mode 100644 index 00000000..14ce9882 --- /dev/null +++ b/sdk/go/cmd/workflow.go @@ -0,0 +1,33 @@ +// Copyright 2026 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. + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var workflowCmd = &cobra.Command{ + Use: "workflow", + Short: "A brief description of your command", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("workflow called") + }, +} + +func init() { + rootCmd.AddCommand(workflowCmd) +} diff --git a/sdk/go/garf/garf.go b/sdk/go/garf/garf.go index c38155a9..682b399f 100644 --- a/sdk/go/garf/garf.go +++ b/sdk/go/garf/garf.go @@ -18,7 +18,9 @@ package garf import ( "context" "log" + "os" + "buf.build/go/protoyaml" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" emptypb "google.golang.org/protobuf/types/known/emptypb" @@ -187,7 +189,7 @@ func (g *Garf) Fetch(title, query string) *FetchResponse { return r } -func (g *Garf) Execute(title, query, writer string) []string { +func (g *Garf) Execute(source, title, query, writer string) []string { ctx, span := tracer.Start(context.Background(), "execute") defer span.End() @@ -202,7 +204,7 @@ func (g *Garf) Execute(title, query, writer string) []string { log.Fatalf("Failed to create fetcher parameters: %v", err) } request := ExecuteRequest{ - Source: "fake", + Source: source, Title: title, Query: query, Context: &ExecutionContext{ @@ -298,3 +300,32 @@ func (g *Garf) ExecuteWorkflow(workflow *Workflow, config *Config, executionCont logger.InfoContext(ctx, "Executed workflow", "workflow", result) return result } + +func ReadWorkflowFromFile(file string) (*Workflow, error) { + workflowData, _ := os.ReadFile(file) + var workflowFile Workflow + options := protoyaml.UnmarshalOptions{ + AllowPartial: true, + DiscardUnknown: true, + } + if err := options.Unmarshal(workflowData, &workflowFile); err != nil { + log.Fatalf("Failed to parse workflow: %v", err) + return nil, err + } + return &workflowFile, nil +} + +func ReadConfigFromFile(file string) (*Config, error) { + workflowData, _ := os.ReadFile(file) + var configFile Config + options := protoyaml.UnmarshalOptions{ + AllowPartial: true, + DiscardUnknown: true, + } + if err := options.Unmarshal(workflowData, &configFile); err != nil { + log.Fatalf("Failed to parse config: %v", err) + return nil, err + } + return &configFile, nil + +} diff --git a/sdk/go/go.mod b/sdk/go/go.mod index 148b3eab..ca32c189 100644 --- a/sdk/go/go.mod +++ b/sdk/go/go.mod @@ -5,6 +5,7 @@ go 1.25.0 require ( buf.build/go/protoyaml v0.7.0 github.com/jedib0t/go-pretty/v6 v6.8.3 + github.com/spf13/cobra v1.10.2 go.opentelemetry.io/contrib/bridges/otelslog v0.20.1 go.opentelemetry.io/contrib/exporters/autoexport v0.71.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0 @@ -25,20 +26,31 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-viper/mapstructure/v2 v2.5.0 // indirect github.com/google/cel-go v0.25.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/prometheus/client_golang v1.24.1 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.70.1 // indirect github.com/prometheus/otlptranslator v1.0.0 // indirect github.com/prometheus/procfs v0.21.1 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/spf13/viper v1.21.0 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect + github.com/subosito/gotenv v1.6.0 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/bridges/prometheus v0.71.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.22.0 // indirect diff --git a/sdk/go/go.sum b/sdk/go/go.sum index 2d34ec44..87b5fcc3 100644 --- a/sdk/go/go.sum +++ b/sdk/go/go.sum @@ -14,15 +14,20 @@ github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1x github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/protoc-gen-validate v1.3.3 h1:MVQghNeW+LZcmXe7SY1V36Z+WFMDjpqGAGacLe2T0ds= github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= +github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/cel-go v0.25.0 h1:jsFw9Fhn+3y2kBbltZR4VEz5xKkcIFRPDnuEzAGv5GY= @@ -33,6 +38,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jedib0t/go-pretty/v6 v6.8.3 h1:yVSk5aemoYHCvcrtqyXklwqcgHQIQzmy/oUzFlmffSQ= github.com/jedib0t/go-pretty/v6 v6.8.3/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk= @@ -43,6 +50,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU= github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE= @@ -57,6 +66,23 @@ github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIj github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -67,6 +93,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/contrib/bridges/otelslog v0.20.1 h1:5sHc4ToTFjfSZCtGAAM6jPunICAmJX73htv372T4ipc= @@ -123,6 +151,7 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw= diff --git a/sdk/go/main.go b/sdk/go/main.go index b3aa1fa7..af7b9091 100644 --- a/sdk/go/main.go +++ b/sdk/go/main.go @@ -22,7 +22,7 @@ import ( "github.com/jedib0t/go-pretty/v6/table" - "buf.build/go/protoyaml" + "github.com/google/garf/sdk/go/cmd" "github.com/google/garf/sdk/go/garf" "github.com/google/garf/sdk/go/telemetry" structpb "google.golang.org/protobuf/types/known/structpb" @@ -94,14 +94,14 @@ func fetchQueryInline(g garf.Garf) error { } func executeQueryInline(g garf.Garf) error { - results := g.Execute("test", "SELECT metric.int AS field FROM fake", "json") + results := g.Execute("fake", "test", "SELECT metric.int AS field FROM fake", "json") fmt.Println(results) return nil } func executeQueryFromFile(g garf.Garf) error { queryData, err := os.ReadFile("../../libs/executors/tests/unit/workflows/test_query.sql") - results := g.Execute("test", string(queryData), "json") + results := g.Execute("fake", "test", string(queryData), "json") fmt.Println(results) return err } @@ -118,17 +118,12 @@ func executeQueryBatchInline(g garf.Garf) error { } func runWorkflowFromFile(g garf.Garf) error { - workflowData, err := os.ReadFile("../../libs/executors/tests/unit/workflows/test_workflow.yaml") - var workflowFile garf.Workflow - options := protoyaml.UnmarshalOptions{ - AllowPartial: true, - DiscardUnknown: true, - } - if err := options.Unmarshal(workflowData, &workflowFile); err != nil { + workflow, err := garf.ReadWorkflowFromFile("../../libs/executors/tests/unit/workflows/test_workflow.yaml") + if err != nil { log.Fatalf("Failed to parse workflow: %v", err) } - resultsFileWorkflow := g.ExecuteWorkflow(&workflowFile, &garf.Config{}, &garf.ExecutionContext{}) + resultsFileWorkflow := g.ExecuteWorkflow(workflow, &garf.Config{}, &garf.ExecutionContext{}) fmt.Println(resultsFileWorkflow) return err @@ -190,7 +185,8 @@ func runInlineWorkflow(g garf.Garf) error { } func main() { - if err := run(); err != nil { - log.Fatalln(err) - } + // if err := run(); err != nil { + // log.Fatalln(err) + // } + cmd.Execute() }