Go API Documentation

github.com/TykTechnologies/tyk/internal/maps

No package summary is available.

Package

Files: 2. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Types

FlatMap

FlatMap is alias of map[string]string.

Field name Field type Comment
type

map[string]string

No comment on field.
type FlatMap map[string]string

StringMap

StringMap holds a concurrency safe, type safe access to map[string]string. Access is protected with a sync.RWMutex, optimized for reads.

Field name Field type Comment
mu

sync.RWMutex

No comment on field.
data

map[string]string

No comment on field.
type StringMap struct {
	mu	sync.RWMutex
	data	map[string]string
}

Functions

func Flatten

Flatten transforms deep map to flat map.

func Flatten(data map[string]interface{}) (flatmap FlatMap, err error) {
	flatmap = make(FlatMap)
	for k, raw := range data {
		err = flatten(flatmap, k, reflect.ValueOf(raw))
		if err != nil {
			return nil, err
		}
	}
	return
}

Cognitive complexity: 6, Cyclomatic complexity: 3

Uses: reflect.ValueOf.

func NewStringMap

NewStringMap returns a new *StringMap.

func NewStringMap() *StringMap {
	return &StringMap{
		data: make(map[string]string),
	}
}

Cognitive complexity: 1, Cyclomatic complexity: 1

func (*StringMap) Get

Get returns the value, and if it existed in the map.

func (s *StringMap) Get(key string) (string, bool) {
	s.mu.RLock()
	defer s.mu.RUnlock()

	v, ok := s.data[key]
	return v, ok
}

Cognitive complexity: 0, Cyclomatic complexity: 1

func (*StringMap) Set

Set will set a value to a key in the map.

func (s *StringMap) Set(key, value string) {
	s.mu.Lock()
	defer s.mu.Unlock()

	s.data[key] = value
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Private functions

func flatten

flatten (result FlatMap, prefix string, v reflect.Value) error
References: fmt.Errorf, fmt.Sprintf, reflect.Array, reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int8, reflect.Interface, reflect.Invalid, reflect.Map, reflect.Slice, reflect.String, reflect.Struct.

func flattenMap

flattenMap (result FlatMap, prefix string, v reflect.Value) error
References: fmt.Sprintf, reflect.Interface, reflect.String.

func flattenSliceArray

flattenSliceArray (result FlatMap, prefix string, v reflect.Value) error
References: fmt.Sprintf.

func flattenStruct

flattenStruct (result FlatMap, prefix string, v reflect.Value) error
References: fmt.Sprintf.