package daemon import ( "errors" "git.beejay.kim/WatchDog/ward/platform" "git.beejay.kim/tool/service/config" "reflect" "strings" ) type Configuration struct { config.Configuration `yaml:",inline"` Platform _platform `yaml:"platform"` } func (c Configuration) Invalidate() error { return config.Invalidate(c) } type _platform struct { Afreeca *platform.Afreeca `yaml:"afreeca"` } func (r *_platform) Detect(pid, bid string) (platform.Platform, error) { if pid = strings.TrimSpace(pid); pid == "" { return nil, errors.New("empty platform") } val := reflect.ValueOf(r).Elem() if val.Kind() != reflect.Struct { if val.IsZero() { return nil, errors.New("config is empty") } val = reflect.ValueOf(r).Elem() } for k := 0; k < val.NumField(); k++ { if !val.Field(k).CanInterface() || val.Field(k).IsZero() { continue } if elm, ok := val.Field(k).Interface().(platform.Platform); ok && elm.Id() == pid { if err := elm.Init(bid); err != nil { return nil, err } return elm, nil } } return nil, errors.New("platform not found") }