Source File
options.go
Belonging Package
src.elv.sh/pkg/eval
package evalimport ()// RawOptions is the type of an argument a Go-native function can take to// declare that it wants to parse options itself. See the doc of NewGoFn for// details.type RawOptions map[string]interface{}// Takes a raw option map and a pointer to a struct, and populate the struct// with options. A field named FieldName corresponds to the option named// field-name, unless the field has a explicit "name" tag. Fields typed// ParsedOptions are ignored.func ( RawOptions, interface{}) error {:= reflect.ValueOf()if .Kind() != reflect.Ptr || .Elem().Kind() != reflect.Struct {return fmt.Errorf("internal bug: need struct ptr to scan options, got %T", )}// fieldIdxForOpt maps option name to the index of field in `struc`.:= make(map[string]int):= .Elem()for := 0; < .Type().NumField(); ++ {if !.Field().CanSet() {continue // ignore unexported fields}:= .Type().Field():= .Tag.Get("name")if == "" {= strutil.CamelToDashed(.Name)}[] =}for , := range {, := []if ! {return fmt.Errorf("unknown option %s", parse.Quote())}:= vals.ScanToGo(, .Field().Addr().Interface())if != nil {return}}return nil}
The pages are generated with Golds v0.2.8-preview. (GOOS=darwin GOARCH=arm64)