collection

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

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

Go to latest
Published: Jul 4, 2019 License: MIT Imports: 2 Imported by: 0

README

Go Report License Say Thanks!

Go arrays management

This package is provided to be used on golang and it gives clean methods to handle arrays.

Requirement

  • Golang 1.12.x: keep your compiler up to date :)
  • reflect

The package is in process.

Install

Run this commands

$ go get github.com/MrJoshLab/go-collection

Basic Usage

You must to import the package name

import (
    collection "github.com/MrJoshLab/go-collection"
)

You also need fmt package to print results in console

import "fmt"

The following illustrates how you can use Array type or function to use methods.

data := map[string] string { "say": "hello" }
c := collection.New(data)

// example:
fmt.Println(c.Has("say"))
// return true

fmt.Println(c.Get("say"))
// return "hello"

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Data interface{}
}

create a type of array with array data

func New

func New(data interface{}) *Collection

make a new instance from Collection type

func (*Collection) AddMap

func (a *Collection) AddMap(key interface{}, value interface{}) *Collection

add a map into array data

func (*Collection) Exists

func (a *Collection) Exists(key string) bool

check exists index of array data

func (*Collection) First

func (a *Collection) First() interface{}

get first index of array data

func (*Collection) Get

func (a *Collection) Get(key interface{}) interface{}

get a index from map array data

func (*Collection) Has

func (a *Collection) Has(key string) bool

check array has key in slice and map array data

func (*Collection) Index

func (a *Collection) Index(key int) interface{}

get index from slice array data

func (*Collection) IsValid

func (a *Collection) IsValid() bool

check valid data

func (*Collection) Last

func (a *Collection) Last() interface{}

get last index from array data

func (*Collection) Only

func (a *Collection) Only(values ...interface{}) interface{}

get only keys need in one array in return

func (*Collection) ToBytes

func (a *Collection) ToBytes() []byte

Convert the given data to json string bytes

func (*Collection) ToJson

func (a *Collection) ToJson() string

Convert the given data to json string

Jump to

Keyboard shortcuts

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