Add code generated files, removed obsolete files
This commit is contained in:
35
pkg/options/DB.gen.go
Normal file
35
pkg/options/DB.gen.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/DB.yaml
|
||||
|
||||
type (
|
||||
DBOpt struct {
|
||||
DSN string `env:"DB_DSN"`
|
||||
}
|
||||
)
|
||||
|
||||
// DB initializes and returns a DBOpt with default values
|
||||
func DB() (o *DBOpt) {
|
||||
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 *DB) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
12
pkg/options/DB.go
Normal file
12
pkg/options/DB.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (o *DBOpt) Defaults() {
|
||||
if o.DSN != "" && !strings.Contains(o.DSN, "://") {
|
||||
// Make sure DSN is compatible with new requirements
|
||||
o.DSN = "mysql://" + o.DSN
|
||||
}
|
||||
}
|
||||
41
pkg/options/HTTPClient.gen.go
Normal file
41
pkg/options/HTTPClient.gen.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/HTTPClient.yaml
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
HTTPClientOpt struct {
|
||||
ClientTSLInsecure bool `env:"HTTP_CLIENT_TSL_INSECURE"`
|
||||
HttpClientTimeout time.Duration `env:"HTTP_CLIENT_TIMEOUT"`
|
||||
}
|
||||
)
|
||||
|
||||
// HTTPClient initializes and returns a HTTPClientOpt with default values
|
||||
func HTTPClient() (o *HTTPClientOpt) {
|
||||
o = &HTTPClientOpt{
|
||||
ClientTSLInsecure: false,
|
||||
HttpClientTimeout: 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 *HTTPClient) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
72
pkg/options/HTTPServer.gen.go
Normal file
72
pkg/options/HTTPServer.gen.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/HTTPServer.yaml
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
)
|
||||
|
||||
type (
|
||||
HTTPServerOpt struct {
|
||||
Addr string `env:"HTTP_ADDR"`
|
||||
LogRequest bool `env:"HTTP_LOG_REQUEST"`
|
||||
LogResponse bool `env:"HTTP_LOG_RESPONSE"`
|
||||
Tracing bool `env:"HTTP_ERROR_TRACING"`
|
||||
EnableHealthcheckRoute bool `env:"HTTP_ENABLE_HEALTHCHECK_ROUTE"`
|
||||
EnableVersionRoute bool `env:"HTTP_ENABLE_VERSION_ROUTE"`
|
||||
EnableDebugRoute bool `env:"HTTP_ENABLE_DEBUG_ROUTE"`
|
||||
EnableMetrics bool `env:"HTTP_METRICS"`
|
||||
MetricsServiceLabel string `env:"HTTP_METRICS_NAME"`
|
||||
MetricsUsername string `env:"HTTP_METRICS_USERNAME"`
|
||||
MetricsPassword string `env:"HTTP_METRICS_PASSWORD"`
|
||||
EnablePanicReporting bool `env:"HTTP_REPORT_PANIC"`
|
||||
ApiEnabled bool `env:"HTTP_API_ENABLED"`
|
||||
ApiBaseUrl string `env:"HTTP_API_BASE_URL"`
|
||||
WebappEnabled bool `env:"HTTP_WEBAPP_ENABLED"`
|
||||
WebappBaseUrl string `env:"HTTP_WEBAPP_BASE_URL"`
|
||||
WebappBaseDir string `env:"HTTP_WEBAPP_BASE_DIR"`
|
||||
WebappList string `env:"HTTP_WEBAPP_LIST"`
|
||||
}
|
||||
)
|
||||
|
||||
// HTTPServer initializes and returns a HTTPServerOpt with default values
|
||||
func HTTPServer() (o *HTTPServerOpt) {
|
||||
o = &HTTPServerOpt{
|
||||
Addr: ":80",
|
||||
LogRequest: false,
|
||||
LogResponse: false,
|
||||
Tracing: false,
|
||||
EnableHealthcheckRoute: true,
|
||||
EnableVersionRoute: true,
|
||||
EnableDebugRoute: false,
|
||||
EnableMetrics: false,
|
||||
MetricsServiceLabel: "corteza",
|
||||
MetricsUsername: "metrics",
|
||||
MetricsPassword: string(rand.Bytes(5)),
|
||||
EnablePanicReporting: true,
|
||||
ApiEnabled: true,
|
||||
WebappEnabled: false,
|
||||
WebappBaseUrl: "/",
|
||||
WebappBaseDir: "webapp/public",
|
||||
WebappList: "admin,auth,messaging,compose",
|
||||
}
|
||||
|
||||
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 *HTTPServer) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
12
pkg/options/HTTPServer.go
Normal file
12
pkg/options/HTTPServer.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package options
|
||||
|
||||
func (o *HTTPServerOpt) Defaults() {
|
||||
|
||||
if o.WebappEnabled && o.ApiEnabled && o.ApiBaseUrl == "" {
|
||||
// api base URL is still on root (empty string)
|
||||
// but webapps are enabled (that means, server also serves static files from WebappBaseDir)
|
||||
//
|
||||
// Let's be nice and move API to /api
|
||||
o.ApiBaseUrl = "/api"
|
||||
}
|
||||
}
|
||||
32
pkg/options/README.adoc
Normal file
32
pkg/options/README.adoc
Normal file
@@ -0,0 +1,32 @@
|
||||
# Options YAML integration
|
||||
|
||||
This file is meant to help with the creation of a .YAML file inside options package.
|
||||
|
||||
The name of the .YAML will dedicate the name of the .gen.go file e.g. fileName1.yaml -> fileName1.gen.go, filename2.yaml -> filename2.gen.go
|
||||
|
||||
The contents of the .YAML file should look like this:
|
||||
|
||||
name:
|
||||
|
||||
imports:
|
||||
|
||||
props
|
||||
- name: ...
|
||||
type: ...
|
||||
env: ...
|
||||
default: ...
|
||||
|
||||
|
||||
|
||||
**name**
|
||||
It is the name of the
|
||||
|
||||
name: name of option
|
||||
imports - the list of needed imports
|
||||
props: - name -> name of variable
|
||||
props: - type -> the type of variable if not given it is "string" by
|
||||
default
|
||||
props: - env -> environment value that if it is not defined will be auto
|
||||
generated from "name" and "props: - name"
|
||||
props: - default -> the default value that is asigned to the "prop"
|
||||
- strings should be given in double quotations if they are to be qouted
|
||||
43
pkg/options/SMTP.gen.go
Normal file
43
pkg/options/SMTP.gen.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/SMTP.yaml
|
||||
|
||||
type (
|
||||
SMTPOpt struct {
|
||||
Host string `env:"SMTP_HOST"`
|
||||
Port int `env:"SMTP_PORT"`
|
||||
User string `env:"SMTP_USER"`
|
||||
Pass string `env:"SMTP_PASS"`
|
||||
From string `env:"SMTP_FROM"`
|
||||
TlsInsecure bool `env:"SMTP_TLS_INSECURE"`
|
||||
TlsServerName string `env:"SMTP_TLS_SERVER_NAME"`
|
||||
}
|
||||
)
|
||||
|
||||
// SMTP initializes and returns a SMTPOpt with default values
|
||||
func SMTP() (o *SMTPOpt) {
|
||||
o = &SMTPOpt{
|
||||
Host: "localhost",
|
||||
Port: 25,
|
||||
TlsInsecure: false,
|
||||
}
|
||||
|
||||
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 *SMTP) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
37
pkg/options/actionLog.gen.go
Normal file
37
pkg/options/actionLog.gen.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/actionLog.yaml
|
||||
|
||||
type (
|
||||
ActionLogOpt struct {
|
||||
Enabled bool `env:"ACTIONLOG_ENABLED"`
|
||||
Debug bool `env:"ACTIONLOG_DEBUG"`
|
||||
}
|
||||
)
|
||||
|
||||
// ActionLog initializes and returns a ActionLogOpt with default values
|
||||
func ActionLog() (o *ActionLogOpt) {
|
||||
o = &ActionLogOpt{
|
||||
Enabled: true,
|
||||
Debug: false,
|
||||
}
|
||||
|
||||
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 *ActionLog) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package options
|
||||
|
||||
type (
|
||||
ActionLogOpt struct {
|
||||
Enabled bool `env:"ACTIONLOG_ENABLED"`
|
||||
Debug bool `env:"ACTIONLOG_DEBUG"`
|
||||
}
|
||||
)
|
||||
|
||||
func ActionLog() (o *ActionLogOpt) {
|
||||
o = &ActionLogOpt{
|
||||
Enabled: true,
|
||||
Debug: false,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
40
pkg/options/auth.gen.go
Normal file
40
pkg/options/auth.gen.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/auth.yaml
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
AuthOpt struct {
|
||||
Secret string `env:"AUTH_JWT_SECRET"`
|
||||
Expiry time.Duration `env:"AUTH_JWT_EXPIRY"`
|
||||
}
|
||||
)
|
||||
|
||||
// Auth initializes and returns a AuthOpt with default values
|
||||
func Auth() (o *AuthOpt) {
|
||||
o = &AuthOpt{
|
||||
Expiry: time.Hour * 24 * 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 *Auth) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
12
pkg/options/auth.go
Normal file
12
pkg/options/auth.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
)
|
||||
|
||||
func (o *AuthOpt) Defaults() {
|
||||
|
||||
if o.Secret == "" {
|
||||
o.Secret = string(rand.Bytes(32))
|
||||
}
|
||||
}
|
||||
64
pkg/options/corredor.gen.go
Normal file
64
pkg/options/corredor.gen.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/corredor.yaml
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
CorredorOpt struct {
|
||||
Enabled bool `env:"CORREDOR_ENABLED"`
|
||||
Addr string `env:"CORREDOR_ADDR"`
|
||||
MaxBackoffDelay time.Duration `env:"CORREDOR_MAX_BACKOFF_DELAY"`
|
||||
MaxReceiveMessageSize int `env:"CORREDOR_MAX_RECEIVE_MESSAGE_SIZE"`
|
||||
DefaultExecTimeout time.Duration `env:"CORREDOR_DEFAULT_EXEC_TIMEOUT"`
|
||||
ListTimeout time.Duration `env:"CORREDOR_LIST_TIMEOUT"`
|
||||
ListRefresh time.Duration `env:"CORREDOR_LIST_REFRESH"`
|
||||
RunAsEnabled bool `env:"CORREDOR_RUN_AS_ENABLED"`
|
||||
TlsCertEnabled bool `env:"CORREDOR_CLIENT_CERTIFICATES_ENABLED"`
|
||||
TlsCertPath string `env:"CORREDOR_CLIENT_CERTIFICATES_PATH"`
|
||||
TlsCertCA string `env:"CORREDOR_CLIENT_CERTIFICATES_CA"`
|
||||
TlsCertPrivate string `env:"CORREDOR_CLIENT_CERTIFICATES_PRIVATE"`
|
||||
TlsCertPublic string `env:"CORREDOR_CLIENT_CERTIFICATES_PUBLIC"`
|
||||
TlsServerName string `env:"CORREDOR_CLIENT_CERTIFICATES_SERVER_NAME"`
|
||||
}
|
||||
)
|
||||
|
||||
// Corredor initializes and returns a CorredorOpt with default values
|
||||
func Corredor() (o *CorredorOpt) {
|
||||
o = &CorredorOpt{
|
||||
Enabled: true,
|
||||
Addr: "localhost:50051",
|
||||
MaxBackoffDelay: time.Minute,
|
||||
MaxReceiveMessageSize: 2 << 23,
|
||||
DefaultExecTimeout: time.Minute,
|
||||
ListTimeout: time.Second * 2,
|
||||
ListRefresh: time.Second * 5,
|
||||
RunAsEnabled: true,
|
||||
TlsCertEnabled: false,
|
||||
TlsCertPath: "/certs/corredor/client",
|
||||
TlsCertCA: "ca.crt",
|
||||
TlsCertPrivate: "private.key",
|
||||
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 *Corredor) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -2,60 +2,10 @@ package options
|
||||
|
||||
import (
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
CorredorOpt struct {
|
||||
Enabled bool `env:"CORREDOR_ENABLED"`
|
||||
|
||||
// Also used by corredor service to configure gRPC server
|
||||
Addr string `env:"CORREDOR_ADDR"`
|
||||
|
||||
MaxBackoffDelay time.Duration `env:"CORREDOR_MAX_BACKOFF_DELAY"`
|
||||
|
||||
MaxReceiveMessageSize int `env:"CORREDOR_MAX_RECEIVE_MESSAGE_SIZE"`
|
||||
|
||||
DefaultExecTimeout time.Duration `env:"CORREDOR_DEFAULT_EXEC_TIMEOUT"`
|
||||
|
||||
ListTimeout time.Duration `env:"CORREDOR_LIST_TIMEOUT"`
|
||||
ListRefresh time.Duration `env:"CORREDOR_LIST_REFRESH"`
|
||||
|
||||
// Allow scripts to have runner explicitly defined
|
||||
RunAsEnabled bool `env:"CORREDOR_RUN_AS_ENABLED"`
|
||||
|
||||
TlsCertEnabled bool `env:"CORREDOR_CLIENT_CERTIFICATES_ENABLED"`
|
||||
TlsCertPath string `env:"CORREDOR_CLIENT_CERTIFICATES_PATH"`
|
||||
TlsCertCA string `env:"CORREDOR_CLIENT_CERTIFICATES_CA"`
|
||||
TlsCertPrivate string `env:"CORREDOR_CLIENT_CERTIFICATES_PRIVATE"`
|
||||
TlsCertPublic string `env:"CORREDOR_CLIENT_CERTIFICATES_PUBLIC"`
|
||||
TlsServerName string `env:"CORREDOR_CLIENT_CERTIFICATES_SERVER_NAME"`
|
||||
}
|
||||
)
|
||||
|
||||
func Corredor() (o *CorredorOpt) {
|
||||
o = &CorredorOpt{
|
||||
Enabled: true,
|
||||
RunAsEnabled: true,
|
||||
Addr: "localhost:50051",
|
||||
MaxBackoffDelay: time.Minute,
|
||||
MaxReceiveMessageSize: 2 << 23, // 16MB
|
||||
DefaultExecTimeout: time.Minute,
|
||||
ListTimeout: time.Second * 2,
|
||||
ListRefresh: time.Second * 5,
|
||||
|
||||
TlsCertEnabled: false,
|
||||
TlsCertPath: "/certs/corredor/client",
|
||||
TlsCertCA: "ca.crt",
|
||||
TlsCertPublic: "public.crt",
|
||||
TlsCertPrivate: "private.key",
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
func (o *CorredorOpt) Defaults() {
|
||||
o.TlsCertCA = path.Join(o.TlsCertPath, o.TlsCertCA)
|
||||
o.TlsCertPrivate = path.Join(o.TlsCertPath, o.TlsCertPrivate)
|
||||
o.TlsCertPublic = path.Join(o.TlsCertPath, o.TlsCertPublic)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
DBOpt struct {
|
||||
DSN string `env:"DB_DSN"`
|
||||
}
|
||||
)
|
||||
|
||||
func DB(pfix string) (o *DBOpt) {
|
||||
o = &DBOpt{
|
||||
DSN: "sqlite3://file::memory:?cache=shared&mode=memory",
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
if o.DSN != "" && !strings.Contains(o.DSN, "://") {
|
||||
// Make sure DSN is compatible with new requirements
|
||||
o.DSN = "mysql://" + o.DSN
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
35
pkg/options/environment.gen.go
Normal file
35
pkg/options/environment.gen.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/environment.yaml
|
||||
|
||||
type (
|
||||
EnvironmentOpt struct {
|
||||
Environment string `env:"ENVIRONMENT"`
|
||||
}
|
||||
)
|
||||
|
||||
// Environment initializes and returns a EnvironmentOpt with default values
|
||||
func Environment() (o *EnvironmentOpt) {
|
||||
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 *Environment) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -2,22 +2,6 @@ package options
|
||||
|
||||
import "strings"
|
||||
|
||||
type (
|
||||
EnvironmentOpt struct {
|
||||
Environment string `env:"ENVIRONMENT"`
|
||||
}
|
||||
)
|
||||
|
||||
func Environment() (o *EnvironmentOpt) {
|
||||
o = &EnvironmentOpt{
|
||||
Environment: "production",
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e EnvironmentOpt) IsDevelopment() bool {
|
||||
return strings.HasPrefix(e.Environment, "dev")
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ import (
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
type (
|
||||
filler interface {
|
||||
fill()
|
||||
}
|
||||
)
|
||||
|
||||
func fill(opt interface{}) {
|
||||
v := reflect.ValueOf(opt)
|
||||
if v.Kind() != reflect.Ptr {
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
)
|
||||
|
||||
type (
|
||||
HTTPServerOpt struct {
|
||||
Addr string `env:"HTTP_ADDR"`
|
||||
LogRequest bool `env:"HTTP_LOG_REQUEST"`
|
||||
LogResponse bool `env:"HTTP_LOG_RESPONSE"`
|
||||
Tracing bool `env:"HTTP_ERROR_TRACING"`
|
||||
|
||||
EnableHealthcheckRoute bool `env:"HTTP_ENABLE_HEALTHCHECK_ROUTE"`
|
||||
EnableVersionRoute bool `env:"HTTP_ENABLE_VERSION_ROUTE"`
|
||||
EnableDebugRoute bool `env:"HTTP_ENABLE_DEBUG_ROUTE"`
|
||||
|
||||
EnableMetrics bool `env:"HTTP_METRICS"`
|
||||
MetricsServiceLabel string `env:"HTTP_METRICS_NAME"`
|
||||
MetricsUsername string `env:"HTTP_METRICS_USERNAME"`
|
||||
MetricsPassword string `env:"HTTP_METRICS_PASSWORD"`
|
||||
|
||||
EnablePanicReporting bool `env:"HTTP_REPORT_PANIC"`
|
||||
|
||||
ApiEnabled bool `env:"HTTP_API_ENABLED"`
|
||||
ApiBaseUrl string `env:"HTTP_API_BASE_URL"`
|
||||
|
||||
WebappEnabled bool `env:"HTTP_WEBAPP_ENABLED"`
|
||||
WebappBaseUrl string `env:"HTTP_WEBAPP_BASE_URL"`
|
||||
WebappBaseDir string `env:"HTTP_WEBAPP_BASE_DIR"`
|
||||
WebappList string `env:"HTTP_WEBAPP_LIST"`
|
||||
}
|
||||
)
|
||||
|
||||
func HTTP(pfix string) (o *HTTPServerOpt) {
|
||||
o = &HTTPServerOpt{
|
||||
Addr: ":80",
|
||||
LogRequest: false,
|
||||
LogResponse: false,
|
||||
Tracing: false,
|
||||
EnableHealthcheckRoute: true,
|
||||
EnableVersionRoute: true,
|
||||
EnableDebugRoute: false,
|
||||
EnableMetrics: false,
|
||||
MetricsServiceLabel: "corteza",
|
||||
MetricsUsername: "metrics",
|
||||
|
||||
// Reports panics to Sentry through HTTP middleware
|
||||
EnablePanicReporting: true,
|
||||
|
||||
// Setting metrics password to random string to prevent security accidents...
|
||||
MetricsPassword: string(rand.Bytes(5)),
|
||||
|
||||
ApiEnabled: true,
|
||||
ApiBaseUrl: "",
|
||||
|
||||
WebappEnabled: false,
|
||||
WebappBaseUrl: "/",
|
||||
WebappBaseDir: "webapp/public",
|
||||
WebappList: "admin,auth,messaging,compose",
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
if o.WebappEnabled && o.ApiEnabled && o.ApiBaseUrl == "" {
|
||||
// api base URL is still on root (empty string)
|
||||
// but webapps are enabled (that means, server also serves static files from WebappBaseDir)
|
||||
//
|
||||
// Let's be nice and move API to /api
|
||||
o.ApiBaseUrl = "/api"
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
HTTPClientOpt struct {
|
||||
ClientTSLInsecure bool `env:"HTTP_CLIENT_TSL_INSECURE"`
|
||||
HttpClientTimeout time.Duration `env:"HTTP_CLIENT_TIMEOUT"`
|
||||
}
|
||||
)
|
||||
|
||||
func HttpClient(pfix string) (o *HTTPClientOpt) {
|
||||
o = &HTTPClientOpt{
|
||||
ClientTSLInsecure: false,
|
||||
HttpClientTimeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/rand"
|
||||
)
|
||||
|
||||
type (
|
||||
AuthOpt struct {
|
||||
Secret string `env:"AUTH_JWT_SECRET"`
|
||||
Expiry time.Duration `env:"AUTH_JWT_EXPIRY"`
|
||||
}
|
||||
)
|
||||
|
||||
func Auth() (o *AuthOpt) {
|
||||
o = &AuthOpt{
|
||||
Expiry: time.Hour * 24 * 30,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
// Setting JWT secret to random string to prevent security accidents...
|
||||
//
|
||||
// @todo check if this is a monolith system
|
||||
// on microservice setup we can not afford to autogenerate secret:
|
||||
// each subsystem will get it's own
|
||||
if o.Secret == "" {
|
||||
o.Secret = string(rand.Bytes(32))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
39
pkg/options/monitor.gen.go
Normal file
39
pkg/options/monitor.gen.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/monitor.yaml
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
MonitorOpt struct {
|
||||
Interval time.Duration `env:"MONITOR_INTERVAL"`
|
||||
}
|
||||
)
|
||||
|
||||
// Monitor initializes and returns a MonitorOpt with default values
|
||||
func Monitor() (o *MonitorOpt) {
|
||||
o = &MonitorOpt{
|
||||
Interval: 300 * 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 *Monitor) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
MonitorOpt struct {
|
||||
Interval time.Duration `env:"MONITOR_INTERVAL"`
|
||||
}
|
||||
)
|
||||
|
||||
func Monitor(pfix string) (o *MonitorOpt) {
|
||||
o = &MonitorOpt{
|
||||
Interval: 300 * time.Second,
|
||||
}
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
44
pkg/options/objectStore.gen.go
Normal file
44
pkg/options/objectStore.gen.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/objectStore.yaml
|
||||
|
||||
type (
|
||||
ObjectStoreOpt struct {
|
||||
Path string `env:"STORAGE_PATH"`
|
||||
MinioEndpoint string `env:"MINIO_ENDPOINT"`
|
||||
MinioSecure bool `env:"MINIO_SECURE"`
|
||||
MinioAccessKey string `env:"MINIO_ACCESS_KEY"`
|
||||
MinioSecretKey string `env:"MINIO_SECRET_KEY"`
|
||||
MinioSSECKey string `env:"MINIO_SSEC_KEY"`
|
||||
MinioBucket string `env:"MINIO_BUCKET"`
|
||||
MinioStrict bool `env:"MINIO_STRICT"`
|
||||
}
|
||||
)
|
||||
|
||||
// ObjectStore initializes and returns a ObjectStoreOpt with default values
|
||||
func ObjectStore() (o *ObjectStoreOpt) {
|
||||
o = &ObjectStoreOpt{
|
||||
Path: "var/store",
|
||||
MinioSecure: true,
|
||||
MinioStrict: false,
|
||||
}
|
||||
|
||||
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 *ObjectStore) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
35
pkg/options/provision.gen.go
Normal file
35
pkg/options/provision.gen.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/provision.yaml
|
||||
|
||||
type (
|
||||
ProvisionOpt struct {
|
||||
Always bool `env:"PROVISION_ALWAYS"`
|
||||
}
|
||||
)
|
||||
|
||||
// Provision initializes and returns a ProvisionOpt with default values
|
||||
func Provision() (o *ProvisionOpt) {
|
||||
o = &ProvisionOpt{
|
||||
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 *Provision) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package options
|
||||
|
||||
type (
|
||||
ProvisionOpt struct {
|
||||
Always bool `env:"PROVISION_ALWAYS"`
|
||||
}
|
||||
)
|
||||
|
||||
func Provision(pfix string) (o *ProvisionOpt) {
|
||||
o = &ProvisionOpt{
|
||||
Always: true,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
PubSubOpt struct {
|
||||
Mode string `env:"PUBSUB_MODE"`
|
||||
|
||||
// Mode
|
||||
PollingInterval time.Duration `env:"PUBSUB_POLLING_INTERVAL"`
|
||||
|
||||
// Redis
|
||||
RedisAddr string `env:"PUBSUB_REDIS_ADDR"`
|
||||
RedisTimeout time.Duration `env:"PUBSUB_REDIS_TIMEOUT"`
|
||||
RedisPingTimeout time.Duration `env:"PUBSUB_REDIS_PING_TIMEOUT"`
|
||||
RedisPingPeriod time.Duration `env:"PUBSUB_REDIS_PING_PERIOD"`
|
||||
}
|
||||
)
|
||||
|
||||
func PubSub(pfix string) (o *PubSubOpt) {
|
||||
const (
|
||||
timeout = 15 * time.Second
|
||||
pingTimeout = 120 * time.Second
|
||||
pingPeriod = (pingTimeout * 9) / 10
|
||||
)
|
||||
|
||||
o = &PubSubOpt{
|
||||
Mode: "poll",
|
||||
PollingInterval: timeout,
|
||||
RedisAddr: "redis:6379",
|
||||
RedisTimeout: timeout,
|
||||
RedisPingTimeout: pingTimeout,
|
||||
RedisPingPeriod: pingPeriod,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
49
pkg/options/sentry.gen.go
Normal file
49
pkg/options/sentry.gen.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/sentry.yaml
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/version"
|
||||
)
|
||||
|
||||
type (
|
||||
SentryOpt struct {
|
||||
DSN string `env:"SENTRY_DSN"`
|
||||
Debug bool `env:"SENTRY_DEBUG"`
|
||||
AttachStacktrace bool `env:"SENTRY_ATTACH_STACKTRACE"`
|
||||
SampleRate float32 `env:"SENTRY_SAMPLE_RATE"`
|
||||
MaxBreadcrumbs int `env:"SENTRY_MAX_BREADCRUMBS"`
|
||||
ServerName string `env:"SENTRY_SERVERNAME"`
|
||||
Release string `env:"SENTRY_RELEASE"`
|
||||
Dist string `env:"SENTRY_DIST"`
|
||||
Environment string `env:"SENTRY_ENVIRONMENT"`
|
||||
}
|
||||
)
|
||||
|
||||
// Sentry initializes and returns a SentryOpt with default values
|
||||
func Sentry() (o *SentryOpt) {
|
||||
o = &SentryOpt{
|
||||
AttachStacktrace: true,
|
||||
MaxBreadcrumbs: 0,
|
||||
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 *Sentry) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza-server/pkg/version"
|
||||
)
|
||||
|
||||
type (
|
||||
SentryOpt struct {
|
||||
DSN string `env:"SENTRY_DSN"`
|
||||
|
||||
Debug bool `env:"SENTRY_DEBUG"`
|
||||
AttachStacktrace bool `env:"SENTRY_ATTACH_STACKTRACE"`
|
||||
SampleRate float32 `env:"SENTRY_SAMPLE_RATE"`
|
||||
MaxBreadcrumbs int `env:"SENTRY_MAX_BREADCRUMBS"`
|
||||
|
||||
ServerName string `env:"SENTRY_SERVERNAME"`
|
||||
Release string `env:"SENTRY_RELEASE"`
|
||||
Dist string `env:"SENTRY_DIST"`
|
||||
Environment string `env:"SENTRY_ENVIRONMENT"`
|
||||
}
|
||||
)
|
||||
|
||||
func Sentry(pfix string) (o *SentryOpt) {
|
||||
o = &SentryOpt{
|
||||
AttachStacktrace: true,
|
||||
MaxBreadcrumbs: 0,
|
||||
|
||||
Release: version.Version,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package options
|
||||
|
||||
type (
|
||||
SMTPOpt struct {
|
||||
Host string `env:"SMTP_HOST"`
|
||||
Port int `env:"SMTP_PORT"`
|
||||
User string `env:"SMTP_USER"`
|
||||
Pass string `env:"SMTP_PASS"`
|
||||
From string `env:"SMTP_FROM"`
|
||||
|
||||
TlsInsecure bool `env:"SMTP_TSL_INSECURE"`
|
||||
TlsServerName string `env:"SMTP_TSL_SERVER_NAME"`
|
||||
}
|
||||
)
|
||||
|
||||
func SMTP(pfix string) (o *SMTPOpt) {
|
||||
o = &SMTPOpt{
|
||||
Host: "localhost",
|
||||
Port: 25,
|
||||
User: "",
|
||||
Pass: "",
|
||||
From: "",
|
||||
|
||||
TlsInsecure: false,
|
||||
TlsServerName: "",
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package options
|
||||
|
||||
type (
|
||||
ObjectStoreOpt struct {
|
||||
Path string `env:"STORAGE_PATH"`
|
||||
|
||||
MinioEndpoint string `env:"MINIO_ENDPOINT"`
|
||||
MinioSecure bool `env:"MINIO_SECURE"`
|
||||
MinioAccessKey string `env:"MINIO_ACCESS_KEY"`
|
||||
MinioSecretKey string `env:"MINIO_SECRET_KEY"`
|
||||
MinioSSECKey string `env:"MINIO_SSEC_KEY"`
|
||||
MinioBucket string `env:"MINIO_BUCKET"`
|
||||
MinioStrict bool `env:"MINIO_STRICT"`
|
||||
}
|
||||
)
|
||||
|
||||
func ObjectStore(pfix string) (o *ObjectStoreOpt) {
|
||||
o = &ObjectStoreOpt{
|
||||
Path: "var/store",
|
||||
|
||||
// Make minio secure by default
|
||||
MinioSecure: true,
|
||||
|
||||
// Run in struct mode:
|
||||
// - do not create un-existing buckets
|
||||
MinioStrict: false,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
37
pkg/options/upgrade.gen.go
Normal file
37
pkg/options/upgrade.gen.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/upgrade.yaml
|
||||
|
||||
type (
|
||||
UpgradeOpt struct {
|
||||
Debug bool `env:"UPGRADE_DEBUG"`
|
||||
Always bool `env:"UPGRADE_ALWAYS"`
|
||||
}
|
||||
)
|
||||
|
||||
// Upgrade initializes and returns a UpgradeOpt with default values
|
||||
func Upgrade() (o *UpgradeOpt) {
|
||||
o = &UpgradeOpt{
|
||||
Debug: false,
|
||||
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 *Upgrade) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package options
|
||||
|
||||
type (
|
||||
UpgradeOpt struct {
|
||||
Debug bool `env:"UPGRADE_DEBUG"`
|
||||
Always bool `env:"UPGRADE_ALWAYS"`
|
||||
}
|
||||
)
|
||||
|
||||
func Upgrade(pfix string) (o *UpgradeOpt) {
|
||||
o = &UpgradeOpt{
|
||||
Debug: false,
|
||||
Always: true,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/waitFor.yaml
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -16,11 +23,11 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func WaitFor(pfix string) (o *WaitForOpt) {
|
||||
// WaitFor initializes and returns a WaitForOpt with default values
|
||||
func WaitFor() (o *WaitForOpt) {
|
||||
o = &WaitForOpt{
|
||||
Delay: 0,
|
||||
StatusPage: true,
|
||||
Services: "",
|
||||
ServicesTimeout: time.Minute,
|
||||
ServicesProbeTimeout: time.Second * 30,
|
||||
ServicesProbeInterval: time.Second * 5,
|
||||
@@ -28,14 +35,14 @@ func WaitFor(pfix string) (o *WaitForOpt) {
|
||||
|
||||
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 *WaitFor) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Parses hosts and return slice of strings, one per host
|
||||
func (o WaitForOpt) GetServices() []string {
|
||||
if len(o.Services) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
return strings.Split(o.Services, " ")
|
||||
}
|
||||
14
pkg/options/waitFor.go
Normal file
14
pkg/options/waitFor.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Parses hosts and return slice of strings, one per host
|
||||
func (o WaitForOpt) GetServices() []string {
|
||||
if len(o.Services) == 0 {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
return strings.Split(o.Services, " ")
|
||||
}
|
||||
43
pkg/options/websocket.gen.go
Normal file
43
pkg/options/websocket.gen.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package options
|
||||
|
||||
// This file is auto-generated.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
//
|
||||
// Definitions file that controls how this file is generated:
|
||||
// pkg/options/websocket.yaml
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
WebsocketOpt struct {
|
||||
Timeout time.Duration `env:"WEBSOCKET_TIMEOUT"`
|
||||
PingTimeout time.Duration `env:"WEBSOCKET_PING_TIMEOUT"`
|
||||
PingPeriod time.Duration `env:"WEBSOCKET_PING_PERIOD"`
|
||||
}
|
||||
)
|
||||
|
||||
// Websocket initializes and returns a WebsocketOpt with default values
|
||||
func Websocket() (o *WebsocketOpt) {
|
||||
o = &WebsocketOpt{
|
||||
Timeout: 15 * time.Second,
|
||||
PingTimeout: 120 * time.Second,
|
||||
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 *Websocket) Defaults() {...}
|
||||
func(o interface{}) {
|
||||
if def, ok := o.(interface{ Defaults() }); ok {
|
||||
def.Defaults()
|
||||
}
|
||||
}(o)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
WebsocketOpt struct {
|
||||
Timeout time.Duration `env:"WEBSOCKET_TIMEOUT"`
|
||||
PingTimeout time.Duration `env:"WEBSOCKET_PING_TIMEOUT"`
|
||||
PingPeriod time.Duration `env:"WEBSOCKET_PING_PERIOD"`
|
||||
}
|
||||
)
|
||||
|
||||
func Websocket(pfix string) (o *WebsocketOpt) {
|
||||
const (
|
||||
timeout = 15 * time.Second
|
||||
pingTimeout = 120 * time.Second
|
||||
pingPeriod = (pingTimeout * 9) / 10
|
||||
)
|
||||
|
||||
o = &WebsocketOpt{
|
||||
Timeout: timeout,
|
||||
PingTimeout: pingTimeout,
|
||||
PingPeriod: pingPeriod,
|
||||
}
|
||||
|
||||
fill(o)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user