5376b9e271
* New config files As decided, config files are parsed at runtime. I decided to go for YAML config files because there can be comments in it. There are 2 files: * config/default_config.yml <= which shouldn't be edited unless we add a config parameter * config/config.yml <= which is the user-defined config. This file shouldn't be commited Changed every call to config.XXX to config.Conf.XXX (look to the new stucture of config in config/types.go) Of course, putting config parameters in config.yml overrides config in config_default.yml. You don't have to put everything in it, just add what you want to override. * Fixing test Replacing conf.New by config.Conf * Fixing call to config.Conf to config.Config{} in test files * Might have fixed testing with this Printf instead of Fatalf * Renaming config.yml in example file * Forbid commiting config.yml * Should be now fixed * Do not need this file anymore
40 lignes
957 o
Go
40 lignes
957 o
Go
package categories
|
|
|
|
import (
|
|
"github.com/NyaaPantsu/nyaa/config"
|
|
)
|
|
|
|
var categories map[string]string
|
|
|
|
// GetCategories : function to get all categories depending on the actual website from config/categories.go
|
|
func GetCategories() map[string]string {
|
|
if categories != nil {
|
|
return categories
|
|
}
|
|
|
|
if config.IsSukebei() {
|
|
categories = config.Conf.Torrents.SukebeiCategories
|
|
} else {
|
|
categories = config.Conf.Torrents.CleanCategories
|
|
}
|
|
|
|
return categories
|
|
}
|
|
|
|
// CategoryExists : Check if a category exist in config
|
|
func CategoryExists(category string) bool {
|
|
_, exists := GetCategories()[category]
|
|
return exists
|
|
}
|
|
|
|
// GetCategoriesSelect : Format categories in map ordered alphabetically
|
|
func GetCategoriesSelect(keepParent bool) map[string]string {
|
|
categories := GetCategories()
|
|
catSelect := make(map[string]string, len(categories))
|
|
for k, v := range categories {
|
|
if len(k) > 2 || keepParent {
|
|
catSelect[v] = k
|
|
}
|
|
}
|
|
return catSelect
|
|
}
|