123456789101112131415161718192021222324252627282930313233343536 |
- package mhayaNats
- import (
- "time"
- cfacade "github.com/mhaya/facade"
- )
- var (
- instance = &Conn{
- running: false,
- }
- )
- func SetInstance(conn *Conn) {
- instance = conn
- }
- func NewFromConfig(config cfacade.ProfileJSON) *Conn {
- conn := New()
- conn.address = config.GetString("address")
- conn.maxReconnects = config.GetInt("max_reconnects")
- conn.reconnectDelay = config.GetDuration("reconnect_delay", 1) * time.Second
- conn.requestTimeout = config.GetDuration("request_timeout", 10) * time.Second
- conn.user = config.GetString("user")
- conn.password = config.GetString("password")
- if conn.address == "" {
- panic("address is empty!")
- }
- return conn
- }
- func Get() *Conn {
- return instance
- }
|