cstructs

package module
v0.0.0-...-ceebf9d Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2017 License: MIT Imports: 4 Imported by: 4

README

CStruct

CStruct copies a source struct to another struct that share similar fields and field types.

Installation

go get github.com/ncodes/cstructs

Example

package main

import "github.com/ncodes/cstructs"

// A
type A struct {
	Name  string
	Age   int
	About []byte
}

// B
type B struct {
	Name  string
	Age   int
	About []byte
}

func main(){ 
    
    ben := A{
		Name:  "benedith",
		Age:   20,
		About: []byte("Ben is a great sports person"),
	}

    var pete B
    cstructs.Copy(&ben, &pete)
}

CopySlice(src interface{}, dest interface{})

Copies a slice of struct to another slice of struct. Both slice must have the same length.If src is empty, nil is returned.

MakeSliceOf(of interface{}, size int)

A convenience method for creating a slice of an initialized type. Useful when there is need to create a slice of struct to use as destination when calling CopySlice.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(src interface{}, dest interface{}) error

Copy copies the value of fields from src to similar fields of dest

func CopySlice

func CopySlice(src interface{}, dest interface{}) error

CopySlice copies the field values of every struct in src to a corresponding struct in dest with matching id, field name and type.

func IsSlice

func IsSlice(s interface{}) bool

IsSlice checks if an interface holds a slice.

func MakeSliceOf

func MakeSliceOf(of interface{}, size int) []interface{}

MakeSliceOf creates a slice of values. It returns a slice of interfaces of length `size“ with the same underlying type as the value `of“

Types

This section is empty.

Jump to

Keyboard shortcuts

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