Documentation

Overview

    Package sourcereflect implements run-time source reflection, allowing a program to look up string representation of objects from the underlying .go source files.

    Specifically, it implements ability to get name of caller funcs and their parameters. It also implements functionality to get a string containing source code of provided func.

    In order to succeed, it expects the program's source code to be available in normal location. It's intended to be used for development purposes, or for experimental programs.

    Example
    Output:
    
    Name of var: thisIsAFunkyVarName
    Some func name: strings.HasPrefix
    Name of second arg: thisIsAFunkyVarName
    
    Example (GetLineStartEndIndicies)
    Output:
    
    0: [0, 4]
    1: [5, 5]
    2: [6, 27]
    3: [28, 31]
    4: [32, 37]
    5: [38, 42]
    6: [-1, -1]
    
    Example (Nil)
    Output:
    
    nil
    
    Example (TrickyCases)
    Output:
    
    1 2 3 4: 2 2
    Name of second arg: <expr not found>
    
    Example (Two)
    Output:
    
    func(a int, b int) int {
    	c := a + b
    	return c
    }
    

    Index

    Examples

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func GetExprAsString

    func GetExprAsString(_ interface{}) string

      GetExprAsString gets the expression as a string.

      Example
      Output:
      
      Name of var: thisIsAFunkyVarName
      

      func GetFuncValueSourceAsString

      func GetFuncValueSourceAsString(fv reflect.Value) string

        GetFuncValueSourceAsString returns the source of the func value fv.

        Example
        Output:
        
        func(a int, b int) int {
        	c := a + b
        	return c
        }
        

        func GetParentArgExprAllAsString

        func GetParentArgExprAllAsString() []string

          GetParentArgExprAllAsString gets all argument expressions of parent func call as a string.

          func GetParentArgExprAsString

          func GetParentArgExprAsString(argIndex uint32) string

            GetParentArgExprAsString gets the argIndex argument expression of parent func call as a string.

            func GetParentFuncArgsAsString

            func GetParentFuncArgsAsString(args ...interface{}) string

              GetParentFuncArgsAsString gets the parent func with its args as a string.

              func GetParentFuncAsString

              func GetParentFuncAsString() string

                GetParentFuncAsString gets the parent func as a string.

                func GetSourceAsString

                func GetSourceAsString(f interface{}) string

                  GetSourceAsString returns the source of the func f.

                  Example
                  Output:
                  
                  func() {
                  	println("Hello from anon func!")
                  }
                  

                  Types

                  This section is empty.