libs

package
v0.0.0-...-7818d9c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func RandToken

func RandToken(len int) string

func ToJSON

func ToJSON(data interface{}) (string, error)

ToJSON encodes any data into a JSON string

func ToJSONString

func ToJSONString(data interface{}) string

ToJSONString encodes any data into a JSON string if it fails it returns null

Types

type AtomicBool

type AtomicBool struct {
	// contains filtered or unexported fields
}

AtomicBool implements a thread safe boolean

func (*AtomicBool) Get

func (b *AtomicBool) Get() bool

Get returns the boolean value

func (*AtomicBool) Set

func (b *AtomicBool) Set(val bool)

Set sets the boolean value

func (*AtomicBool) Swap

func (b *AtomicBool) Swap(val bool) bool

Swap sets a new value and returns the old value

type Done

type Done struct {
	// contains filtered or unexported fields
}

Done can be used to broadcast safely a done message across multiple goroutines

func NewDone

func NewDone() Done

NewDone creates a new done struct

func (Done) Done

func (c Done) Done()

Done closes the done channel (safe to call multiple times)

func (Done) Wait

func (c Done) Wait()

Wait returns once the Done function is called

func (Done) WaitCh

func (c Done) WaitCh() <-chan bool

WaitCh returns a channel that will be closed when the done function is called

type JSONArray

type JSONArray []interface{}

JSONArray provides convenience methods for arrays returned by the go JSON parser

func (JSONArray) JSON

func (data JSONArray) JSON() (string, error)

JSON encodes this JSONData object into a JSON string

func (JSONArray) String

func (data JSONArray) String() string

String encodes this JSONData object into a JSON string Like JSON but returns "{}" if it fails

type JSONBool

type JSONBool bool

JSONBool provides json convenience methods for booleans

func (JSONBool) JSON

func (b JSONBool) JSON() (string, error)

JSON encodes this boolean into a JSON string

func (JSONBool) String

func (b JSONBool) String() string

String encodes this boolean into a JSON string

func (JSONBool) Type

func (b JSONBool) Type() string

Type returns the type of this JSONData entity

type JSONData

type JSONData interface {
	JSON() (string, error)
	String() string
	Type() string
}

JSONData is the common interface for JSONObject and JSONBool

type JSONObject

type JSONObject map[string]interface{}

JSONObject provides convenience methods for maps returned by the go JSON parser

func ParseJSON

func ParseJSON(jsonStr []byte) (JSONObject, error)

ParseJSON parses a JSON string and returns a JSONObject

func (JSONObject) GetAny

func (data JSONObject) GetAny(key string) (interface{}, bool)

GetAny returns any value from the JSON object

func (JSONObject) GetArray

func (data JSONObject) GetArray(key string) (JSONArray, bool)

GetArray returns a value from the JSON object as JsonData

func (JSONObject) GetBool

func (data JSONObject) GetBool(key string) (bool, bool)

GetBool returns a value from the JSON object as a boolean

func (JSONObject) GetKeys

func (data JSONObject) GetKeys() []string

GetKeys returns an array of all the keys in this JSON object

func (JSONObject) GetNum

func (data JSONObject) GetNum(key string) *float64

GetNum returns a value from the JSON object as a float64 or nil if not present or not a number

func (JSONObject) GetNumber

func (data JSONObject) GetNumber(key string) (float64, bool)

GetNumber returns a value from the JSON object as a float64

func (JSONObject) GetObj

func (data JSONObject) GetObj(key string) (JSONObject, bool)

GetObj returns a value from the JSON object as JsonData

func (JSONObject) GetString

func (data JSONObject) GetString(key string) (string, bool)

GetString returns a value from the JSON object as string

func (JSONObject) HasKey

func (data JSONObject) HasKey(key string) bool

HasKey returns true if the key is present

func (JSONObject) JSON

func (data JSONObject) JSON() (string, error)

JSON encodes this JSONData object into a JSON string

func (JSONObject) SetNumber

func (data JSONObject) SetNumber(key string, val float64) bool

SetNumber sets a float64 number on the object if it is not NaN

func (JSONObject) String

func (data JSONObject) String() string

String encodes this JSONData object into a JSON string Like JSON but returns "{}" if it fails

func (JSONObject) Type

func (data JSONObject) Type() string

Type returns the type of this JSONData entity

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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