code

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = &packages.Config{Mode: packages.NeedName}

DefaultConfig for loading Go base.

Functions

func CompatibleTypes

func CompatibleTypes(expected types.Type, actual types.Type) error

CompatibleTypes isn't a strict comparison, it allows for pointer differences

func ImportPathForDir

func ImportPathForDir(dir string) (res string)

ImportPathForDir takes a path and returns a golang import path for the package

func Indirect

func Indirect(t reflect.Type) reflect.Type

Indirect returns the type at the end of indirection.

func NameForDir

func NameForDir(dir string) string

NameForDir manually looks for package stanzas in files located in the given directory. This can be much faster than having to consult go list, because we already know exactly where to look.

func NormalizeVendor

func NormalizeVendor(pkg string) string

NormalizeVendor takes a qualified package path and turns it into normal one. eg . github.com/foo/vendor/github.com/99designs/gqlgen/graphql becomes github.com/99designs/gqlgen/graphql

func PkgAndType

func PkgAndType(name string) (string, string)

take a string in the form github.com/package/blah.Type and split it into package and type

func PkgName

func PkgName(ident string) string

PkgName returns the package name from a Go identifier with a package qualifier.

func PkgPath

func PkgPath(config *packages.Config, target string) (string, error)

PkgPath returns the Go package name for given target path. Even if the existing path is not exist yet in the filesystem.

If base.Config is nil, DefaultConfig will be used to load base.

func PkgShortName

func PkgShortName(pkgPath string) string

func QualifyPackagePath

func QualifyPackagePath(importPath string) string

QualifyPackagePath takes an import and fully qualifies it with a vendor dir, if one is required. eg . github.com/99designs/gqlgen/graphql becomes github.com/foo/vendor/github.com/99designs/gqlgen/graphql

x/tools/packages only supports 'qualified package paths' so this will need to be done prior to calling it See https://github.com/golang/go/issues/30289

func SanitizePackageName

func SanitizePackageName(pkg string) string

func TypeName

func TypeName(ident string) string

TypeName returns the element type name from a Go identifier with a package qualifier.

Types

type Packages

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

Packages is a wrapper around x/tools/go/packages that maintains a (hopefully prewarmed) cache of packages that can be invalidated as writes are made and packages are known to change.

func (*Packages) Count

func (p *Packages) Count() int

func (*Packages) Errors

func (p *Packages) Errors() PkgErrors

Errors returns any errors that were returned by Load, either from the call itself or any of the loaded packages.

func (*Packages) Evict

func (p *Packages) Evict(importPath string)

Evict removes a given package import path from the cache, along with any packages that depend on it. Further calls to Load will fetch it from disk.

func (*Packages) Load

func (p *Packages) Load(importPath string) *packages.Package

Load works the same as LoadAll, except a single package at a time.

func (*Packages) LoadAll

func (p *Packages) LoadAll(importPaths ...string) []*packages.Package

LoadAll will call packages.Load and return the package data for the given packages, but if the package already have been loaded it will return cached values instead.

func (*Packages) LoadWithTypes

func (p *Packages) LoadWithTypes(importPath string) *packages.Package

LoadWithTypes tries a standard load, which may not have enough type info (TypesInfo== nil) available if the imported package is a second order dependency. Fortunately this doesnt happen very often, so we can just issue a load when we detect it.

func (*Packages) ModTidy

func (p *Packages) ModTidy() error

func (*Packages) NameForPackage

func (p *Packages) NameForPackage(importPath string) string

NameForPackage looks up the package name from the package stanza in the go files at the given import path.

func (*Packages) ReloadAll

func (p *Packages) ReloadAll(importPaths ...string) []*packages.Package

ReloadAll will call LoadAll after clearing the package cache, so we can reload packages in the case that the packages have changed

type PkgErrors

type PkgErrors []error

func (PkgErrors) Error

func (p PkgErrors) Error() string

type RType

type RType struct {
	Name    string // reflect.Type.Name
	Ident   string // reflect.Type.String
	Kind    reflect.Kind
	PkgPath string
	Methods map[string]struct{ In, Out []*RType }
	// contains filtered or unexported fields
}

RType holds a serializable reflect.Type information of Go object. Used by the entc package.

func ParseGoType

func ParseGoType(typ any) (*RType, error)

func (*RType) IsPtr

func (r *RType) IsPtr() bool

IsPtr reports if the reflect-type is a pointer type.

func (RType) ReflectType

func (r RType) ReflectType() reflect.Type

func (*RType) String

func (r *RType) String() string

RType returns the string value of the Indirect reflect.Type.

func (*RType) TypeEqual

func (r *RType) TypeEqual(t reflect.Type) bool

TypeEqual reports if the underlying type is equal to the RType (after pointer indirections).

type Type

type Type uint8

A Type represents a field type.

const (
	TypeInvalid Type = iota
	TypeBool
	TypeTime
	TypeJSON
	TypeUUID
	TypeBytes
	TypeEnum
	TypeString
	TypeOther
	TypeInt8
	TypeInt16
	TypeInt32
	TypeInt
	TypeInt64
	TypeUint8
	TypeUint16
	TypeUint32
	TypeUint
	TypeUint64
	TypeFloat32
	TypeFloat64
)

List of field types.

func (Type) ConstName

func (t Type) ConstName() string

ConstName returns the constant name of a info type. It's used by entc for printing the constant name in templates.

func (Type) Float

func (t Type) Float() bool

Float reports if the given type is a float type.

func (Type) Integer

func (t Type) Integer() bool

Integer reports if the given type is an integral type.

func (Type) Numeric

func (t Type) Numeric() bool

Numeric reports if the given type is a numeric type.

func (Type) String

func (t Type) String() string

String returns the string representation of a type.

func (Type) Valid

func (t Type) Valid() bool

Valid reports if the given type if known type.

type TypeInfo

type TypeInfo struct {
	Type     Type
	Ident    string
	PkgPath  string // import path.
	PkgName  string // local package name.
	Nillable bool   // slices,map or pointers.
	RType    *RType
}

TypeInfo holds the information regarding field type. Used by complex types like JSON and Bytes.

func (TypeInfo) Clone

func (t TypeInfo) Clone() *TypeInfo

Clone returns a copy.

func (TypeInfo) Comparable

func (t TypeInfo) Comparable() bool

Comparable reports whether values of this type are comparable.

func (TypeInfo) ConstName

func (t TypeInfo) ConstName() string

ConstName returns the const name of the info type.

func (*TypeInfo) GoType

func (t *TypeInfo) GoType(typ any)

GoType parse by the given Type and reflect.Type. original field will override.

func (TypeInfo) Numeric

func (t TypeInfo) Numeric() bool

Numeric reports if the given type is a numeric type.

func (TypeInfo) String

func (t TypeInfo) String() string

String returns the string representation of a type.

func (TypeInfo) Stringer

func (t TypeInfo) Stringer() bool

Stringer indicates if this type implements the Stringer interface.

func (TypeInfo) StructString

func (t TypeInfo) StructString() string

func (TypeInfo) Valid

func (t TypeInfo) Valid() bool

Valid reports if the given type if known type.

Jump to

Keyboard shortcuts

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