Skip to content

Commit

Permalink
gofmt 1.20 (#139)
Browse files Browse the repository at this point in the history
dolmen authored Aug 8, 2023
1 parent dce549b commit 3499ad5
Showing 7 changed files with 50 additions and 51 deletions.
8 changes: 4 additions & 4 deletions accessors.go
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@ var mapAccessRegex = regexp.MustCompile(mapAccessRegexString)
//
// Get can only operate directly on map[string]interface{} and []interface.
//
// Example
// # Example
//
// To access the title of the third chapter of the second book, do:
//
// o.Get("books[1].chapters[2].title")
// o.Get("books[1].chapters[2].title")
func (m Map) Get(selector string) *Value {
rawObj := access(m, selector, nil, false)
return &Value{data: rawObj}
@@ -52,11 +52,11 @@ func (m Map) Get(selector string) *Value {
//
// Set can only operate directly on map[string]interface{} and []interface
//
// Example
// # Example
//
// To set the title of the third chapter of the second book, do:
//
// o.Set("books[1].chapters[2].title","Time to Go")
// o.Set("books[1].chapters[2].title","Time to Go")
func (m Map) Set(selector string, value interface{}) Map {
access(m, selector, value, true)
return m
2 changes: 1 addition & 1 deletion codegen/template.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
{4} ({1} and []{1})
{4} ({1} and []{1})
*/

// {4} gets the value as a {1}, returns the optionalDefault
2 changes: 1 addition & 1 deletion codegen/template_test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Tests for {4} ({1} and []{1})
Tests for {4} ({1} and []{1})
*/
func Test{4}(t *testing.T) {
val := {1}({2})
40 changes: 20 additions & 20 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
/*
Package objx provides utilities for dealing with maps, slices, JSON and other data.
Overview
# Overview
Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes
a powerful `Get` method (among others) that allows you to easily and quickly get
access to data within the map, without having to worry too much about type assertions,
missing data, default values etc.
Pattern
# Pattern
Objx uses a predictable pattern to make access data from within `map[string]interface{}` easy.
Call one of the `objx.` functions to create your `objx.Map` to get going:
m, err := objx.FromJSON(json)
m, err := objx.FromJSON(json)
NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong,
the rest will be optimistic and try to figure things out without panicking.
Use `Get` to access the value you're interested in. You can use dot and array
notation too:
m.Get("places[0].latlng")
m.Get("places[0].latlng")
Once you have sought the `Value` you're interested in, you can use the `Is*` methods to determine its type.
if m.Get("code").IsStr() { // Your code... }
if m.Get("code").IsStr() { // Your code... }
Or you can just assume the type, and use one of the strong type methods to extract the real value:
m.Get("code").Int()
m.Get("code").Int()
If there's no value there (or if it's the wrong type) then a default value will be returned,
or you can be explicit about the default value.
Get("code").Int(-1)
Get("code").Int(-1)
If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating,
manipulating and selecting that data. You can find out more by exploring the index below.
Reading data
# Reading data
A simple example of how to use Objx:
// Use MustFromJSON to make an objx.Map from some JSON
m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)
// Use MustFromJSON to make an objx.Map from some JSON
m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)
// Get the details
name := m.Get("name").Str()
age := m.Get("age").Int()
// Get the details
name := m.Get("name").Str()
age := m.Get("age").Int()
// Get their nickname (or use their name if they don't have one)
nickname := m.Get("nickname").Str(name)
// Get their nickname (or use their name if they don't have one)
nickname := m.Get("nickname").Str(name)
Ranging
# Ranging
Since `objx.Map` is a `map[string]interface{}` you can treat it as such.
For example, to `range` the data, do what you would expect:
m := objx.MustFromJSON(json)
for key, value := range m {
// Your code...
}
m := objx.MustFromJSON(json)
for key, value := range m {
// Your code...
}
*/
package objx
9 changes: 4 additions & 5 deletions map.go
Original file line number Diff line number Diff line change
@@ -47,17 +47,16 @@ func New(data interface{}) Map {
//
// The arguments follow a key, value pattern.
//
//
// Returns nil if any key argument is non-string or if there are an odd number of arguments.
//
// Example
// # Example
//
// To easily create Maps:
//
// m := objx.MSI("name", "Mat", "age", 29, "subobj", objx.MSI("active", true))
// m := objx.MSI("name", "Mat", "age", 29, "subobj", objx.MSI("active", true))
//
// // creates an Map equivalent to
// m := objx.Map{"name": "Mat", "age": 29, "subobj": objx.Map{"active": true}}
// // creates an Map equivalent to
// m := objx.Map{"name": "Mat", "age": 29, "subobj": objx.Map{"active": true}}
func MSI(keyAndValuePairs ...interface{}) Map {
newMap := Map{}
keyAndValuePairsLen := len(keyAndValuePairs)
36 changes: 18 additions & 18 deletions type_specific_codegen_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
)

/*
Tests for Inter (interface{} and []interface{})
Tests for Inter (interface{} and []interface{})
*/
func TestInter(t *testing.T) {
val := interface{}("something")
@@ -130,7 +130,7 @@ func TestCollectInter(t *testing.T) {
}

/*
Tests for Bool (bool and []bool)
Tests for Bool (bool and []bool)
*/
func TestBool(t *testing.T) {
val := bool(true)
@@ -251,7 +251,7 @@ func TestCollectBool(t *testing.T) {
}

/*
Tests for Str (string and []string)
Tests for Str (string and []string)
*/
func TestStr(t *testing.T) {
val := string("hello")
@@ -372,7 +372,7 @@ func TestCollectStr(t *testing.T) {
}

/*
Tests for Int (int and []int)
Tests for Int (int and []int)
*/
func TestInt(t *testing.T) {
val := int(1)
@@ -493,7 +493,7 @@ func TestCollectInt(t *testing.T) {
}

/*
Tests for Int8 (int8 and []int8)
Tests for Int8 (int8 and []int8)
*/
func TestInt8(t *testing.T) {
val := int8(1)
@@ -614,7 +614,7 @@ func TestCollectInt8(t *testing.T) {
}

/*
Tests for Int16 (int16 and []int16)
Tests for Int16 (int16 and []int16)
*/
func TestInt16(t *testing.T) {
val := int16(1)
@@ -735,7 +735,7 @@ func TestCollectInt16(t *testing.T) {
}

/*
Tests for Int32 (int32 and []int32)
Tests for Int32 (int32 and []int32)
*/
func TestInt32(t *testing.T) {
val := int32(1)
@@ -856,7 +856,7 @@ func TestCollectInt32(t *testing.T) {
}

/*
Tests for Int64 (int64 and []int64)
Tests for Int64 (int64 and []int64)
*/
func TestInt64(t *testing.T) {
val := int64(1)
@@ -977,7 +977,7 @@ func TestCollectInt64(t *testing.T) {
}

/*
Tests for Uint (uint and []uint)
Tests for Uint (uint and []uint)
*/
func TestUint(t *testing.T) {
val := uint(1)
@@ -1098,7 +1098,7 @@ func TestCollectUint(t *testing.T) {
}

/*
Tests for Uint8 (uint8 and []uint8)
Tests for Uint8 (uint8 and []uint8)
*/
func TestUint8(t *testing.T) {
val := uint8(1)
@@ -1219,7 +1219,7 @@ func TestCollectUint8(t *testing.T) {
}

/*
Tests for Uint16 (uint16 and []uint16)
Tests for Uint16 (uint16 and []uint16)
*/
func TestUint16(t *testing.T) {
val := uint16(1)
@@ -1340,7 +1340,7 @@ func TestCollectUint16(t *testing.T) {
}

/*
Tests for Uint32 (uint32 and []uint32)
Tests for Uint32 (uint32 and []uint32)
*/
func TestUint32(t *testing.T) {
val := uint32(1)
@@ -1461,7 +1461,7 @@ func TestCollectUint32(t *testing.T) {
}

/*
Tests for Uint64 (uint64 and []uint64)
Tests for Uint64 (uint64 and []uint64)
*/
func TestUint64(t *testing.T) {
val := uint64(1)
@@ -1582,7 +1582,7 @@ func TestCollectUint64(t *testing.T) {
}

/*
Tests for Uintptr (uintptr and []uintptr)
Tests for Uintptr (uintptr and []uintptr)
*/
func TestUintptr(t *testing.T) {
val := uintptr(1)
@@ -1703,7 +1703,7 @@ func TestCollectUintptr(t *testing.T) {
}

/*
Tests for Float32 (float32 and []float32)
Tests for Float32 (float32 and []float32)
*/
func TestFloat32(t *testing.T) {
val := float32(1)
@@ -1824,7 +1824,7 @@ func TestCollectFloat32(t *testing.T) {
}

/*
Tests for Float64 (float64 and []float64)
Tests for Float64 (float64 and []float64)
*/
func TestFloat64(t *testing.T) {
val := float64(1)
@@ -1945,7 +1945,7 @@ func TestCollectFloat64(t *testing.T) {
}

/*
Tests for Complex64 (complex64 and []complex64)
Tests for Complex64 (complex64 and []complex64)
*/
func TestComplex64(t *testing.T) {
val := complex64(1)
@@ -2066,7 +2066,7 @@ func TestCollectComplex64(t *testing.T) {
}

/*
Tests for Complex128 (complex128 and []complex128)
Tests for Complex128 (complex128 and []complex128)
*/
func TestComplex128(t *testing.T) {
val := complex128(1)
4 changes: 2 additions & 2 deletions type_specific_test.go
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import (
)

/*
Tests for MSI (map[string]interface{} and []map[string]interface{})
Tests for MSI (map[string]interface{} and []map[string]interface{})
*/
func TestMSI(t *testing.T) {
val := map[string]interface{}(map[string]interface{}{"name": "Tyler"})
@@ -232,7 +232,7 @@ func TestCollectMSI2(t *testing.T) {
}

/*
Tests for ObjxMap ((objx.Map) and [](objx.Map))
Tests for ObjxMap ((objx.Map) and [](objx.Map))
*/
func TestObjxMap(t *testing.T) {
val := (objx.Map)(objx.New(1))

0 comments on commit 3499ad5

Please sign in to comment.