Ejemplo n.º 1
0
func main() {
	r.SetVerbose(true)

	defer utils.Recover()
	utils.ListenSignals()
	utils.Liveness()

	if os.Getenv("DEBUG_N") != "true" {
		gin.SetMode(gin.ReleaseMode)
	}

	engine := gin.New()

	engine.Use(gin.Recovery())
	engine.Use(func() gin.HandlerFunc {
		return func(c *gin.Context) {
			defer c.Next()
			log.Info(c.Request.Method, c.Request.URL.Path, c.Writer.Status())
		}
	}())

	api.Initialize(engine)

	engine.Run(config.Get(config.KEY_API_PORT))
}
Ejemplo n.º 2
0
func NewWebsocketClient(realms []string) *WebSocketClient {
	connect := func() (interface{}, error) {
		c, err := gowamp.NewWebsocketClient(gowamp.JSON, config.Get(config.KEY_REALTIME_ADDR))
		if err != nil {
			return nil, err
		}

		for _, r := range realms {
			c.JoinRealm(r, nil)
		}

		return c, err
	}

	baseClient := NewClient(connect, config.Get(config.KEY_REALTIME_ADDR))

	return &WebSocketClient{baseClient}
}
Ejemplo n.º 3
0
func (n *NatsClient) Subscribe(c string, cb nats.Handler) error {
	for {
		if n.GetConnection() != nil {
			_, err := n.GetConnection().Subscribe(config.Get(config.CONST_REALTIME_JOBS_SUBJ), cb)
			return err
		} else {
			time.Sleep(time.Second * 1)
		}
	}
}
Ejemplo n.º 4
0
func (d *dbService) GetSession() (*r.Session, error) {
	addr := config.Get(config.KEY_RETHINK_ADDR)

	session, err := r.Connect(r.ConnectOpts{Address: addr})

	if err != nil {
		return nil, err
	}

	return session, nil
}
Ejemplo n.º 5
0
func GetNewRedisClient() *redis.Client {
	redisAddr := config.Get(config.KEY_REDIS_ADDR)
	//TODO: check if will reconnect automatically on lost connection
	redisClient := redis.NewClient(&redis.Options{
		Addr:     redisAddr,
		Password: "",
		DB:       0,
	})

	log.Info("Connected to redis client on:", redisAddr)
	return redisClient
}
Ejemplo n.º 6
0
func NewApiClient(appId string) *ApiClient {
	url := config.Get(config.KEY_API_ADDR)

	return &ApiClient{
		BaseUrl:        url,
		Token:          "",
		ClientId:       "",
		NotifyRealTime: false,
		AppId:          appId,
		Origin:         "api",
	}
}
Ejemplo n.º 7
0
func main() {
	r.SetVerbose(true)

	defer utils.Recover()
	utils.ListenSignals()
	utils.Liveness()

	err := server.Initialize()
	if err != nil {
		panic(err)
	}

	log.Info("Realtime service listening")
	log.Error(http.ListenAndServe(config.Get(config.KEY_REALTIME_PORT), nil))
}
Ejemplo n.º 8
0
func main() {
	s, connectErr := r.Connect(r.ConnectOpts{
		Address: config.Get(config.KEY_RETHINK_ADDR),
	})

	fmt.Println("Preparing rethinkdb")

	if connectErr != nil {
		fmt.Println(connectErr)
	}

	dbname := db.DATABASE_NAME

	fmt.Println("Creating database " + dbname)
	_, dbErr := r.DBCreate(dbname).RunWrite(s)
	if dbErr != nil {
		fmt.Println(dbErr)
	}

	fmt.Println("Creating table " + db.USERS_TABLE)
	_, usersTableError := r.DB(dbname).TableCreate(db.USERS_TABLE).RunWrite(s)
	if usersTableError != nil {
		fmt.Println(usersTableError)
	}

	fmt.Println("Creating indexes for " + db.USERS_TABLE)
	_, createEmailIndexError := r.DB(dbname).Table(db.USERS_TABLE).IndexCreate(db.USERS_TABLE_EMAIL_INDEX).RunWrite(s)
	if createEmailIndexError != nil {
		fmt.Println(createEmailIndexError)
	}

	fmt.Println("Creating table " + db.DATA_TABLE)
	_, dataTableError := r.DB(dbname).TableCreate(db.DATA_TABLE).RunWrite(s)
	if dataTableError != nil {
		fmt.Println(dataTableError)
	}

	fmt.Println("Creating index for table " + db.DATA_TABLE)
	_, createDataEmailAppidIndexError := r.DB(dbname).Table(db.DATA_TABLE).
		IndexCreateFunc(db.DATA_TABLE_APPIDTYPE_INDEX, func(row r.Term) interface{} {
			return []interface{}{row.Field(db.APP_ID_FIELD), row.Field(db.TYPE_FIELD)}
		}).RunWrite(s)
	if createDataEmailAppidIndexError != nil {
		fmt.Println(createDataEmailAppidIndexError)
	}

	fmt.Println("Creating table " + db.APPS_TABLE)
	_, createAppTableError := r.DB(dbname).TableCreate(db.APPS_TABLE).RunWrite(s)
	if createAppTableError != nil {
		fmt.Println(createAppTableError)
	}

	fmt.Println("Creating table " + db.APPS_USERS_TABLE)
	_, createAppsUsersTableError := r.DB(dbname).TableCreate(db.APPS_USERS_TABLE).RunWrite(s)
	if createAppsUsersTableError != nil {
		fmt.Println(createAppsUsersTableError)
	}

	fmt.Println("Creating index for table " + db.APPS_USERS_TABLE)
	_, createAppsUsersTableIndexError := r.DB(dbname).Table(db.APPS_USERS_TABLE).
		IndexCreateFunc(db.APPS_USERS_TABLE_EMAILAPPID_INDEX, func(row r.Term) interface{} {
			return []interface{}{row.Field(db.EMAIL_FIELD), row.Field(db.APP_ID_FIELD)}
		}).RunWrite(s)
	if createAppsUsersTableIndexError != nil {
		fmt.Println(createAppsUsersTableIndexError)
	}

	fmt.Println("Done preparing rethinkdb")
}