mapping

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Into

func Into[S any, D any](src S, dst *D)

Into the function for copy data from input into output struct, Fast when large data, Single-Level Struct Support Benchmark:

Benchmark_Manual-10          	 3096486	       364.7 ns/op
Benchmark_Into-10            	  487270	      2312 ns/op

How to use:

type Input struct {
	Field1 int `json:"field1"`
	Field2 int `json:"field2"`
	Field3 int `json:"field3"`
	Field4 int `json:"field4"`
}

type Output struct {
	FieldFloat32  float32 `json:"field_float32"`
	FieldFloat64  float64 `json:"field_float64"`
	FieldInt      int     `json:"field_int"`
	FieldInt8     int8    `json:"field_int8"`
	FieldInt16    int16   `json:"field_int16"`
	FieldInt32    int32   `json:"field_int32"`
	FieldInt64    int64   `json:"field_int64"`
	FieldUint     uint    `json:"field_uint"`
	FieldUint8    uint8   `json:"field_uint8"`
	FieldUint16   uint16  `json:"field_uint16"`
	FieldUint32   uint32  `json:"field_uint32"`
	FieldUint64   uint64  `json:"field_uint64"`
	FieldString   string  `json:"field_string"`
	FieldBool     bool    `json:"field_bool"`
	FieldAny      any     `json:"field_any"`
	FieldError    error   `json:"field_error"`
}

input := Input{
	Field1: 1,
	Field2: 2,
	Field3: 3,
	Field4: 4,
}

var output Output
Into(input, &output)
fmt.Printf("%+v\n", output) // Output: {Field1:1 Field2:2}

func TinyInto

func TinyInto[D any](src any, dst *D) error

TinyInto unsupported error type, Fast when small data, Multiple-Level Struct Support

Types

This section is empty.

Jump to

Keyboard shortcuts

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