depths

package
v0.0.0-...-05bd1a1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Flatten makes flat, one-dimensional maps from arbitrarily nested ones.

It turns map keys into compound names, in four styles: dotted (`a.b.1.c`), path-like (`a/b/1/c`), Rails (`a[b][1][c]`), or with underscores (`a_b_1_c`). It takes input as either JSON strings or Go structures. It knows how to traverse these JSON types: objects/maps, arrays and scalars.

You can flatten JSON strings.

nested := `{
  "one": {
    "two": [
      "2a",
      "2b"
    ]
  },
  "side": "value"
}`

flat, err := flatten.FlattenString(nested, "", flatten.DotStyle)

// output: `{ "one.two.0": "2a", "one.two.1": "2b", "side": "value" }`

Or Go maps directly.

nested := map[string]interface{}{
	"a": "b",
	"c": map[string]interface{}{
		"d": "e",
		"f": "g",
	},
	"z": 1.4567,
}

flat, err := flatten.Flatten(nested, "", flatten.RailsStyle)

// output:
// map[string]interface{}{
//	"a":    "b",
//	"c[d]": "e",
//	"c[f]": "g",
//	"z":    1.4567,
// }

Index

Constants

This section is empty.

Variables

View Source
var NotValidInputError = errors.New("Not a valid input: map or slice")

Nested input must be a map or slice

Functions

func BytesToInts

func BytesToInts(postings []byte) []int32

func BytesToUints

func BytesToUints(postings []byte) []uint32

func Cleanup

func Cleanup(s string) string

func CleanupAllowDot

func CleanupAllowDot(s string) string

func CleanupVW

func CleanupVW(s string) string

func CreateTopic

func CreateTopic(brokers string, topic string, partitions int, replication int) error

func DumpObj

func DumpObj(src interface{}) string

func DumpObjNoIndent

func DumpObjNoIndent(src interface{}) string

func Flatten

func Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]string, error)

Flatten generates a flat map from a nested one. The original may include values of type map, slice and scalar, but not struct. Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style. A prefix is joined to each key.

func FlattenArray

func FlattenArray(nested []interface{}, prefix string, style SeparatorStyle) (map[string]string, error)

func FlattenString

func FlattenString(nestedstr, prefix string, style SeparatorStyle) (string, error)

FlattenString generates a flat JSON map from a nested one. Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style. A prefix is joined to each key.

func ForeachCSV

func ForeachCSV(csv string, cb func(a, b string))

func Hash

func Hash(s []byte) uint64

func Hashs

func Hashs(s string) uint64

func HealthCheckKafka

func HealthCheckKafka(brokers string, topic string) error

func IntsToBytes

func IntsToBytes(postings []int32) []byte

func IsDigit

func IsDigit(s string) bool

func PathForTag

func PathForTag(root, tagKey, tagValue string) (string, string)

func SegmentFromNs

func SegmentFromNs(ns int64) string

func SegmentFromNsInt

func SegmentFromNsInt(ns int64) int64

func ShuffledStrings

func ShuffledStrings(list []string) []string

func UintsToBytes

func UintsToBytes(postings []uint32) []byte

func UnmarshalAndClose

func UnmarshalAndClose(c *gin.Context, into proto.Message) error

Types

type SeparatorStyle

type SeparatorStyle int

The presentation style of keys.

const (

	// Separate nested key components with dots, e.g. "a.b.1.c.d"
	DotStyle SeparatorStyle

	// Separate with path-like slashes, e.g. a/b/1/c/d
	PathStyle

	// Separate ala Rails, e.g. "a[b][c][1][d]"
	RailsStyle

	// Separate with underscores, e.g. "a_b_1_c_d"
	UnderscoreStyle
)

Jump to

Keyboard shortcuts

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