util

package
v1.91.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Checks that JSON file does not contain any fields that are not in the struct

Checks that all the fields in a struct are initialized

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check_type_is_ptr_to_struct

func Check_type_is_ptr_to_struct(struct_ptr interface{}) error

func Json_unmarshall_error_on_extra_fields

func Json_unmarshall_error_on_extra_fields(data []byte, struct_ptr interface{}) error

func Recursively_Check_for_nil_pointers

func Recursively_Check_for_nil_pointers(thing_to_be_checked interface{}, name_of_the_thing string) error

Recursively_Check_for_nil_pointers is a function that checks the 'thing_to_be_checked' and its nested elements for nil pointers. It has to be recursive so that it checks inside nested data structures. Note that it does not check maps and slices for nil values, since we don't really care about that If a slice is empty, that's okay and allowed. Likewise if a map is empty, that's okay too. We want users to be able to do that. What we don't want are empty fields in structs, whether these structs are inside other structs, or slices, or maps.

The function uses reflection to inspect the structure of the data. It performs the following steps: 1. Checks whether the argument is a pointer. If not, it returns an error. 2. Checks whether the argument is a nil pointer. If so, it returns an error. 3. Dereferences the pointer to find the actual data type. 4. Calls itself on each nested element.

Guarantees: - If the data structure contains a nil pointer, then the function is guaranteed to return an error. - Therefore, if it doesn't throw an error then we can be sure that the data structure doesn't contain a nil pointer. - It does not modify the input data structure.

Parameters: - thing_to_be_checked: The thing which the function checks for nil pointers.

Returns: - An error if a nil pointer or unsupported data type is found within the data structure, indicating the type of error. - nil if no nil pointers or unsupported data types are found within the data structure.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL