func NewMemoryGroupConfig(conf *Config) *MemoryGroupConfig {
	c := NewDefaultMemoryGroupConfig()
	if err := conf.UnmarshalKey("pitaya.groups.memory", &c); err != nil {
		panic(err)
	}
	return c
}
NewMemoryGroupConfig returns a new, default group instance
package config
import (
	"fmt"
	"time"
	"github.com/topfreegames/pitaya/v2/metrics/models"
)
type PitayaConfig struct {
	Heartbeat struct {
		Interval time.Duration
	}
	Handler struct {
		Messages struct {
			Compression bool
		}
	}
	Buffer struct {
		Agent struct {
			Messages int
		}
		Handler struct {
			LocalProcess  int
			RemoteProcess int
		}
	}
	Concurrency struct {
		Handler struct {
			Dispatch int
		}
	}
	Session struct {
		Unique bool
	}
	Metrics struct {
		Period time.Duration
	}
}
func NewDefaultPitayaConfig() *PitayaConfig {
	return &PitayaConfig{
		Heartbeat: struct{ Interval time.Duration }{
			Interval: time.Duration(30 * time.Second),
		},
		Handler: struct {
			Messages struct {
				Compression bool
			}
		}{
			Messages: struct {
				Compression bool
			}{
				Compression: true,
			},
		},
		Buffer: struct {
			Agent struct {
				Messages int
			}
			Handler struct {
				LocalProcess  int
				RemoteProcess int
			}
		}{
			Agent: struct {
				Messages int
			}{
				Messages: 100,
			},
			Handler: struct {
				LocalProcess  int
				RemoteProcess int
			}{
				LocalProcess:  20,
				RemoteProcess: 20,
			},
		},
		Concurrency: struct {
			Handler struct {
				Dispatch int
			}
		}{
			Handler: struct {
				Dispatch int
			}{
				Dispatch: 25,
			},
		},
		Session: struct {
			Unique bool
		}{
			Unique: true,
		},
		Metrics: struct {
			Period time.Duration
		}{
			Period: time.Duration(15 * time.Second),
		},
	}
}
func NewPitayaConfig(config *Config) *PitayaConfig {
	conf := NewDefaultPitayaConfig()
	if err := config.UnmarshalKey("pitaya", &conf); err != nil {
		panic(err)
	}
	return conf
}
type BuilderConfig struct {
	Pitaya  PitayaConfig
	Metrics struct {
		Prometheus struct {
			Enabled bool
		}
		Statsd struct {
			Enabled bool
		}
	}
	DefaultPipelines struct {
		StructValidation struct {
			Enabled bool
		}
	}
}
func NewDefaultBuilderConfig() *BuilderConfig {
	return &BuilderConfig{
		Pitaya: *NewDefaultPitayaConfig(),
		Metrics: struct {
			Prometheus struct {
				Enabled bool
			}
			Statsd struct {
				Enabled bool
			}
		}{
			Prometheus: struct {
				Enabled bool
			}{
				Enabled: false,
			},
			Statsd: struct {
				Enabled bool
			}{
				Enabled: false,
			},
		},
		DefaultPipelines: struct {
			StructValidation struct {
				Enabled bool
			}
		}{
			StructValidation: struct {
				Enabled bool
			}{
				Enabled: false,
			},
		},
	}
}
func NewBuilderConfig(config *Config) *BuilderConfig {
	conf := NewDefaultBuilderConfig()
	if err := config.Unmarshal(&conf); err != nil {
		panic(err)
	}
	fmt.Println(conf)
	return conf
}
type GRPCClientConfig struct {
	DialTimeout    time.Duration
	LazyConnection bool
	RequestTimeout time.Duration
}
func NewDefaultGRPCClientConfig() *GRPCClientConfig {
	return &GRPCClientConfig{
		DialTimeout:    time.Duration(5 * time.Second),
		LazyConnection: false,
		RequestTimeout: time.Duration(5 * time.Second),
	}
}
func NewGRPCClientConfig(config *Config) *GRPCClientConfig {
	conf := NewDefaultGRPCClientConfig()
	if err := config.UnmarshalKey("pitaya.cluster.rpc.client.grpc", &conf); err != nil {
		panic(err)
	}
	return conf
}
type GRPCServerConfig struct {
	Port int
}
func NewDefaultGRPCServerConfig() *GRPCServerConfig {
	return &GRPCServerConfig{
		Port: 3434,
	}
}
func NewGRPCServerConfig(config *Config) *GRPCServerConfig {
	return &GRPCServerConfig{
		Port: config.GetInt("pitaya.cluster.rpc.server.grpc.port"),
	}
}
type NatsRPCClientConfig struct {
	Connect                string
	MaxReconnectionRetries int
	RequestTimeout         time.Duration
	ConnectionTimeout      time.Duration
}
func NewDefaultNatsRPCClientConfig() *NatsRPCClientConfig {
	return &NatsRPCClientConfig{
		Connect:                "nats://localhost:4222",
		MaxReconnectionRetries: 15,
		RequestTimeout:         time.Duration(5 * time.Second),
		ConnectionTimeout:      time.Duration(2 * time.Second),
	}
}
func NewNatsRPCClientConfig(config *Config) *NatsRPCClientConfig {
	conf := NewDefaultNatsRPCClientConfig()
	if err := config.UnmarshalKey("pitaya.cluster.rpc.client.nats", &conf); err != nil {
		panic(err)
	}
	return conf
}
type NatsRPCServerConfig struct {
	Connect                string
	MaxReconnectionRetries int
	Buffer                 struct {
		Messages int
		Push     int
	}
	Services          int
	ConnectionTimeout time.Duration
}
func NewDefaultNatsRPCServerConfig() *NatsRPCServerConfig {
	return &NatsRPCServerConfig{
		Connect:                "nats://localhost:4222",
		MaxReconnectionRetries: 15,
		Buffer: struct {
			Messages int
			Push     int
		}{
			Messages: 75,
			Push:     100,
		},
		Services:          30,
		ConnectionTimeout: time.Duration(2 * time.Second),
	}
}
func NewNatsRPCServerConfig(config *Config) *NatsRPCServerConfig {
	conf := NewDefaultNatsRPCServerConfig()
	if err := config.UnmarshalKey("pitaya.cluster.rpc.server.nats", &conf); err != nil {
		panic(err)
	}
	return conf
}
type InfoRetrieverConfig struct {
	Region string
}
func NewDefaultInfoRetrieverConfig() *InfoRetrieverConfig {
	return &InfoRetrieverConfig{
		Region: "",
	}
}
func NewInfoRetrieverConfig(c *Config) *InfoRetrieverConfig {
	conf := NewDefaultInfoRetrieverConfig()
	if err := c.UnmarshalKey("pitaya.cluster.info", &conf); err != nil {
		panic(err)
	}
	return conf
}
type EtcdServiceDiscoveryConfig struct {
	Endpoints   []string
	User        string
	Pass        string
	DialTimeout time.Duration
	Prefix      string
	Heartbeat   struct {
		TTL time.Duration
		Log bool
	}
	SyncServers struct {
		Interval    time.Duration
		Parallelism int
	}
	Revoke struct {
		Timeout time.Duration
	}
	GrantLease struct {
		Timeout       time.Duration
		MaxRetries    int
		RetryInterval time.Duration
	}
	Shutdown struct {
		Delay time.Duration
	}
	ServerTypesBlacklist []string
}
func NewDefaultEtcdServiceDiscoveryConfig() *EtcdServiceDiscoveryConfig {
	return &EtcdServiceDiscoveryConfig{
		Endpoints:   []string{"localhost:2379"},
		User:        "",
		Pass:        "",
		DialTimeout: time.Duration(5 * time.Second),
		Prefix:      "pitaya/",
		Heartbeat: struct {
			TTL time.Duration
			Log bool
		}{
			TTL: time.Duration(60 * time.Second),
			Log: false,
		},
		SyncServers: struct {
			Interval    time.Duration
			Parallelism int
		}{
			Interval:    time.Duration(120 * time.Second),
			Parallelism: 10,
		},
		Revoke: struct {
			Timeout time.Duration
		}{
			Timeout: time.Duration(5 * time.Second),
		},
		GrantLease: struct {
			Timeout       time.Duration
			MaxRetries    int
			RetryInterval time.Duration
		}{
			Timeout:       time.Duration(60 * time.Second),
			MaxRetries:    15,
			RetryInterval: time.Duration(5 * time.Second),
		},
		Shutdown: struct {
			Delay time.Duration
		}{
			Delay: time.Duration(300 * time.Millisecond),
		},
		ServerTypesBlacklist: nil,
	}
}
func NewEtcdServiceDiscoveryConfig(config *Config) *EtcdServiceDiscoveryConfig {
	conf := NewDefaultEtcdServiceDiscoveryConfig()
	if err := config.UnmarshalKey("pitaya.cluster.sd.etcd", &conf); err != nil {
		panic(err)
	}
	return conf
}
func NewDefaultCustomMetricsSpec() *models.CustomMetricsSpec {
	return &models.CustomMetricsSpec{
		Summaries: []*models.Summary{},
		Gauges:    []*models.Gauge{},
		Counters:  []*models.Counter{},
	}
}
func NewCustomMetricsSpec(config *Config) *models.CustomMetricsSpec {
	spec := &models.CustomMetricsSpec{}
	if err := config.UnmarshalKey("pitaya.metrics.custom", &spec); err != nil {
		return NewDefaultCustomMetricsSpec()
	}
	return spec
}
type PrometheusConfig struct {
	Prometheus struct {
		Port             int
		AdditionalLabels map[string]string
	}
	Game        string
	ConstLabels map[string]string
}
func NewDefaultPrometheusConfig() *PrometheusConfig {
	return &PrometheusConfig{
		Prometheus: struct {
			Port             int
			AdditionalLabels map[string]string
		}{
			Port:             9090,
			AdditionalLabels: map[string]string{},
		},
		ConstLabels: map[string]string{},
	}
}
func NewPrometheusConfig(config *Config) *PrometheusConfig {
	conf := NewDefaultPrometheusConfig()
	if err := config.UnmarshalKey("pitaya.metrics", &conf); err != nil {
		panic(err)
	}
	return conf
}
type StatsdConfig struct {
	Statsd struct {
		Host   string
		Prefix string
		Rate   float64
	}
	ConstLabels map[string]string
}
func NewDefaultStatsdConfig() *StatsdConfig {
	return &StatsdConfig{
		Statsd: struct {
			Host   string
			Prefix string
			Rate   float64
		}{
			Host:   "localhost:9125",
			Prefix: "pitaya.",
			Rate:   1,
		},
		ConstLabels: map[string]string{},
	}
}
func NewStatsdConfig(config *Config) *StatsdConfig {
	conf := NewDefaultStatsdConfig()
	if err := config.UnmarshalKey("pitaya.metrics", &conf); err != nil {
		panic(err)
	}
	return conf
}
type WorkerConfig struct {
	Redis struct {
		ServerURL string
		Pool      string
		Password  string
	}
	Namespace   string
	Concurrency int
}
func NewDefaultWorkerConfig() *WorkerConfig {
	return &WorkerConfig{
		Redis: struct {
			ServerURL string
			Pool      string
			Password  string
		}{
			ServerURL: "localhost:6379",
			Pool:      "10",
		},
		Concurrency: 1,
	}
}
func NewWorkerConfig(config *Config) *WorkerConfig {
	conf := NewDefaultWorkerConfig()
	if err := config.UnmarshalKey("pitaya.worker", &conf); err != nil {
		panic(err)
	}
	return conf
}
type EnqueueOpts struct {
	Enabled     bool
	Max         int
	Exponential int
	MinDelay    int
	MaxDelay    int
	MaxRandom   int
}
func NewDefaultEnqueueOpts() *EnqueueOpts {
	return &EnqueueOpts{
		Enabled:     true,
		Max:         2,
		Exponential: 5,
		MinDelay:    10,
		MaxDelay:    10,
		MaxRandom:   0,
	}
}
func NewEnqueueOpts(config *Config) *EnqueueOpts {
	conf := NewDefaultEnqueueOpts()
	if err := config.UnmarshalKey("pitaya.worker.retry", &conf); err != nil {
		panic(err)
	}
	return conf
}
type MemoryGroupConfig struct {
	TickDuration time.Duration
}
func NewDefaultMemoryGroupConfig() *MemoryGroupConfig {
	return &MemoryGroupConfig{TickDuration: time.Duration(30 * time.Second)}
}