windmill icon indicating copy to clipboard operation
windmill copied to clipboard

feature: add default values to Go's script parameters

Open fermuch opened this issue 1 year ago • 2 comments

The other scripts have an interpreter for default values in the script parameters. Go, to be consistent with the others, should have this functionality too.

There is already support for the "json" annotation, so it seems natural to add another annotation for "default" values.

Example:

package main

import "fmt"

func main(x int, y string, z bool, l []string, o struct { Name string `json:"name",default:"my name"` }, n interface{}, m map[string]interface{}) {
    fmt.Println("hello world")
}   

There is one catch though: only structs can have struct tags. One alternative might be to, if the only parameter is a struct, to use the fields inside that struct as the input parameters.

Example:

package main

import "fmt"

func main(o struct { Name string `json:"name",default:"my name"`, Surname string `json:"surname",default:"my surname"` }) (interface{}, error) {
    fmt.Println("hello world")
    return nil, nil
}

Given that example, it would be rendered in the UI like so: imagen

fermuch avatar May 19 '23 19:05 fermuch