astrix

package module
v0.0.0-...-208a59c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 11 Imported by: 0

README

astrix

Astrix exists to help with code generation as working with AST isn't the most enjoyable thing in the world.

Documentation

Index

Constants

View Source
const (
	TypeUnknown primitiveType = iota
	TypeInt
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt64
	TypeUint
	TypeUint8
	TypeUint16
	TypeUint32
	TypeUint64
	TypeFloat32
	TypeFloat64
	TypeStruct
	TypeMap
	TypeString
	TypeSlice
	TypeInterface
	TypeBool
	TypePointer
)

Variables

This section is empty.

Functions

func DefaultValue

func DefaultValue(t primitiveType) (result string, success bool)

func FindFiles

func FindFiles(path string, except *regexp.Regexp) (files []os.FileInfo, err error)

GetFiles returns a list of files from the pkg of your choice. To be sure, just use an absolute path which can be retrieved from runtime:

 package main

 import (
   "fmt"
   "path/filepath"
   "runtime"

   "github.com/andersfylling/ggi"
  )

  var (
    _, b, _, _ = runtime.Caller(0)
    basepath   = filepath.Dir(b)
    genpath    = "/generate/testing" // diff path; from root pkg to this files pkg
  )

  func main() {
	   path := basepath[:len(basepath)-len(genpath)]
	   files, err := astrix.FindFiles(path, regexp.MustCompile(".*\_gen\.go"))
	   if err != nil {
      panic(err)
    }

    // TODO: make sure these prints the .go files in your desired directory
    for _, f := range files {
      fmt.Println(f.Name())
    }
  }

func ToCamelCase

func ToCamelCase(s string) string

ToCamelCase takes typical CONST names such as T_AS and converts them to TAs. TEST_EIN_TRES => TestEinTres

Types

type Data

type Data struct {
	PackageName string
}

type FieldInfo

type FieldInfo struct {
	Pointer bool
	*TypeInfo
}

type InterfaceInfo

type InterfaceInfo struct {
	Name    string
	Methods []string
}

type TypeInfo

type TypeInfo struct {
	T                  *TypeInfo
	PrimitiveType      primitiveType
	DefaultValueString string
	Name               string
	Fields             map[string]*FieldInfo
	Exported           bool
}

func GetTypes

func GetTypes(path string, excludeFilesRegexp *regexp.Regexp, excludeTypesRegexp *regexp.Regexp) (types []*TypeInfo, err error)

GenerateTypes generates a list of types that can be reflected upon.

func GetTypesFromFile

func GetTypesFromFile(file *ast.File, exclude *regexp.Regexp) (types []*TypeInfo, err error)

func (*TypeInfo) Is

func (t *TypeInfo) Is(pt primitiveType) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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