Documentation ¶
Overview ¶
Package flc provides an interface for interacting with flc (ent codegen) as a package rather than an executable.
Index ¶
- func Generate(schemaPath string, config *gen.Config, options ...Option) error
- func LoadGraph(schemaPath string, cfg *gen.Config) (*gen.Graph, error)
- type Annotation
- type DefaultExtension
- type DependencyOption
- type Extension
- type Option
- func Annotations(annotations ...Annotation) Option
- func BuildFlags(flags ...string) Option
- func BuildTags(tags ...string) Option
- func Dependency(opts ...DependencyOption) Option
- func Extensions(extensions ...Extension) Option
- func FeatureNames(names ...string) Option
- func Storage(typ string) Option
- func TemplateDir(path string) Option
- func TemplateFiles(filenames ...string) Option
- func TemplateGlob(pattern string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate runs the codegen on the schema path. The default target directory for the assets, is one directory above the schema path. Hence, if the schema package resides in "<project>/fluent/schema", the base directory for codegen will be "<project>/fluent".
If no storage driver provided by option, SQL driver will be used.
flc.Generate("./fluent/path", &gen.Config{ Header: "// Custom header", IDType: &field.TypeInfo{Type: field.TypeInt}, })
Types ¶
type Annotation ¶
type Annotation = schema.Annotation
Annotation is used to attach arbitrary metadata to the schema objects in codegen. Unlike schema annotations, being serializable to JSON raw value is not mandatory.
Template extensions can retrieve this metadata and use it inside their execution. Read more about it in fluent website: https://github.com/usalko/fluent/docs/templates/#annotations.
type DefaultExtension ¶
type DefaultExtension struct{}
DefaultExtension is the default implementation for flc.Extension.
Embedding this type allow third-party packages to create extensions without implementing all methods.
type Extension struct { flc.DefaultExtension }
func (DefaultExtension) Annotations ¶
func (DefaultExtension) Annotations() []Annotation
Annotations of the extensions.
func (DefaultExtension) Options ¶
func (DefaultExtension) Options() []Option
Options of the extensions.
func (DefaultExtension) Templates ¶
func (DefaultExtension) Templates() []*gen.Template
Templates of the extensions.
type DependencyOption ¶
type DependencyOption func(*gen.Dependency) error
DependencyOption allows configuring optional dependencies using functional options.
func DependencyName ¶
func DependencyName(name string) DependencyOption
DependencyName sets the struct field and the option name of the dependency in the generated builders.
func DependencyType ¶
func DependencyType(v any) DependencyOption
DependencyType sets the type of the struct field in the generated builders for the configured dependency.
func DependencyTypeInfo ¶
func DependencyTypeInfo(t *field.TypeInfo) DependencyOption
DependencyTypeInfo is similar to DependencyType, but allows setting the field.TypeInfo explicitly.
type Extension ¶
type Extension interface { // Hooks holds an optional list of Hooks to apply // on the graph before/after the code-generation. Hooks() []gen.Hook // Annotations injects global annotations to the gen.Config object that // can be accessed globally in all templates. Unlike schema annotations, // being serializable to JSON raw value is not mandatory. // // {{- with $.Config.Annotations.GQL }} // {{/* Annotation usage goes here. */}} // {{- end }} // Annotations() []Annotation // Templates specifies a list of alternative templates // to execute or to override the default. Templates() []*gen.Template // Options specifies a list of flc.Options to evaluate on // the gen.Config before executing the code generation. Options() []Option }
Extension describes an Ent code generation extension that allows customizing the code generation and integrate with other tools and libraries (e.g. GraphQL, gRPC, OpenAPI) by registering hooks, templates and global annotations in one simple call.
ex, err := fluent_gql.NewExtension( fluent_gql.WithConfig("../gqlgen.yml"), fluent_gql.WithSchema("../schema.graphql"), ) if err != nil { log.Fatalf("creating graphql extension: %v", err) } err = flc.Generate("./schema", &gen.Config{ Templates: entswag.Templates, }, flc.Extensions(ex)) if err != nil { log.Fatalf("running fluent codegen: %v", err) }
type Option ¶
Option allows for managing codegen configuration using functional options.
func Annotations ¶
func Annotations(annotations ...Annotation) Option
Annotations appends the given annotations to the codegen config.
func BuildFlags ¶
BuildFlags appends the given build flags to the codegen config.
func Dependency ¶
func Dependency(opts ...DependencyOption) Option
Dependency allows configuring optional dependencies as struct fields on the generated builders. For example:
opts := []flc.Option{ flc.Dependency( flc.DependencyType(&http.Client{}), ), flc.Dependency( flc.DependencyName("DB"), flc.DependencyType(&sql.DB{}), ) } if err := flc.Generate("./fluent/path", &gen.Config{}, opts...); err != nil { log.Fatalf("running fluent codegen: %v", err) }
func Extensions ¶
Extensions evaluates the list of Extensions on the gen.Config.
func FeatureNames ¶
FeatureNames enables sets of features by their names.
func TemplateDir ¶
TemplateDir parses the template definitions from the files in the directory and associates the resulting templates with codegen templates.
func TemplateFiles ¶
TemplateFiles parses the named files and associates the resulting templates with codegen templates.
func TemplateGlob ¶
TemplateGlob parses the template definitions from the files identified by the pattern and associates the resulting templates with codegen templates.
Directories ¶
Path | Synopsis |
---|---|
Package gen is the interface for generating loaded schemas into a Go package.
|
Package gen is the interface for generating loaded schemas into a Go package. |
integration
module
|
|
Package load is the interface for loading an fluent/schema package into a Go program.
|
Package load is the interface for loading an fluent/schema package into a Go program. |