Fix options defaults (Defaults() fn must be called before fill())

This commit is contained in:
Denis Arh
2022-02-16 20:34:37 +01:00
parent 23c7f357fb
commit 7fd719364e
7 changed files with 294 additions and 209 deletions
@@ -1,45 +0,0 @@
package {{ .package }}
{{ template "gocode/header-gentext.tpl" }}
{{ if .imports }}
import (
{{- range .imports }}
{{ . }}
{{- end }}
)
{{- end }}
type (
{{ .struct }} struct {
{{- range .options }}
{{ .expIdent }} {{ .type }} `env:"{{ .env }}"`
{{- end }}
}
)
// {{ .func }} initializes and returns a {{ .struct }} with default values
//
// This function is auto-generated
func {{ .func }}() (o *{{ .struct }}) {
o = &{{ .struct }}{
{{- range .options }}
{{- if .default }}
{{ .expIdent }}: {{ .default }},
{{- end }}
{{- end }}
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *{{ .struct }}) Defaults() {...}
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
return
}
@@ -33,17 +33,22 @@ type (
{{- end }}
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *{{ .struct }}) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
{{ end }}
-14
View File
@@ -9,20 +9,6 @@ import (
options:
[...schema.#codegen] &
[
// placeholder
// for g in app.corteza.options {
// template: "gocode/options/$options_group.go.tpl"
// output: "pkg/options/\(g.ident).gen.go"
// payload: {
// package: "options"
// imports: g.imports
// func: g.expIdent
// struct: g.expIdent + "Opt"
// options: g.options
// }
// },
{
template: "gocode/options/options.go.tpl"
output: "pkg/options/options.gen.go"
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"strings"
)
func (o *DBOpt) Defaults() {
func (o *DBOpt) Cleanup() {
if o.DSN != "" && !strings.Contains(o.DSN, "://") {
// Make sure DSN is compatible with new requirements
o.DSN = "mysql://" + o.DSN
+1 -1
View File
@@ -1,6 +1,6 @@
package options
func (o *HttpServerOpt) Defaults() {
func (o *HttpServerOpt) Cleanup() {
o.BaseUrl = CleanBase(o.BaseUrl)
o.ApiBaseUrl = CleanBase(o.ApiBaseUrl)
o.WebappBaseUrl = CleanBase(o.WebappBaseUrl)
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"path"
)
func (o *CorredorOpt) Defaults() {
func (o *CorredorOpt) Cleanup() {
o.TlsCertCA = path.Join(o.TlsCertPath, o.TlsCertCA)
o.TlsCertPrivate = path.Join(o.TlsCertPath, o.TlsCertPrivate)
o.TlsCertPublic = path.Join(o.TlsCertPath, o.TlsCertPublic)
+281 -142
View File
@@ -7,10 +7,9 @@ package options
//
import (
"time"
"github.com/cortezaproject/corteza-server/pkg/rand"
"github.com/cortezaproject/corteza-server/pkg/version"
"time"
)
type (
@@ -261,17 +260,22 @@ func DB() (o *DBOpt) {
DSN: "sqlite3://file::memory:?cache=shared&mode=memory",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *DBOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -283,17 +287,22 @@ func HTTPClient() (o *HTTPClientOpt) {
Timeout: 30 * time.Second,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *HTTPClientOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -318,17 +327,22 @@ func HttpServer() (o *HttpServerOpt) {
SslTerminated: isSecure(),
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *HttpServerOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -342,17 +356,22 @@ func Rbac() (o *RbacOpt) {
AnonymousRoles: "anonymous",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *RbacOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -365,17 +384,22 @@ func SCIM() (o *SCIMOpt) {
ExternalIdValidation: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *SCIMOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -388,17 +412,22 @@ func SMTP() (o *SMTPOpt) {
Port: 25,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *SMTPOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -410,17 +439,22 @@ func ActionLog() (o *ActionLogOpt) {
Enabled: true,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *ActionLogOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -434,17 +468,22 @@ func Apigw() (o *ApigwOpt) {
ProxyOutboundTimeout: time.Second * 30,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *ApigwOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -477,17 +516,22 @@ func Auth() (o *AuthOpt) {
DefaultClient: "corteza-webapp",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *AuthOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -509,17 +553,22 @@ func Corredor() (o *CorredorOpt) {
TlsCertPublic: "public.crt",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *CorredorOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -531,17 +580,22 @@ func Environment() (o *EnvironmentOpt) {
Environment: "production",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *EnvironmentOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -554,17 +608,22 @@ func Eventbus() (o *EventbusOpt) {
SchedulerInterval: time.Minute,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *EventbusOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -581,17 +640,22 @@ func Federation() (o *FederationOpt) {
DataPageSize: 100,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *FederationOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -601,17 +665,22 @@ func Federation() (o *FederationOpt) {
func Limit() (o *LimitOpt) {
o = &LimitOpt{}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *LimitOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -624,17 +693,22 @@ func Locale() (o *LocaleOpt) {
QueryStringParam: "lng",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *LocaleOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -647,17 +721,22 @@ func Log() (o *LogOpt) {
StacktraceLevel: "dpanic",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *LogOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -669,17 +748,22 @@ func Messagebus() (o *MessagebusOpt) {
Enabled: true,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *MessagebusOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -691,17 +775,22 @@ func Monitor() (o *MonitorOpt) {
Interval: 5 * time.Minute,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *MonitorOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -715,17 +804,22 @@ func ObjectStore() (o *ObjectStoreOpt) {
MinioBucket: "{component}",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *ObjectStoreOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -737,17 +831,22 @@ func Plugins() (o *PluginsOpt) {
Enabled: true,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *PluginsOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -760,17 +859,22 @@ func Provision() (o *ProvisionOpt) {
Path: "provision/*",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *ProvisionOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -780,17 +884,22 @@ func Provision() (o *ProvisionOpt) {
func Seeder() (o *SeederOpt) {
o = &SeederOpt{}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *SeederOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -804,17 +913,22 @@ func Sentry() (o *SentryOpt) {
Release: version.Version,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *SentryOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -824,17 +938,22 @@ func Sentry() (o *SentryOpt) {
func Template() (o *TemplateOpt) {
o = &TemplateOpt{}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *TemplateOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -846,17 +965,22 @@ func Upgrade() (o *UpgradeOpt) {
Always: true,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *UpgradeOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -871,17 +995,22 @@ func WaitFor() (o *WaitForOpt) {
ServicesProbeInterval: time.Second * 5,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *WaitForOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -895,17 +1024,22 @@ func Websocket() (o *WebsocketOpt) {
PingPeriod: ((120 * time.Second) * 9) / 10,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *WebsocketOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}
@@ -918,16 +1052,21 @@ func Workflow() (o *WorkflowOpt) {
CallStackSize: 16,
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *WorkflowOpt) Defaults() {...}
// Custom defaults
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
fill(o)
// Custom cleanup
func(o interface{}) {
if def, ok := o.(interface{ Cleanup() }); ok {
def.Cleanup()
}
}(o)
return
}