typer

package module
v0.0.0-...-ad77b29 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

This package has been pulled into the typer-site repository so won't be updated. Probably best that no one uses it anyways

Typer is a package that can take in a .go file as an io.Reader and parse all the types to extract data such as signatures, fields, and methods. It can then associate the methods with their types. Eventually there will be a website built around this to allow users to search for concrete types that satisfy interfaces. As of the the usage is as follows:

r := *Some io.Reader*
//Create a new initialized typer
t := typer.NewTyper()
//Pass in a file to be parsed by the typer. This will extract the interfaces, structs, and methods
t.Parse(r)
//This iterates over the extracted methods and assigns them to their respective structs
t.ResolveMethods()

The parsed interfaces, structs, types, and methods can then be retrieved using any of the get methods e.g t.GetMethods

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcreteType

type ConcreteType struct {
	Package  string            `json:"Package"`
	Name     string            `json:"Name"`
	BaseType string            `json:"BaseType"`
	Fields   map[string]string `json:"Fields"`
	Methods  []Method          `json:"Methods"`
}

ConcreteType represents a defined type with methods on it, regardless of the base type.

type Interface

type Interface struct {
	Package  string   `json:"Package"`
	Name     string   `json:"Name"`
	BaseType string   `json:"BaseType"`
	Methods  []Method `json:"Methods"`
}

Interface holds the information about an interface including what methods it requires.

type Method

type Method struct {
	Package      string   `json:"Package"`
	Receiver     string   `json:"Receiver"`
	Name         string   `json:"Name"`
	Parameters   []string `json:"Parameters"`
	ReturnValues []string `json:"ReturnValues"`
}

Method is a type to hold all the information needed to associate a method with a type

type Typer

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

Typer can parse go files to extract the types from the file and extract all the information about each type including fields, methods, and signatures.

func NewTyper

func NewTyper() *Typer

NewTyper returns an already initialized Typer, ready to parse files.

func (*Typer) GetConcreteTypes

func (t *Typer) GetConcreteTypes() []ConcreteType

GetConcreteTypes returns the ConcreteTypes that Typer has parsed so far

func (*Typer) GetInterfaces

func (t *Typer) GetInterfaces() []Interface

GetInterfaces returns the Interfaces that Typer has parsed so far

func (*Typer) GetMethods

func (t *Typer) GetMethods() []Method

GetMethods returns the Methods that Typer has parsed so far

func (*Typer) Parse

func (t *Typer) Parse(source io.Reader) error

Parse reads the given io.Reader and parses the interfaces within

func (*Typer) ResolveMethods

func (t *Typer) ResolveMethods()

ResolveMethods takes the methods that have already been parsed and associate them with their respective receivers

Jump to

Keyboard shortcuts

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