/mutastruct

Use reflect package to do atypical changes to struct types.

Primary LanguageGo

mutastruct

Use the reflect package to make changes to a struct in an atypical manner.

To use, import the mutastruct package.

Call the following function to set a struct field.

func Set(anyStruct any, fieldName string, setting any) error {
    ...
}

The first argument must be a pointer to a struct. The last parameter, setting, is the desired value of the field specified by fieldName (the second parameter). The setting argument must be the same type as the field you wish to change.