gotype

package
v0.0.0-...-abac61d Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnsupportedKind = "unsupported"
	StructKind      = "struct"
	ArrayKind       = "array"
	StringKind      = "string"
	IntKind         = "int"
	Uint64Kind      = "uint64"
	FloatKind       = "float64"
	BoolKind        = "bool"
	MapKind         = "map"
	OpaqueKind      = "opaque"
	AutoImportKind  = "autoImport"
)
View Source
const PACKAGE_BASE = "github.com/mongodb/mongodb-atlas-kubernetes/tools/crd2go"

Variables

View Source
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

func NewEmbeddedField(gt *GoType) *GoField

NewEmbeddedField creates and embedded field, without a name

func NewGoField

func NewGoField(name string, gt *GoType) *GoField

NewGoField creates a new GoField with the given name and GoType

func NewGoFieldWithKey

func NewGoFieldWithKey(name, key string, gt *GoType) *GoField

NewGoFieldWithKey creates a new GoField with the given name, key, and GoType

func (*GoField) IsEmbedded

func (gt *GoField) IsEmbedded() bool

IsEmbedded returns whether nor not his field is an embedded one

func (*GoField) Signature

func (gt *GoField) Signature() string

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 JSONTag

func JSONTag(jsonTag string) GoFieldOptionFunc

JSONTag option sets a csutom JSON tag

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

func AddImportInfo(gt *GoType, alias, packagePath string) *GoType

AddImportInfo allows to attach the import information to a type

func BuiltInType

func BuiltInType(name, alias, path string) *GoType

func KnownTypes

func KnownTypes() []*GoType

func MustTypeFrom

func MustTypeFrom(t reflect.Type) *GoType

func NewArray

func NewArray(element *GoType) *GoType

NewArray creates a new GoType representing an array type

func NewAutoImportType

func NewAutoImportType(importType *config.ImportedTypeConfig) *GoType

NewAutoImportType creates a new GoType representing an opaque type with hidden internals

func NewOpaqueType

func NewOpaqueType(name string) *GoType

NewOpaqueType creates a new GoType representing an opaque type with hidden internals

func NewPrimitive

func NewPrimitive(name, kind string) *GoType

NewPrimitive creates a new GoType representing a primitive type

func NewStruct

func NewStruct(name string, fields []*GoField) *GoType

NewStruct creates a new GoType representing a struct type

func SetAlias

func SetAlias(gt *GoType, alias string) *GoType

SetAlias allows to attach an alias to the import information of a type

func TypeFrom

func TypeFrom(t reflect.Type) (*GoType, error)

func (*GoType) BaseType

func (gt *GoType) BaseType() *GoType

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

func (gt *GoType) CloneStructure(ot *GoType)

CloneStructure copies the structure of another type, but leaved the name and import info intact

func (*GoType) IsPrimitive

func (gt *GoType) IsPrimitive() bool

IsPrimitive checks if the GoType is a primitive type

func (*GoType) Signature

func (gt *GoType) Signature() string

signature generates a unique signature for a GoType reflecting its structure. This is leveraged by TypeDict to check if a type is already registered with the same internal structure, regardless of the name.

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

func NewTypeDict(renames map[string]string, goTypes ...*GoType) *TypeDict

NewTypeDict creates a new TypeDict with the given renames and Go types

func (TypeDict) Add

func (td TypeDict) Add(gt *GoType)

Add adds a GoType to the TypeDict, ensuring that the type name is unique

func (TypeDict) AddAll

func (td TypeDict) AddAll(goTypes ...*GoType)

AddAll adds all the given tipes to the dictionary

func (TypeDict) Get

func (td TypeDict) Get(name string) (*GoType, bool)

Get retrieves a GoType by its name from the TypeDict

func (TypeDict) Has

func (td TypeDict) Has(gt *GoType) bool

Has checks if the TypeDict contains a GoType with the same signature

func (TypeDict) MarkGenerated

func (td TypeDict) MarkGenerated(gt *GoType)

MarkGenerated marks a GoType as generated

func (*TypeDict) RenameField

func (td *TypeDict) RenameField(gf *GoField, parentNames []string) error

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

func (td TypeDict) RenameType(parentNames []string, gt *GoType) error

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

func (td TypeDict) WasGenerated(gt *GoType) bool

WasGenerated checks if a GoType was marked as generated

Jump to

Keyboard shortcuts

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