Ejemplo n.º 1
0
func init() {
	// Main DB for storing all data (MySQL)
	// username, password, ipAddress, port, name string
	mainDB, err := utils.ConnectDB("root", "root", "33.33.33.10", "3306", "oaked_db")
	MainDBGlbl = mainDB

	if err != nil {
		panic("Unable to connect to DB")
	}
}
Ejemplo n.º 2
0
func main() {
	// Load Environment
	err := godotenv.Load()
	if err != nil {
		os.Exit(-1)
	}

	// Logging with Papertrail
	logger := logrus.New()
	paperTrailPort, err := strconv.Atoi(os.Getenv("OAKED_PAPERTRAIL_PORT"))

	if err != nil {
		logger.Fatal("Unable to convert port to int")
		os.Exit(-1)
	}

	hook, err := logrus_papertrail.NewPapertrailHook(
		&logrus_papertrail.Hook{
			Host:     os.Getenv("OAKED_PAPERTRAIL_HOST"),
			Port:     paperTrailPort,
			Appname:  os.Getenv("OAKED_PAPERTRAIL_HOST_NAME"),
			Hostname: os.Getenv("OAKED_PAPERTRAIL_APP_NAME"),
		})

	if err == nil {
		logger.Hooks.Add(hook)
	} else {
		logger.Fatal("Unable to attach Papertrail Hook")
		os.Exit(-1)
	}

	// Main DB for storing all data (MySQL)
	mainDB, err := utils.ConnectDB(
		os.Getenv("OAKED_MAIN_DB_USERNAME"),
		os.Getenv("OAKED_MAIN_DB_PASSWORD"),
		os.Getenv("OAKED_MAIN_DB_IP_ADDR"),
		os.Getenv("OAKED_MAIN_DB_PORT"),
		os.Getenv("OAKED_MAIN_DB"))

	defer mainDB.Close()

	if err != nil {
		logger.Printf("Unable to connect to Main DB (%v)", err)
		os.Exit(-1)
	}
	/*
		// Cache DB w/ Bolt
		cacheDB, err := bolt.Open(
			os.Getenv("THISY_CACHE_DB"),
			0600,
			&bolt.Options{Timeout: 1 * time.Second})

		if err != nil {
			logger.Printf("Unable to connect to Cache DB (%v)", err)
			os.Exit(-1)
		}

		defer cacheDB.Close()

		// Setup the DB Buckets (if not already done)
		err = cacheDB.Update(func(tx *bolt.Tx) error {
			_, err := tx.CreateBucketIfNotExists([]byte(
				os.Getenv("OAKED_CACHE_DB_EMBED_BUCKET")))
			_, err = tx.CreateBucketIfNotExists([]byte(
				os.Getenv("OAKED_CACHE_DB_STORES_BUCKET")))
			return err
		})

		if err != nil {
			logger.Printf("Unable to create cache DB buckets (%v)", err)
			os.Exit(-1)
		}

		// Session DB (for auth)
		sessionStore, err := redistore.NewRediStore(
			10,
			"tcp",
			os.Getenv("OAKED_SESSION_DB_PORT"),
			os.Getenv("OAKED_SESSION_DB_AUTH"),
			[]byte(os.Getenv("OAKED_SESSION_DB_SESSION_BUCKET")))

		if err != nil {
			logger.Printf("Unable to connect to Session DB (%v)", err)
			os.Exit(-1)
		}

		defer sessionStore.Close()

		sessionStore.Options = &sessions.Options{
			Domain:   os.Getenv("THISY_SESSION_DOMAIN"),
			Path:     "/",
			MaxAge:   30 * 24 * 3600,
			Secure:   true,
			HttpOnly: true,
		}
	*/
	// Template Loading

	// Routing & HTTP Server
	mx := mux.NewRouter()
	router.Router(mx,
		&config.Env{
			MainDB: mainDB,
			//	Cache:   cacheDB,
			Log: logger,
			//	Session: sessionStore
		})

	jobrunner.Start()

	http.ListenAndServe(":9001", mx)
}