From f34a625add415aed0610150e729adae477f43614 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 15 Oct 2022 11:18:17 +0200 Subject: [PATCH] fix(go-client): improve go-client variable and resource handling --- frontend/src/lib/components/EditorBar.svelte | 10 ++++++++++ frontend/src/lib/script_helpers.ts | 2 ++ go-client/windmill.go | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/EditorBar.svelte b/frontend/src/lib/components/EditorBar.svelte index 35ecac579c..0ed8b8331c 100644 --- a/frontend/src/lib/components/EditorBar.svelte +++ b/frontend/src/lib/components/EditorBar.svelte @@ -124,6 +124,11 @@ editor.insertAtBeginning('import wmill\n') } editor.insertAtCursor(`wmill.get_variable("${path}")`) + } else if (lang == 'go') { + if (!editor.getCode().includes('wmill "github.com/windmill-labs/windmill-go-client"')) { + editor.insertAtBeginning('import wmill "github.com/windmill-labs/windmill-go-client"\n') + } + editor.insertAtCursor(`v, _ := wmill.GetVariable("${path}")`) } sendUserToast(`${name} inserted at cursor`) }} @@ -163,6 +168,11 @@ editor.insertAtBeginning('import wmill\n') } editor.insertAtCursor(`wmill.get_resource("${path}")`) + } else if (lang == 'go') { + if (!editor.getCode().includes('wmill "github.com/windmill-labs/windmill-go-client"')) { + editor.insertAtBeginning('import wmill "github.com/windmill-labs/windmill-go-client"\n') + } + editor.insertAtCursor(`r, _ := wmill.GetResource("${path}")`) } sendUserToast(`${path} inserted at cursor`) }} diff --git a/frontend/src/lib/script_helpers.ts b/frontend/src/lib/script_helpers.ts index 08f9c28f10..3aac6277b7 100644 --- a/frontend/src/lib/script_helpers.ts +++ b/frontend/src/lib/script_helpers.ts @@ -54,11 +54,13 @@ export const GO_INIT_CODE = `package inner import ( "fmt" "rsc.io/quote" + // wmill "github.com/windmill-labs/windmill-go-client" ) func main(x string) (interface{}, error) { fmt.Println("Hello, World") fmt.Println(quote.Opt()) + // v, _ := wmill.GetVariable("g/all/pretty_secret") return x, nil } ` diff --git a/go-client/windmill.go b/go-client/windmill.go index d76f8bb6f2..2d95928f60 100644 --- a/go-client/windmill.go +++ b/go-client/windmill.go @@ -19,7 +19,7 @@ type ClientWithWorkspace struct { } func GetClient() (ClientWithWorkspace, error) { - base_url := os.Getenv("BASE_INTERNAL_URL") + base_url := os.Getenv("BASE_INTERNAL_URL") + "/api" workspace := os.Getenv("WM_WORKSPACE") token := os.Getenv("WM_TOKEN")