예제 #1
0
파일: core.go 프로젝트: shiroyuki/tori-go
// Create a core of the web framework with everything pre-configured for development.
func NewSimpleCore() *Core {
	var enigma = yotsuba.Enigma{}
	var router = NewRouter()
	var actualCacheDriver = yotsuba.NewInMemoryCacheDriver(&enigma, false)
	var castedCacheDriver = yotsuba.CacheDriver(actualCacheDriver)

	return NewCore(
		router,
		&castedCacheDriver,
		&enigma,
		false,
	)
}
예제 #2
0
func StartService(
	address string,
	cachePath string,
	metadataPath string,
	debugMode bool,
) {
	cryptographer := yotsuba.Enigma{}

	memoryCacheDriver := yotsuba.NewInMemoryCacheDriver(&cryptographer, !debugMode)

	cacheDriver := yotsuba.CacheDriver(memoryCacheDriver)
	fetcherService := NewFetcher(
		&cryptographer,
		cachePath,
		metadataPath,
		true,
	)

	app := Application{
		CacheDriver:    cacheDriver,
		Cryptographer:  cryptographer,
		FetcherService: fetcherService,
	}

	core := tori.NewSimpleCore()

	core.Router.DebugMode = debugMode
	core.Router.PriorityList.DebugMode = debugMode

	core.Router.OnGet(
		"image-default",
		"/i/<destination>",
		app.HandleImage,
		true,
	)

	core.Router.OnGet(
		"image-default",
		"/i/<destination>/<spec>",
		app.HandleImage,
		true,
	)

	core.Listen(&address)
}