Beispiel #1
0
package test

import (
	"os"
	"testing"

	dbo "github.com/urandom/readeef/content/sql/db"
	"github.com/urandom/readeef/content/sql/sqlite3"
	"github.com/urandom/readeef/tests"
	"github.com/urandom/webfw"
)

func TestRepo(t *testing.T) {
	tests.CheckBool(t, false, repo.HasErr())
}

var (
	logger = webfw.NewStandardLogger(os.Stderr, "", 0)
	db     = dbo.New(logger)
	repo   = sqlite3.NewRepo(db, logger)
)
Beispiel #2
0
func main() {
	serverconfpath := flag.String("server-config", "", "server config path")
	readeefconfpath := flag.String("readeef-config", "", "readeef config path")
	address := flag.String("address", "", "local server network address")
	port := flag.Int("port", 0, "server port")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*readeefconfpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *readeefconfpath, err))
	}

	logger := readeef.NewLogger(cfg)
	defer func() {
		if rec := recover(); rec != nil {
			stack := debug.Stack()
			logger.Fatalf("Fatal error: %v\n%s\n", rec, stack)
		}
	}()

	server := webfw.NewServer(*serverconfpath)
	if *address != "" {
		server.Address = *address
	}

	if *port > 0 {
		server.Port = *port
	}

	var accessWriter io.Writer
	if cfg.Logger.AccessFile == "-" {
		accessWriter = os.Stdout
	} else {
		accessWriter = &lumberjack.Logger{
			Filename:   cfg.Logger.AccessFile,
			MaxSize:    20,
			MaxBackups: 5,
			MaxAge:     28,
		}
	}

	accessLogger := webfw.NewStandardLogger(accessWriter, "", 0)

	dispatcher := server.Dispatcher("/api/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	if err := api.RegisterControllers(cfg, dispatcher, logger); err != nil {
		exitWithError(err.Error())
	}

	dispatcher = server.Dispatcher("/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	web.RegisterControllers(cfg, dispatcher, "/api/")

	if err := server.ListenAndServe(); err != nil {
		exitWithError(fmt.Sprintf("Error starting server: %s\n", err.Error()))
	}
}
Beispiel #3
0
func main() {
	configpath := flag.String("config", "", "readeef config path")

	flag.Parse()

	cfg, err := readeef.ReadConfig(*configpath)
	if err != nil {
		exitWithError(fmt.Sprintf("Error reading config from path '%s': %v", *configpath, err))
	}

	if len(cfg.Config.Session.IgnoreURLPrefix) == 0 {
		cfg.Config.Session.IgnoreURLPrefix = []string{"/v2/fever", "/v12/tt-rss"}
	}
	if len(cfg.Config.I18n.Languages) == 0 {
		cfg.Config.I18n.Languages = []string{"en", "bg"}
	}
	if len(cfg.Config.I18n.IgnoreURLPrefix) == 0 {
		cfg.Config.I18n.IgnoreURLPrefix = []string{"/dist", "/js", "/css", "/images", "/proxy"}
	}

	logger := readeef.NewLogger(cfg)
	defer func() {
		if rec := recover(); rec != nil {
			stack := debug.Stack()
			logger.Fatalf("Fatal error: %v\n%s\n", rec, stack)
		}
	}()

	server := webfw.NewServerWithConfig(cfg.Config)

	var accessWriter io.Writer
	if cfg.Logger.AccessFile == "-" {
		accessWriter = os.Stdout
	} else {
		accessWriter = &lumberjack.Logger{
			Filename:   cfg.Logger.AccessFile,
			MaxSize:    20,
			MaxBackups: 5,
			MaxAge:     28,
		}
	}

	accessLogger := webfw.NewStandardLogger(accessWriter, "", 0)

	dispatcher := server.Dispatcher("/api/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	if err := api.RegisterControllers(cfg, dispatcher, logger); err != nil {
		exitWithError(err.Error())
	}

	dispatcher = server.Dispatcher("/")
	dispatcher.Logger = logger
	dispatcher.RegisterMiddleware(middleware.Logger{AccessLogger: accessLogger})

	web.RegisterControllers(cfg, dispatcher, "/api/")

	if err := server.ListenAndServe(); err != nil {
		exitWithError(fmt.Sprintf("Error starting server: %s\n", err.Error()))
	}
}