function

package
v0.0.0-...-d2861cf Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2018 License: MIT Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFunc

func IsFunc(fun interface{}) (b bool)

IsFunc returns true if interface fun is a function or method and false otherwise.

func Name

func Name(fun interface{}) (s string)

Name returns name of the function as a string s. Name will panic if function is not a function or method.

func Signature

func Signature(fun interface{}, name ...string) (sgn string)

Signature returns the function signature of any function or method. Signature accepts an optional name parameter used in the function signature. Signature will panic if function is not a function or method.

func Type

func Type(fun interface{}) (t reflect.Type)

Type returns the type of a function or method.

Types

type CallerInfo

type CallerInfo struct {
	File string
	Line int
	Pkg  string
	Func string
}

CallerInfo is a structure for containing function caller information.

func ExtractCallerInfo

func ExtractCallerInfo(depth int) (ci CallerInfo)

ExtractCallerInfo returns caller info associated to a function call given a depth. ExtractCallerInfo returns unknown caller info if frame unwinding fails.

type Function

type Function interface{}

Function is a representation of a function.

type FunctionBinding

type FunctionBinding struct {
	Binding *sync.Map // [*Namespace]Function
}

FunctionBinding maintains a function binding.

func NewFunctionBinding

func NewFunctionBinding() (fb FunctionBinding)

NewFunctionBinding creates a binding between a reference to a namespace and a function.

func (*FunctionBinding) Add

func (fb *FunctionBinding) Add(ref *Namespace, fun *Function) (status bool)

Add a binding to fb between a namespace ref and function fun. Add returns true if the addition of the binding was successful, and false otherwise.

func (*FunctionBinding) Function

func (fb *FunctionBinding) Function(ref *Namespace) (fun *Function)

Function returns a pointer to function fun given a namespace reference ref. Function returns nil if no function is a attached to the namespace reference ref.

func (*FunctionBinding) Remove

func (fb *FunctionBinding) Remove(ref *Namespace) (status bool)

Remove a binding from fb given a namespace reference ref. Remove returns true if the removal of the binding was successful, and false otherwise.

func (FunctionBinding) String

func (fb FunctionBinding) String() (s string)

String returns a print friendly representation of a function binding fb.

type LanguageBinding

type LanguageBinding struct {
	InternalToExternal *sync.Map // [*Namespace]*Namespace
	ExternalToInternal *sync.Map // [*Namespace]*Namespace
}

LanguageBinding is a structure to maintain a function mapping between two languages.

func NewLanguageBinding

func NewLanguageBinding() (lb LanguageBinding)

NewLanguageBinding creates a two-way binding lb between two namespaces in two different languages.

func (*LanguageBinding) Add

func (lb *LanguageBinding) Add(a *Namespace, b *Namespace) (status bool)

Add will add a new language binding between two namespaces a and b. Add returns true if the addition of namespace ns was successful, and false otherwise.

func (*LanguageBinding) External

func (lb *LanguageBinding) External(inter *Namespace) (exter *Namespace)

External returns the external namespace reference exter given an internal namespace reference inter. External returns nil if the internal namespace reference inter could not be found.

func (*LanguageBinding) Internal

func (lb *LanguageBinding) Internal(exter *Namespace) (inter *Namespace)

Internal returns the internal namespace reference a given an external namespace reference b. Internal returns nil if the internal namespace reference a could not be found.

func (*LanguageBinding) RemoveInternal

func (lb *LanguageBinding) RemoveInternal(ns *Namespace) (status bool)

RemoveInternal removes a binding for the internal namespace ns from the language bindings dictionary lb. RemoveInternal returns true if the removal of the binding namespace ns was successful, and false otherwise.

func (LanguageBinding) String

func (lb LanguageBinding) String() (s string)

String returns a print friendly representation of a language binding lb.

type Namespace

type Namespace string

Namespace is a representation of a location of a function.

func NewNamespace

func NewNamespace(s string) (ns Namespace)

NewNamespace creates a new namespace from a string.

func (*Namespace) DeepCopy

func (ref *Namespace) DeepCopy() (ns Namespace)

DeepCopy creates a copy of a namespace ref.

func (*Namespace) String

func (ref *Namespace) String() (s string)

String returns a print friendly representation of namespace ref.

type NamespaceDictionary

type NamespaceDictionary struct {
	RefLookUp  *sync.Map // [*Namespace]Namespace
	NameLookUp *sync.Map // [Namespace]*Namespace
}

NamespaceDictionary is a representation for looking up namespaces names.

func NewNamespaceDictionary

func NewNamespaceDictionary() (nsd NamespaceDictionary)

NewNamespaceDictionary creates a two-way dictionary for looking up between a reference of a namespace and namespace itself.

func (*NamespaceDictionary) Add

func (nsd *NamespaceDictionary) Add(ns Namespace) (status bool)

Add will add a namespace ns to a namespace dictionary nsd. Add returns true if the addition of namespace ns was successful, and false otherwise.

func (*NamespaceDictionary) Reference

func (nsd *NamespaceDictionary) Reference(ns Namespace) (ref *Namespace)

Reference returns a reference ref for the namespace ns from namespace dictionary nsd.

func (*NamespaceDictionary) Remove

func (nsd *NamespaceDictionary) Remove(ns Namespace) (status bool)

Remove will remove a namespace ns from the namespace dictionary nsd. Remove returns true if the removal of namespace ns, and false otherwise.

func (NamespaceDictionary) String

func (nsd NamespaceDictionary) String() (s string)

String returns a print friendly representation of a namespace dictionary nsd.

func (*NamespaceDictionary) Value

func (nsd *NamespaceDictionary) Value(ref *Namespace) (ns Namespace)

Value returns a namespace value ns from a namespace dictionary nsd given a reference ref.

type Registry

type Registry struct {
	NameDict NamespaceDictionary
	FuncBind FunctionBinding
	LangBind LanguageBinding
}

Registry represents the available functions between languages.

var GlobalRegistry *Registry

GlobalRegistry is the global function registry used throughout the library.

func NewRegistry

func NewRegistry() (fr Registry)

NewRegistry creates a function registry.

func (*Registry) Check

func (fr *Registry) Check(fun Function) (status bool)

Check performs a check if function fun is registered in function registry fr. Check returns true if function fun is registered, and false otherwise.

func (*Registry) Decode

func (fr *Registry) Decode(exter Namespace) (fun *Function)

Decode returns a function fun given an external namespace ns. Decode returns nil if the function could not be found.

func (*Registry) Encode

func (fr *Registry) Encode(fun Function) (exter *Namespace)

Encode returns a pointer to an external namespace ns for function fun. Encode returns nil if the function could not be encoded.

func (*Registry) Register

func (fr *Registry) Register(fun Function) (status bool)

Register performs a registring of function fun to function registry fr. Register returns true if registring of function fun was succesful, and false otherwise.

func (*Registry) Unregister

func (fr *Registry) Unregister(fun Function) (status bool)

Unregister performs a unregistring of function fun from function registry fr. Unregister returns true if unregistring of function fun was succesful, and false otherwise.

Jump to

Keyboard shortcuts

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