Exemple #1
0
func (srv *T) Init() error {
	err := os.MkdirAll(srv.Config.General.DataPath, os.ModeDir|0700)
	if err != nil {
		return err
	}
	database, err := db.NewDB(filepath.Join(srv.Config.General.DataPath, "db"))
	if err != nil {
		return err
	}
	srv.DB = database
	srv.Log = log15.New()
	srv.Router = pubsub.New(100)
	return nil
}
Exemple #2
0
func init() {
	var dbPath string

	flag.StringVar(&dbPath, "db", "gitchain.db", "path to database, defaults to gitchain.db")
	flag.IntVar(&Port, "port", 3000, "port to connect to or serve on")
	flag.Parse()

	// Initialize database
	if len(flag.Args()) == 0 || flag.Arg(0) == "Serve" {
		var err error
		DB, err = db.NewDB(dbPath)
		if err != nil {
			log.Panicf("Can't open database %v because of %v", dbPath, err)
		}
	}
}