Skip to content

A simple go tool to convert all nil slices to empty slices in you struct

Notifications You must be signed in to change notification settings

jamsman94/slicehelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slicehelper

A simple go tool to make json Marshalling less painful for slices

install

go get -u github.com/jamsman94/slicehelper

Usage

Replacing All nil slices with initialized empty slices for json marshal

This currently supports custom structs, pointers, slices and maps, and the combination of above types.

import "github.com/jamsman94/slicehelper"

var myslice []string                               // nil

slicehelper.ReplaceNilWithEmptySlice(myslice)      // []

type SupportedType struct {
    PointerToSlice   *[]string           `json:"pointer_to_slice"`
    OnlySlice        []string            `json:"only_string"`
    SliceOfPointer   []*string           `json:"slice_of_pointer"`
    MapofSlice       map[string][]string `json:"map_of_slice"`
}
}

About

A simple go tool to convert all nil slices to empty slices in you struct

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages