Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Fix categories on sukebei

Cette révision appartient à :
akuma06 2017-07-22 02:41:28 +02:00
Parent a69b0b4ead
révision b797b7aacf
2 fichiers modifiés avec 17 ajouts et 5 suppressions

Voir le fichier

@ -3,6 +3,7 @@ package router
import (
"sync"
"github.com/NyaaPantsu/nyaa/config"
"github.com/gin-gonic/gin"
)
@ -12,6 +13,9 @@ var once sync.Once
// Get return a router signleton
func Get() *gin.Engine {
once.Do(func() {
if config.Get().Environment == "PRODUCTION" {
gin.SetMode(gin.ReleaseMode)
}
router = gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())

Voir le fichier

@ -3,6 +3,8 @@ package categories
import (
"sort"
"fmt"
"github.com/NyaaPantsu/nyaa/config"
)
@ -21,7 +23,10 @@ var Index map[string]int
// InitCategories init the categories and index variables. Exported for tests
func InitCategories() {
var cats map[string]string
fmt.Println(config.Get().Models.TorrentsTableName)
fmt.Println(config.IsSukebei())
if config.IsSukebei() {
fmt.Println("works")
cats = config.Get().Torrents.SukebeiCategories
} else {
cats = config.Get().Torrents.CleanCategories
@ -44,24 +49,27 @@ func InitCategories() {
}
}
func init() {
// All : function to get all categories depending on the actual website from config/categories.go
func All() Categories {
if len(categories) == 0 {
InitCategories()
}
}
// All : function to get all categories depending on the actual website from config/categories.go
func All() Categories {
return categories
}
// Get : function to get a category by the key in the index array
func Get(key int) Category {
if len(categories) == 0 {
InitCategories()
}
return All()[key]
}
// GetByID : function to get a category by the id of the category from the database
func GetByID(id string) (Category, bool) {
if len(categories) == 0 {
InitCategories()
}
if key, ok := Index[id]; ok {
return All()[key], true
}