config

package
v1.0.178 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

type Api struct {
	Name string `json:"name"`
	Host string `json:"host"`
	Port int    `json:"port"`
	Path string `json:"path"`

	Swagger  Swagger  `json:"swagger"`
	Cors     Cors     `json:"cors"`
	Https    Https    `json:"https"`
	Gateway  Gateway  `json:"gateway"`
	Timeouts Timeouts `json:"timeouts"`
	Dbs      []string `json:"dbs"`
	Ativo    bool     `json:"ativo"`
}

func (*Api) GetPortStr

func (a *Api) GetPortStr() string

type Bot

type Bot struct {
	Name  string   `json:"name"`
	Dbs   []string `json:"dbs"`
	Ativo bool     `json:"ativo"`
}

type Cert

type Cert struct {
	Name         string
	Ativo        bool
	Path_crt     string
	Path_private string
	Pass         string
}

type Certs

type Certs []*Cert

func (*Certs) GetCert

func (c *Certs) GetCert(value string) (bool, *Cert)

type Config

type Config struct {
	Dbs      []*Database `json:"dbs"`
	Services []*Service  `json:"services"`
	Bots     []*Bot      `json:"bots"`
	Apis     []*Api      `json:"apis"`
	Jwt      []*Jwt      `json:"jwt"`
	Parans   Params      `json:"parans"`
	Certs    Certs       `json:"certs"`
	Log      Log         `json:"log"`
	Monitor  *Monitor    `json:"monitor,omitempty"`
	Path     string      `json:"path"`
	JsonFile string
}
var InstanceConfig *Config

func NewConfig

func NewConfig() *Config

func (*Config) AddApi

func (c *Config) AddApi(api Api)

func (*Config) AddDb

func (c *Config) AddDb(db Database)

func (*Config) AddService

func (c *Config) AddService(service Service)

func (*Config) GetApi

func (c *Config) GetApi(name string) (bool, *Api)

func (*Config) GetBot

func (c *Config) GetBot(name string) (bool, *Bot)

func (*Config) GetCert

func (c *Config) GetCert(name string) (bool, *Cert)

func (*Config) GetDB

func (c *Config) GetDB(name string) (bool, *Database)

func (*Config) GetJwt added in v1.0.144

func (c *Config) GetJwt(name string) (bool, *Jwt)

func (*Config) GetService

func (c *Config) GetService(name string) (bool, *Service)

func (*Config) RemoveApi

func (c *Config) RemoveApi(api Api)

func (*Config) RemoveDb

func (c *Config) RemoveDb(db Database)

func (*Config) RemoveService

func (c *Config) RemoveService(service Service)

func (*Config) Save

func (c *Config) Save() error

type Cors

type Cors struct {
	MaxAge           int      `json:"maxAge"`
	AllowCredentials bool     `json:"allowCredentials"`
	AllowHeaders     []string `json:"allowHeaders"`
	ExposedHeaders   []string `json:"exposedHeaders"`
	AllowMethods     []string `json:"allowMethods"`
	AllowOrigins     []string `json:"allowOrigins"`
	Ativo            bool     `json:"ativo"`
}

type Database

type Database struct {
	Name     string `json:"name"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	User     string `json:"user"`
	Pass     string `json:"pass"`
	Schema   string `json:"schema"`
	Sid      string `json:"sid"`
	PoolSize int    `json:"poolsize"`
	MaxConn  int    `json:"maxconn"`
	Ativo    bool   `json:"ativo"`
	Trace    Trace  `json:"trace"`
	Db       string `json:"db"`
}

func (Database) GetDsn

func (d Database) GetDsn() string

type Gateway

type Gateway struct {
	Protocolo string `json:"protocolo"`
	Host      string `json:"host"`
	Port      int    `json:"port"`
	Ativo     bool   `json:"ativo"`
}

type Https

type Https struct {
	Cert     string    `json:"cert"`
	Key      string    `json:"key"`
	Validate time.Time `json:"validate"`
	Ativo    bool      `json:"ativo"`
}

type Jwt added in v1.0.143

type Jwt struct {
	Name           string `json:"name"`
	ExpirationTime int    `json:"expirationTime"`
	SecretKey      string `json:"secret"`
}

type Log added in v1.0.143

type Log struct {
	Nivel  int  `json:"nivel"`
	Screen bool `json:"screen"`
}

type Monitor added in v1.0.173

type Monitor struct {
	Ativo        bool          `json:"ativo"`
	Host         string        `json:"host"`
	Port         int           `json:"port"`
	User         string        `json:"user"`
	Pass         string        `json:"pass"`
	SessionKey   string        `json:"sessionKey"`
	IntervalSec  int           `json:"intervalSec"`
	RetentionMin int           `json:"retentionMin"`
	Alerts       []MonitorRule `json:"alerts"`
}

func (*Monitor) GetPortStr added in v1.0.173

func (m *Monitor) GetPortStr() string

type MonitorRule added in v1.0.173

type MonitorRule struct {
	Name      string  `json:"name"`
	Metric    string  `json:"metric"`
	Op        string  `json:"op"`
	Threshold float64 `json:"threshold"`
	WindowSec int     `json:"windowSec"`
	Severity  string  `json:"severity"`
	Ativo     bool    `json:"ativo"`
}

type Param

type Param struct {
	Marcador string
	Name     string
	Value    string
}

type Params

type Params []*Param

func (*Params) GetParam

func (p *Params) GetParam(Marcador, Name string) (bool, string)

type Service

type Service struct {
	Name  string   `json:"name"`
	Dbs   []string `json:"dbs"`
	Ativo bool     `json:"ativo"`
}

type Swagger

type Swagger struct {
	AuthJwt bool `json:"authJwt"`
	Ativo   bool `json:"ativo"`
}

type Timeouts added in v1.0.173

type Timeouts struct {
	// ReadHeaderTimeout — tempo máximo para o servidor ler o cabeçalho
	// HTTP da requisição (do início da conexão até o fim dos headers).
	//
	// Para que serve: protege contra ataques tipo "slowloris", em que
	// um cliente abre muitas conexões e envia bytes lentamente para
	// esgotar as conexões disponíveis.
	//
	// Aumentar: clientes em redes muito lentas conseguem completar
	// o handshake/headers. Pode ser necessário em redes móveis ruins.
	// Diminuir: rejeita conexões lentas/maliciosas mais cedo,
	// liberando recursos do servidor.
	//
	// Default quando 0: 10 segundos.
	ReadHeaderTimeout int `json:"read_header_timeout"`

	// ReadTimeout — tempo máximo para o servidor ler a requisição
	// inteira (cabeçalho + body) do cliente.
	//
	// Para que serve: limita por quanto tempo uma requisição pode
	// ficar "em andamento" do lado de leitura.
	//
	// Aumentar: necessário se sua API recebe uploads grandes ou
	// clientes lentos enviando POSTs/PUTs longos.
	// Diminuir: abandona requisições demoradas mais cedo, libera
	// goroutines presas. Cuidado: se for menor que o tempo real
	// de upload típico, uploads serão cortados no meio.
	//
	// Default quando 0: 30 segundos.
	ReadTimeout int `json:"read_timeout"`

	// WriteTimeout — tempo máximo para o servidor escrever a resposta
	// completa para o cliente (a partir do fim da leitura do header).
	//
	// Para que serve: limita por quanto tempo o handler pode demorar
	// para gerar e enviar a resposta.
	//
	// Aumentar: necessário se você tem endpoints SÍNCRONOS que
	// processam por muito tempo (ex: relatórios pesados, exportações,
	// queries longas). Caso contrário o cliente recebe a conexão
	// fechada no meio da resposta.
	// Diminuir: corta handlers que demoram demais, evita "pendurar"
	// o servidor com handlers lentos.
	//
	// Default quando 0: 60 segundos.
	WriteTimeout int `json:"write_timeout"`

	// IdleTimeout — tempo máximo que uma conexão keep-alive ociosa
	// fica aberta aguardando a próxima requisição do mesmo cliente.
	//
	// Para que serve: controla reuso de conexões TCP entre múltiplas
	// requisições do mesmo cliente.
	//
	// Aumentar: reduz o overhead de reabrir conexões para clientes
	// que fazem requisições frequentes (ex: SPAs, microserviços
	// chamando uns aos outros). Mantém mais conexões abertas.
	// Diminuir: libera recursos mais rápido em clientes esporádicos.
	// Pode aumentar latência se o cliente sempre precisa renegociar.
	//
	// Default quando 0: 120 segundos.
	IdleTimeout int `json:"idle_timeout"`

	// ShutdownTimeout — tempo máximo que o servidor espera as
	// requisições em andamento terminarem ao receber sinal de parada
	// (graceful shutdown).
	//
	// Para que serve: ao parar o serviço, aguarda os handlers ativos
	// completarem suas respostas em vez de cortar conexões abruptamente.
	//
	// Aumentar: dá mais tempo para handlers longos completarem antes
	// do shutdown forçado. Necessário se você tem handlers que podem
	// demorar para terminar.
	// Diminuir: o serviço para mais rápido, mas pode cortar respostas
	// no meio. Útil em ambientes onde reinício rápido é prioridade.
	//
	// Default quando 0: 10 segundos.
	ShutdownTimeout int `json:"shutdown_timeout"`
}

Timeouts define os tempos limite do servidor HTTP da API. Todos os valores são em SEGUNDOS. Quando 0 (ou ausente no JSON), o helper correspondente aplica o default seguro indicado em cada campo.

func (Timeouts) Idle added in v1.0.173

func (t Timeouts) Idle() time.Duration

func (Timeouts) Read added in v1.0.173

func (t Timeouts) Read() time.Duration

func (Timeouts) ReadHeader added in v1.0.173

func (t Timeouts) ReadHeader() time.Duration

func (Timeouts) Shutdown added in v1.0.173

func (t Timeouts) Shutdown() time.Duration

func (Timeouts) Write added in v1.0.173

func (t Timeouts) Write() time.Duration

type Trace

type Trace struct {
	Path  string `json:"path"`
	Ativo bool   `json:"ativo"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL