Documentation ¶
Index ¶
- Variables
- func CompatibleTypes(expected types.Type, actual types.Type) error
- func ImportPathForDir(dir string) (res string)
- func Indirect(t reflect.Type) reflect.Type
- func NameForDir(dir string) string
- func NormalizeVendor(pkg string) string
- func PkgAndType(name string) (string, string)
- func PkgName(ident string) string
- func PkgPath(config *packages.Config, target string) (string, error)
- func PkgShortName(pkgPath string) string
- func QualifyPackagePath(importPath string) string
- func SanitizePackageName(pkg string) string
- func TypeName(ident string) string
- type Packages
- func (p *Packages) Count() int
- func (p *Packages) Errors() PkgErrors
- func (p *Packages) Evict(importPath string)
- func (p *Packages) Load(importPath string) *packages.Package
- func (p *Packages) LoadAll(importPaths ...string) []*packages.Package
- func (p *Packages) LoadWithTypes(importPath string) *packages.Package
- func (p *Packages) ModTidy() error
- func (p *Packages) NameForPackage(importPath string) string
- func (p *Packages) ReloadAll(importPaths ...string) []*packages.Package
- type PkgErrors
- type RType
- type Type
- type TypeInfo
- func (t TypeInfo) Clone() *TypeInfo
- func (t TypeInfo) Comparable() bool
- func (t TypeInfo) ConstName() string
- func (t *TypeInfo) GoType(typ any)
- func (t TypeInfo) Numeric() bool
- func (t TypeInfo) String() string
- func (t TypeInfo) Stringer() bool
- func (t TypeInfo) StructString() string
- func (t TypeInfo) Valid() bool
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = &packages.Config{Mode: packages.NeedName}
DefaultConfig for loading Go base.
Functions ¶
func CompatibleTypes ¶
CompatibleTypes isn't a strict comparison, it allows for pointer differences
func ImportPathForDir ¶
ImportPathForDir takes a path and returns a golang import path for the package
func NameForDir ¶
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 ¶
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 ¶
take a string in the form github.com/package/blah.Type and split it into package and type
func PkgPath ¶
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 QualifyPackagePath ¶
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 ¶
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) Errors ¶
Errors returns any errors that were returned by Load, either from the call itself or any of the loaded packages.
func (*Packages) Evict ¶
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) LoadAll ¶
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 ¶
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) NameForPackage ¶
NameForPackage looks up the package name from the package stanza in the go files at the given import path.
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 (RType) ReflectType ¶
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 ¶
ConstName returns the constant name of a info type. It's used by entc for printing the constant name in templates.
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) Comparable ¶
Comparable reports whether values of this type are comparable.
func (*TypeInfo) GoType ¶
GoType parse by the given Type and reflect.Type. original field will override.