code

package
v0.0.0-...-c19637d Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeBool    = SimpleType("bool")
	TypeInt     = SimpleType("int")
	TypeFloat64 = SimpleType("float64")
	TypeString  = SimpleType("string")
	TypeError   = SimpleType("error")
)

commonly-used types

Variables

View Source
var (
	ErrAmbiguousPackageName = errors.New("code: ambiguous package name")
)

Functions

This section is empty.

Types

type ArrayType

type ArrayType struct {
	ContainedType Type
}

ArrayType is a model of array

func (ArrayType) Code

func (t ArrayType) Code() string

Code returns token string in code format

func (ArrayType) IsNumber

func (t ArrayType) IsNumber() bool

IsNumber returns false

type DuplicateInterfaceError

type DuplicateInterfaceError string

func (DuplicateInterfaceError) Error

func (err DuplicateInterfaceError) Error() string

type DuplicateStructError

type DuplicateStructError string

func (DuplicateStructError) Error

func (err DuplicateStructError) Error() string

type ExternalType

type ExternalType struct {
	PackageAlias string
	Name         string
}

ExternalType is a type that is called to another package

func (ExternalType) Code

func (t ExternalType) Code() string

Code returns token string in code format

func (ExternalType) IsNumber

func (t ExternalType) IsNumber() bool

IsNumber returns false

type File

type File struct {
	PackageName string
	Imports     []Import
	Structs     []Struct
	Interfaces  []InterfaceType
}

File is a container of all required components for code generation in the file

func ExtractComponents

func ExtractComponents(f *ast.File) File

ExtractComponents converts ast file into code components model

type Import

type Import struct {
	Name string
	Path string
}

Import is a model for package imports

type InterfaceType

type InterfaceType struct {
	Name    string
	Methods []Method
}

InterfaceType is a definition of the interface

func (InterfaceType) Code

func (intf InterfaceType) Code() string

Code returns token string in code format

func (InterfaceType) IsNumber

func (intf InterfaceType) IsNumber() bool

IsNumber returns false

type MapType

type MapType struct {
	KeyType   Type
	ValueType Type
}

MapType is a model of map

func (MapType) Code

func (t MapType) Code() string

Code returns token string in code format

func (MapType) IsNumber

func (t MapType) IsNumber() bool

IsNumber returns false

type Method

type Method struct {
	Name     string
	Comments []string
	Params   []Param
	Returns  []Type
}

Method is a definition of the method inside the interface

type Package

type Package struct {
	Name       string
	Structs    map[string]Struct
	Interfaces map[string]InterfaceType
}

Package stores package name, struct and interface implementations as a result from ParsePackage.

func NewPackage

func NewPackage() Package

NewPackage is a constructor function for Package.

func ParsePackage

func ParsePackage(pkgs map[string]*ast.Package) (Package, error)

ParsePackage extracts package name, struct and interface implementations from map[string]*ast.Package. Test files will be ignored.

type Param

type Param struct {
	Name string
	Type Type
}

Param is a model of method parameter

type PointerType

type PointerType struct {
	ContainedType Type
}

PointerType is a model of pointer

func (PointerType) Code

func (t PointerType) Code() string

Code returns token string in code format

func (PointerType) IsNumber

func (t PointerType) IsNumber() bool

IsNumber returns IsNumber of its contained type

type SimpleType

type SimpleType string

SimpleType is a type that can be called directly

func (SimpleType) Code

func (t SimpleType) Code() string

Code returns token string in code format

func (SimpleType) IsNumber

func (t SimpleType) IsNumber() bool

IsNumber returns true id a SimpleType is integer or float variants.

type Struct

type Struct struct {
	Name   string
	Fields StructFields
}

Struct is a definition of the struct

func (Struct) ReferencedType

func (str Struct) ReferencedType() Type

ReferencedType returns a type variable of this struct

type StructField

type StructField struct {
	Name string
	Type Type
	Tag  reflect.StructTag
}

StructField is a definition of the struct field

type StructFields

type StructFields []StructField

StructFields is a group of the StructField model

func (StructFields) ByName

func (fields StructFields) ByName(name string) (StructField, bool)

ByName return struct field with matching name

type Type

type Type interface {
	Code() string
	IsNumber() bool
}

Type is an interface for value types

Jump to

Keyboard shortcuts

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