Move all the code to a lib folder
This commit is contained in:
parent
e963d00014
commit
9d1f1ad5c0
31 changed files with 123 additions and 98 deletions
46
config.go
46
config.go
|
@ -1,48 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HOST_URL = "xfmro77i3lixucja.onion"
|
PORT = "8080"
|
||||||
PORT = "8080"
|
|
||||||
|
|
||||||
DB_IP = "127.0.0.1"
|
DB_IP = "127.0.0.1"
|
||||||
DB_NAME = "trantor"
|
DB_NAME = "trantor"
|
||||||
META_COLL = "meta"
|
|
||||||
|
|
||||||
EPUB_FILE = "book.epub"
|
STORE_PATH = "store/"
|
||||||
COVER_FILE = "cover.jpg"
|
|
||||||
COVER_SMALL_FILE = "coverSmall.jpg"
|
|
||||||
|
|
||||||
MINUTES_UPDATE_TAGS = 11
|
|
||||||
MINUTES_UPDATE_VISITED = 41
|
|
||||||
MINUTES_UPDATE_DOWNLOADED = 47
|
|
||||||
MINUTES_UPDATE_HOURLY_V = 31
|
|
||||||
MINUTES_UPDATE_DAILY_V = 60*12 + 7
|
|
||||||
MINUTES_UPDATE_MONTHLY_V = 60*24 + 11
|
|
||||||
MINUTES_UPDATE_HOURLY_D = 29
|
|
||||||
MINUTES_UPDATE_DAILY_D = 60*12 + 13
|
|
||||||
MINUTES_UPDATE_MONTHLY_D = 60*24 + 17
|
|
||||||
MINUTES_UPDATE_LOGGER = 5
|
|
||||||
BOOKS_FRONT_PAGE = 6
|
|
||||||
SEARCH_ITEMS_PAGE = 20
|
|
||||||
NEW_ITEMS_PAGE = 50
|
|
||||||
NUM_NEWS = 10
|
|
||||||
DAYS_NEWS_INDEXPAGE = 15
|
|
||||||
CACHE_MAX_AGE = 1800
|
|
||||||
|
|
||||||
STORE_PATH = "store/"
|
|
||||||
TEMPLATE_PATH = "templates/"
|
|
||||||
CSS_PATH = "css/"
|
|
||||||
JS_PATH = "js/"
|
|
||||||
IMG_PATH = "img/"
|
|
||||||
ROBOTS_PATH = "robots.txt"
|
|
||||||
DESCRIPTION_PATH = "description.json"
|
|
||||||
OPENSEARCH_PATH = "opensearch.xml"
|
|
||||||
KEY_PATH = "key.asc"
|
|
||||||
LOGGER_CONFIG = "logger.xml"
|
|
||||||
|
|
||||||
IMG_WIDTH_BIG = 300
|
|
||||||
IMG_WIDTH_SMALL = 60
|
|
||||||
IMG_QUALITY = 80
|
|
||||||
|
|
||||||
CHAN_SIZE = 100
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func deleteHandler(h handler) {
|
func deleteHandler(h handler) {
|
44
lib/config.go
Normal file
44
lib/config.go
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package trantor
|
||||||
|
|
||||||
|
const (
|
||||||
|
HOST_URL = "xfmro77i3lixucja.onion"
|
||||||
|
|
||||||
|
META_COLL = "meta"
|
||||||
|
|
||||||
|
EPUB_FILE = "book.epub"
|
||||||
|
COVER_FILE = "cover.jpg"
|
||||||
|
COVER_SMALL_FILE = "coverSmall.jpg"
|
||||||
|
|
||||||
|
MINUTES_UPDATE_TAGS = 11
|
||||||
|
MINUTES_UPDATE_VISITED = 41
|
||||||
|
MINUTES_UPDATE_DOWNLOADED = 47
|
||||||
|
MINUTES_UPDATE_HOURLY_V = 31
|
||||||
|
MINUTES_UPDATE_DAILY_V = 60*12 + 7
|
||||||
|
MINUTES_UPDATE_MONTHLY_V = 60*24 + 11
|
||||||
|
MINUTES_UPDATE_HOURLY_D = 29
|
||||||
|
MINUTES_UPDATE_DAILY_D = 60*12 + 13
|
||||||
|
MINUTES_UPDATE_MONTHLY_D = 60*24 + 17
|
||||||
|
MINUTES_UPDATE_LOGGER = 5
|
||||||
|
BOOKS_FRONT_PAGE = 6
|
||||||
|
SEARCH_ITEMS_PAGE = 20
|
||||||
|
NEW_ITEMS_PAGE = 50
|
||||||
|
NUM_NEWS = 10
|
||||||
|
DAYS_NEWS_INDEXPAGE = 15
|
||||||
|
CACHE_MAX_AGE = 1800
|
||||||
|
|
||||||
|
TEMPLATE_PATH = "templates/"
|
||||||
|
CSS_PATH = "css/"
|
||||||
|
JS_PATH = "js/"
|
||||||
|
IMG_PATH = "img/"
|
||||||
|
ROBOTS_PATH = "robots.txt"
|
||||||
|
DESCRIPTION_PATH = "description.json"
|
||||||
|
OPENSEARCH_PATH = "opensearch.xml"
|
||||||
|
KEY_PATH = "key.asc"
|
||||||
|
LOGGER_CONFIG = "logger.xml"
|
||||||
|
|
||||||
|
IMG_WIDTH_BIG = 300
|
||||||
|
IMG_WIDTH_SMALL = 60
|
||||||
|
IMG_QUALITY = 80
|
||||||
|
|
||||||
|
CHAN_SIZE = 100
|
||||||
|
)
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "image/gif"
|
_ "image/gif"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/meskio/epubgo"
|
"github.com/meskio/epubgo"
|
||||||
"github.com/nfnt/resize"
|
"github.com/nfnt/resize"
|
||||||
"gitlab.com/trantor/trantor/storage"
|
"gitlab.com/trantor/trantor/lib/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func coverHandler(h handler) {
|
func coverHandler(h handler) {
|
|
@ -1,9 +1,9 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type newsData struct {
|
type newsData struct {
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/meskio/epubgo"
|
"github.com/meskio/epubgo"
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type chapter struct {
|
type chapter struct {
|
|
@ -1,11 +1,11 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type searchData struct {
|
type searchData struct {
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sesStore = sessions.NewCookieStore(securecookie.GenerateRandomKey(64))
|
var sesStore = sessions.NewCookieStore(securecookie.GenerateRandomKey(64))
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -9,8 +9,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
"gitlab.com/trantor/trantor/storage"
|
"gitlab.com/trantor/trantor/lib/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
|
@ -1,15 +1,15 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitTasks(db *database.DB) {
|
func InitTasks(db *database.DB) {
|
||||||
periodicTask(updateLogger, MINUTES_UPDATE_LOGGER*time.Minute)
|
periodicTask(UpdateLogger, MINUTES_UPDATE_LOGGER*time.Minute)
|
||||||
periodicTask(db.UpdateTags, MINUTES_UPDATE_TAGS*time.Minute)
|
periodicTask(db.UpdateTags, MINUTES_UPDATE_TAGS*time.Minute)
|
||||||
periodicTask(db.UpdateMostVisited, MINUTES_UPDATE_VISITED*time.Minute)
|
periodicTask(db.UpdateMostVisited, MINUTES_UPDATE_VISITED*time.Minute)
|
||||||
periodicTask(db.UpdateDownloadedBooks, MINUTES_UPDATE_DOWNLOADED*time.Minute)
|
periodicTask(db.UpdateDownloadedBooks, MINUTES_UPDATE_DOWNLOADED*time.Minute)
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
txt_tmpl "text/template"
|
txt_tmpl "text/template"
|
||||||
|
@ -11,7 +11,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -6,12 +6,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
"gitlab.com/trantor/trantor/storage"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type statusData struct {
|
type statusData struct {
|
||||||
|
@ -147,7 +145,7 @@ func notFound(h handler) {
|
||||||
loadTemplate(h, "404", data)
|
loadTemplate(h, "404", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateLogger() error {
|
func UpdateLogger() error {
|
||||||
logger, err := log.LoggerFromConfigAsFile(LOGGER_CONFIG)
|
logger, err := log.LoggerFromConfigAsFile(LOGGER_CONFIG)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -156,32 +154,7 @@ func updateLogger() error {
|
||||||
return log.ReplaceLogger(logger)
|
return log.ReplaceLogger(logger)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func InitRouter(db *database.DB, sg *StatsGatherer) {
|
||||||
defer log.Flush()
|
|
||||||
err := updateLogger()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Error loading the logger xml: ", err)
|
|
||||||
}
|
|
||||||
log.Info("Start the imperial library of trantor")
|
|
||||||
|
|
||||||
db := database.Init(DB_IP, DB_NAME)
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
store, err := storage.Init(STORE_PATH)
|
|
||||||
if err != nil {
|
|
||||||
log.Critical("Problem initializing store: ", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
InitTasks(db)
|
|
||||||
sg := InitStats(db, store)
|
|
||||||
InitUpload(db, store)
|
|
||||||
|
|
||||||
initRouter(db, sg)
|
|
||||||
log.Error(http.ListenAndServe(":"+PORT, nil))
|
|
||||||
}
|
|
||||||
|
|
||||||
func initRouter(db *database.DB, sg *StatsGatherer) {
|
|
||||||
const id_pattern = "[0-9a-zA-Z\\-\\_]{16}"
|
const id_pattern = "[0-9a-zA-Z\\-\\_]{16}"
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
|
@ -10,9 +10,9 @@ import (
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
|
|
||||||
"github.com/meskio/epubgo"
|
"github.com/meskio/epubgo"
|
||||||
"gitlab.com/trantor/trantor/database"
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
"gitlab.com/trantor/trantor/parser"
|
"gitlab.com/trantor/trantor/lib/parser"
|
||||||
"gitlab.com/trantor/trantor/storage"
|
"gitlab.com/trantor/trantor/lib/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitUpload(database *database.DB, store *storage.Store) {
|
func InitUpload(database *database.DB, store *storage.Store) {
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package trantor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
46
main.go
Normal file
46
main.go
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"gitlab.com/trantor/trantor/lib"
|
||||||
|
"gitlab.com/trantor/trantor/lib/database"
|
||||||
|
"gitlab.com/trantor/trantor/lib/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
PORT = "8080"
|
||||||
|
|
||||||
|
DB_IP = "127.0.0.1"
|
||||||
|
DB_NAME = "trantor"
|
||||||
|
|
||||||
|
STORE_PATH = "store/"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
defer log.Flush()
|
||||||
|
err := trantor.UpdateLogger()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error loading the logger xml: ", err)
|
||||||
|
}
|
||||||
|
log.Info("Start the imperial library of trantor")
|
||||||
|
|
||||||
|
db := database.Init(DB_IP, DB_NAME)
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
store, err := storage.Init(STORE_PATH)
|
||||||
|
if err != nil {
|
||||||
|
log.Critical("Problem initializing store: ", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
trantor.InitTasks(db)
|
||||||
|
sg := trantor.InitStats(db, store)
|
||||||
|
trantor.InitUpload(db, store)
|
||||||
|
|
||||||
|
trantor.InitRouter(db, sg)
|
||||||
|
log.Error(http.ListenAndServe(":"+PORT, nil))
|
||||||
|
}
|
Reference in a new issue