Exemplo n.º 1
0
func New(db *database.DB,
	mailer mailer.Mailer,
	log *logrus.Logger,
	cfg *config.Config) *Server {

	secureCookieKey, _ := base64.StdEncoding.DecodeString(cfg.SecureCookieKey)

	cookie := securecookie.New(
		[]byte(cfg.SecretKey),
		secureCookieKey,
	)

	renderOptions := render.Options{
		IsDevelopment: cfg.IsDev(),
	}

	renderer := render.New(renderOptions)

	feedparser := feedparser.New()

	return &Server{
		DB:         db,
		Config:     cfg,
		Log:        log,
		Render:     renderer,
		Cookie:     cookie,
		Feedparser: feedparser,
		Mailer:     mailer,
	}
}
Exemplo n.º 2
0
func New(db *sqlx.DB, cfg *config.Config) (*DB, error) {

	var (
		ps  purse.Purse
		err error
	)

	if cfg.IsDev() {
		ps, err = purse.New(filepath.Join(".", "sql", "queries"))
		if err != nil {
			return nil, err
		}
	} else {
		ps = sql.Queries
	}

	return &DB{
		DB:            db,
		Users:         &defaultUserDBImpl{db, ps},
		Channels:      &defaultChannelDBImpl{db, ps},
		Podcasts:      &defaultPodcastDBImpl{db, ps},
		Subscriptions: &defaultSubscriptionDBImpl{db, ps},
		Bookmarks:     &defaultBookmarkDBImpl{db, ps},
		Plays:         &defaultPlayDBImpl{db, ps},
	}, nil
}