Exemple #1
0
func init() {
	server, ok := GetString("redis_ip")
	if !ok {
		log.Err("Config values missing")
		panic("Config values for redis missing, unable to start the server")
	}
	pass, ok := GetString("redis_pass")
	if !ok {
		log.Err("Config values missing")
		panic("Config values for redis missing, unable to start the server")
	}
	RedisPool = redis.Pool{
		MaxIdle:     3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", server)
			if err != nil {
				return nil, err
			}
			if len(pass) != 0 {
				if _, err := c.Do("AUTH", pass); err != nil {
					c.Close()
					return nil, err
				}
			}
			return c, err
		},
		TestOnBorrow: func(c redis.Conn, t time.Time) error {
			_, err := c.Do("PING")
			return err
		},
	}
}
Exemple #2
0
//Reply with given error
func Err(w http.ResponseWriter, e *ae.Error) {
	log.Err(*e)
	log.Err(string(debug.Stack()))
	jsonData, err := json.Marshal(e)
	if err != nil {
		fmt.Fprint(w, "Error")
	}
	w.Header().Set("Content-Type", "application/json")
	w.Header().Set("X-Content-Type-Options", "nosniff")
	w.WriteHeader(e.HttpStatus)
	fmt.Fprintln(w, string(jsonData))
}
Exemple #3
0
func init() {
	dbUserName, ok := GetString("pg_uname")
	if !ok {
		log.Err("Config values missing")
		panic("Config values missing, unable to start the server")
	}
	dbPass, ok := GetString("pg_pass")
	if !ok {
		log.Err("Config values missing")
		panic("Config values missing, unable to start the server")
	}

	dbIp, ok := GetString("pg_ip")
	if !ok {
		log.Err("Config values missing")
		panic("Config values missing, unable to start the server")
	}

	dbPortNo, ok := GetInt("pg_port")
	if !ok {
		log.Err("Config values missing")
		panic("Config values missing, unable to start the server")
	}

	dbName, ok := GetString("pg_name")
	if !ok {
		log.Err("Config values missing")
		panic("Config values missing, unable to start the server")
	}
	if dbPass != "" {
		dbPass = "******" + dbPass
	} else {
		dbPass = "******"
	}
	var err error
	dbStringSlice := []string{"postgres://", dbUserName, dbPass, "@", dbIp, ":", strconv.Itoa(dbPortNo), "/", dbName, "?sslmode=disable"}
	DB, err = sql.Open("postgres", strings.Join(dbStringSlice, ""))
	if err != nil {
		log.Err("Unable to connect to DB")
		panic("Unable to connect to DB")
	}

}