mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Summary:
Set the standard header ("Code generated by entc, DO NOT EDIT.") as default, and override it using option in graph.
No changes to graph except the `generate.go` file.
Reviewed By: idoshveki
Differential Revision: D16642348
fbshipit-source-id: d9fd1d2046e2fd96acbb100ef061fda75d99ce52
52 lines
1.1 KiB
Cheetah
52 lines
1.1 KiB
Cheetah
{{ define "config" }}
|
|
|
|
{{ $pkg := base $.Config.Package }}
|
|
{{ template "header" $ }}
|
|
|
|
{{ template "import" $ }}
|
|
|
|
// Option function to configure the client.
|
|
type Option func(*config)
|
|
|
|
// Config is the configuration for the client and its builder.
|
|
type config struct {
|
|
// driver is the driver used for execute database requests.
|
|
driver dialect.Driver
|
|
// verbose enable a verbosity logging.
|
|
verbose bool
|
|
// log used for logging on verbose mode.
|
|
log func(...interface{})
|
|
}
|
|
|
|
// Options applies the options on the config object.
|
|
func (c *config) options(opts ...Option) {
|
|
for _, opt := range opts {
|
|
opt(c)
|
|
}
|
|
if c.verbose {
|
|
c.driver = dialect.Debug(c.driver, c.log)
|
|
}
|
|
}
|
|
|
|
// Verbose sets the client logging to verbose.
|
|
func Verbose() Option {
|
|
return func(c *config) {
|
|
c.verbose = true
|
|
}
|
|
}
|
|
|
|
// Log sets the client logging to verbose.
|
|
func Log(fn func(...interface{})) Option {
|
|
return func(c *config) {
|
|
c.log = fn
|
|
}
|
|
}
|
|
|
|
// Driver configures the client driver.
|
|
func Driver(driver dialect.Driver) Option {
|
|
return func(c *config) {
|
|
c.driver = driver
|
|
}
|
|
}
|
|
|
|
{{ end }} |