34 lines
606 B
Go
34 lines
606 B
Go
package service
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/crypt"
|
|
)
|
|
|
|
func GetTFUrl(tf string) string {
|
|
if tf != "" {
|
|
type tfStc struct {
|
|
Url string `json:"url"`
|
|
Name string `json:"name"`
|
|
}
|
|
var tfArr []tfStc
|
|
_ = crypt.JSON2Struct(tf, &tfArr)
|
|
if len(tfArr) == 0 {
|
|
return tf
|
|
}
|
|
weight := 100 / len(tfArr)
|
|
chioce := make([]common.Choice, len(tfArr))
|
|
for i := range tfArr {
|
|
chioce[i] = common.Choice{
|
|
Weight: weight,
|
|
Item: tfArr[i].Url,
|
|
}
|
|
}
|
|
ch, _ := common.WeightedChoice(chioce)
|
|
if v, ok := ch.Item.(string); ok {
|
|
return v
|
|
}
|
|
}
|
|
return tf
|
|
}
|