Documentation
¶
Index ¶
- Constants
- Variables
- type GoField
- type GoFieldOptionFunc
- type GoType
- func AddImportInfo(gt *GoType, alias, packagePath string) *GoType
- func BuiltInType(name, alias, path string) *GoType
- func KnownTypes() []*GoType
- func MustTypeFrom(t reflect.Type) *GoType
- func NewArray(element *GoType) *GoType
- func NewAutoImportType(importType *config.ImportedTypeConfig) *GoType
- func NewOpaqueType(name string) *GoType
- func NewPrimitive(name, kind string) *GoType
- func NewStruct(name string, fields []*GoField) *GoType
- func SetAlias(gt *GoType, alias string) *GoType
- func TypeFrom(t reflect.Type) (*GoType, error)
- type Request
- type TypeDict
- func (td TypeDict) Add(gt *GoType)
- func (td TypeDict) AddAll(goTypes ...*GoType)
- func (td TypeDict) Get(name string) (*GoType, bool)
- func (td TypeDict) Has(gt *GoType) bool
- func (td TypeDict) MarkGenerated(gt *GoType)
- func (td *TypeDict) RenameField(gf *GoField, parentNames []string) error
- func (td TypeDict) RenameType(parentNames []string, gt *GoType) error
- func (td TypeDict) WasGenerated(gt *GoType) bool
Constants ¶
const ( UnsupportedKind = "unsupported" StructKind = "struct" ArrayKind = "array" StringKind = "string" IntKind = "int" Uint64Kind = "uint64" FloatKind = "float64" BoolKind = "bool" MapKind = "map" OpaqueKind = "opaque" AutoImportKind = "autoImport" )
const PACKAGE_BASE = "github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go"
Variables ¶
var ( JSONType = BuiltInType("JSON", "apiextensionsv1", "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1") TimeType = BuiltInType("Time", "metav1", "k8s.io/apimachinery/pkg/apis/meta/v1") )
Functions ¶
This section is empty.
Types ¶
type GoField ¶
type GoField struct {
Comment string
Required bool
Name string
Key string
GoType *GoType
CustomJSONTag string
}
GoField is a field in a Go struct
func NewEmbeddedField ¶
NewEmbeddedField creates and embedded field, without a name
func NewGoField ¶
NewGoField creates a new GoField with the given name and GoType
func NewGoFieldWithKey ¶
NewGoFieldWithKey creates a new GoField with the given name, key, and GoType
func (*GoField) IsEmbedded ¶
IsEmbedded returns whether nor not his field is an embedded one
func (*GoField) Signature ¶
Signature generates a unique signature for a GoField using the type Signature
func (*GoField) WithOptions ¶
func (gt *GoField) WithOptions(opts ...GoFieldOptionFunc) *GoField
type GoFieldOptionFunc ¶
type GoFieldOptionFunc func(*GoField)
func Required ¶
func Required(required bool) GoFieldOptionFunc
Required option sets the required flag
type GoType ¶
type GoType struct {
Name string
Kind string
Fields []*GoField
Element *GoType
Import *config.ImportInfo
}
GoType represents a Go type, which can be a primitive type, a struct, or an array. It is used in conjunbction with TypeDict to track and ensure unique type names.
func AddImportInfo ¶
AddImportInfo allows to attach the import information to a type
func BuiltInType ¶
func KnownTypes ¶
func KnownTypes() []*GoType
func MustTypeFrom ¶
func NewAutoImportType ¶
func NewAutoImportType(importType *config.ImportedTypeConfig) *GoType
NewAutoImportType creates a new GoType representing an opaque type with hidden internals
func NewOpaqueType ¶
NewOpaqueType creates a new GoType representing an opaque type with hidden internals
func NewPrimitive ¶
NewPrimitive creates a new GoType representing a primitive type
func (*GoType) BaseType ¶
BaseType returns the base type of the GoType. If a type is an array, it returns the element type, traversing until a non-array type is found.
func (*GoType) CloneStructure ¶
CloneStructure copies the structure of another type, but leaved the name and import info intact
func (*GoType) IsPrimitive ¶
IsPrimitive checks if the GoType is a primitive type
type Request ¶
type Request struct {
config.CoreConfig
CodeWriterFn config.CodeWriterFunc
TypeDict *TypeDict
}
Request holds the runtime information to handle a CRD generation request
type TypeDict ¶
type TypeDict struct {
// contains filtered or unexported fields
}
TypeDict is a dictionary of Go types, used to track and ensure unique type names. It also keeps track of generated types to avoid re-genrating the same type again.
func NewTypeDict ¶
NewTypeDict creates a new TypeDict with the given renames and Go types
func (TypeDict) MarkGenerated ¶
MarkGenerated marks a GoType as generated
func (*TypeDict) RenameField ¶
RenameField renames the GoType of the field to ensure it is unique within the TypeDict. It uses the parent names as needed to create a unique name for the type, if the type is not a primitive and its name is already taken.
func (TypeDict) RenameType ¶
RenameType renames the given GoType to ensure it is unique within the TypeDict. It uses the parent names as needed to create a unique name for the type, if the type is not a primitive and its name is already taken.
func (TypeDict) WasGenerated ¶
WasGenerated checks if a GoType was marked as generated