mirror of
https://github.com/fxkt-tech/liv
synced 2025-09-26 20:11:20 +08:00
45 lines
760 B
Go
45 lines
760 B
Go
package filter
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Filter struct {
|
|
// instreams []string
|
|
// content string
|
|
// outstreams []string
|
|
opt *option
|
|
}
|
|
|
|
func New(opts ...OptionFunc) *Filter {
|
|
o := &option{}
|
|
for _, opt := range opts {
|
|
opt(o)
|
|
}
|
|
return &Filter{
|
|
opt: o,
|
|
}
|
|
}
|
|
|
|
func (f *Filter) Params() (params []string) {
|
|
if len(f.opt.instreams) != 0 {
|
|
for _, stream := range f.opt.instreams {
|
|
params = append(params, fmt.Sprintf("[%s]", stream))
|
|
}
|
|
}
|
|
if f.opt.content != "" {
|
|
params = append(params, f.opt.content)
|
|
}
|
|
if len(f.opt.outstreams) != 0 {
|
|
for _, stream := range f.opt.outstreams {
|
|
params = append(params, fmt.Sprintf("[%s]", stream))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (f *Filter) String() string {
|
|
return strings.Join(f.Params(), "")
|
|
}
|