Change default struct of Tags in Search Struct (#1437)
Doing this makes it possible to use the method from ArrayString (Contains and Join). Therefore: * Tags.Join() would return a string of all the tags separated by commas * Tags.Contains(str) would return a boolean on whether there is the str or not
Cette révision appartient à :
Parent
9bb26a7dbe
révision
195912d11f
|
@ -1,5 +1,9 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Config : Configuration for DB, I2P, Fetcher, Go Server and Translation
|
||||
type Config struct {
|
||||
Host string `json:"host" yaml:"host,omitempty"`
|
||||
|
@ -211,8 +215,10 @@ type SearchConfig struct {
|
|||
ElasticsearchType string `yaml:"es_type,omitempty"`
|
||||
}
|
||||
|
||||
// ArrayString is an array of string with some easy functions
|
||||
type ArrayString []string
|
||||
|
||||
// Contains check if there is a string in the array of string
|
||||
func (ar ArrayString) Contains(str string) bool {
|
||||
for _, s := range ar {
|
||||
if s == str {
|
||||
|
@ -222,6 +228,11 @@ func (ar ArrayString) Contains(str string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// Join regroup the array of string in one string separated by commas
|
||||
func (ar ArrayString) Join() string {
|
||||
return strings.Join(ar, ",")
|
||||
}
|
||||
|
||||
var tagtypes map[string]int
|
||||
|
||||
func initTagTypes() {
|
||||
|
|
|
@ -2,10 +2,12 @@ package search
|
|||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
)
|
||||
|
||||
// Tags struct for search
|
||||
type Tags []string
|
||||
type Tags config.ArrayString
|
||||
|
||||
// Parse a tag list separated by commas to Tags struct
|
||||
func (ta *Tags) Parse(str string) bool {
|
||||
|
|
Référencer dans un nouveau ticket