Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wrap

Golang wrappers for pointers, slices, and maps that provide secure access, useful methods, and support for JSON/XML serialization.

usage

package main

import (
  "fmt"
  "github.com/twoojoo/wrap"
)

func main() {

  // wrapped pointer
  ptr := wrap.NewPointer(10)
  ptr.SetValue(20)

  v, exists := ptr.GetValue()
  fmt.Println(v, exists) // 20, true

  prt.Clear()
  v, exists = ptr.GetValue() // 0, false

  // wrapped slice
  slice := wrap.NewSlice([]int{1, 2, 3})
  slice.Append(4, 5, 6)

  v, exists = slice.ValueAt(3) // 4, true
  v, exists = slice.ValueAt(10) // 0, false

  // wrapped map
  m := wrap.NewMap(map[string]int{"a": 1, "b": 2})
  m.Set("c", 3) 

  m.Keys() // ["a", "b", "c"]
  m.Values() // [1, 2, 3]
}

About

Golang wrappers for pointers, slices and maps that provide secure access, useful methods and JSON / XML serialization support

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages