mr

package
v4.14.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package mr implements cached functionality for efficient introspection of models and other related structs. It is used to implement the generic reflect-based indexes and selective JSON streaming in the front end.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(a, b interface{}) bool

func Fetch

func Fetch(v interface{}, fields ...string) (res interface{}, found bool)

func IsText

func IsText(t reflect.Type) bool

IsText indicates that this field will be marshalled and unmarshalled into a string. Fields uses it to skip processing for certain fields.

func K

func K(t reflect.Type) reflect.Kind

K resolves the passed in reflect.Type down to its base Kind.

func ReallyAMap

func ReallyAMap(v interface{}, x func(interface{}) interface{})

ReallyAMap is used to signal to this package that the passed-in type for v is really just a Map under the hood, and x should be used to resolve down to the map in question. It should be called during init() before Fields is called for the first time.

func T

func T(t reflect.Type) reflect.Type

T resolves the passed-in reflect.Type down to its base Type.

func TK

TK resolves the passed-in reflect.Type down to the underlying Type and Kind. Pointers and Interfaces are skipped through.

func V

V resolves a reflect.Value down to its base reflect.Value. Pointers and interface indirection will be resolved.

Types

type F

type F struct {
	// Docs is the docs for this struct/map
	Docs string
	// TopLevel returns all the keys that can be accessed directly on a struct,
	// and everything in a specific map.  It includes embedded structs.
	TopLevel []string
	// All returns all the fields that can be accessed via s struct or map.  Indirections to
	// other structs are indicated by having a / in the value.
	All []string
	// contains filtered or unexported fields
}

F keeps track of everything needed to look up values in an arbitrary struct or map.

func Fields

func Fields(m interface{}) *F

Fields translates m into an F. m must be a Struct or a Map. If m is a Map, F will not be cached for later reuse. If M is a Struct, then F will be cached for later reuse. If m us neither a Struct or a Map, then F will be nil.

func (*F) Field

func (f *F) Field(v string) Field

Field returns a reflect.StructField describing what kind of data is stored in the passed-in v.

type Field

type Field struct {
	Value
	Index struct {
		Name   string
		Key    bool
		Unique bool
		Ignore bool
		Shard  bool
		NoEq   bool
	}
	Json struct {
		Name      string
		Ignore    bool
		OmitEmpty bool
	}
	Options options
	reflect.StructField
}

Field is a reflect.StructField, some useful pre-parsed tag information, and a function that can fetch something from the location of the Field.

type Value

type Value func(interface{}) reflect.Value

Value is a function that can be used to pluck an arbitrary value out of a struct based on its name.

Jump to

Keyboard shortcuts

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