pcm-participant/ai/algorithm/feature.go

98 lines
2.1 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package algorithm
import "context"
type Features struct {
HasPublic bool
HasPrivate bool
HasPreset bool
IsStoredLocally bool
IsStoredRemote bool
HasVersionControl bool
HasRecommendation bool
Recommended func(ctx context.Context) (Algorithms, error)
Public func(ctx context.Context) (Algorithms, error)
Private func(ctx context.Context) (Algorithms, error)
Preset func(ctx context.Context) (Algorithms, error)
}
type FeatureSpec struct {
SpecBondWithId bool //资源提交时是否需要绑定Id
SpecHasVersionControl bool
SpecBasedOnRepository bool
SpecBasedOnFileSystem bool
WithId func() (*Id, error)
WithIdVsn func() (*IdVsn, error)
WithFilePath func() (*FilePath, error)
WithCodeRepo func() (*CodeRepository, error)
}
func (ft *Features) Fill(ctx context.Context, algorithm IAlgorithm) *Features {
if do, ok := algorithm.(Recommended); ok {
ft.Recommended = do.Recommended
}
if do, ok := algorithm.(Public); ok {
ft.Public = do.Public
}
if do, ok := algorithm.(Private); ok {
ft.Private = do.Private
}
if do, ok := algorithm.(Preset); ok {
ft.Preset = do.Preset
}
return ft
}
func (ft *FeatureSpec) Fill(ctx context.Context, spec ISpec) *FeatureSpec {
if do, ok := spec.(WithId); ok {
ft.WithId = do.WithId
}
if do, ok := spec.(WithIdVsn); ok {
ft.WithIdVsn = do.WithIdVsn
}
if do, ok := spec.(WithFilePath); ok {
ft.WithFilePath = do.WithFilePath
}
if do, ok := spec.(WithCodeRepo); ok {
ft.WithCodeRepo = do.WithCodeRepo
}
return ft
}
type Recommended interface {
Recommended(ctx context.Context) (Algorithms, error)
}
type Public interface {
Public(ctx context.Context) (Algorithms, error)
}
type Private interface {
Private(ctx context.Context) (Algorithms, error)
}
type Preset interface {
Preset(ctx context.Context) (Algorithms, error)
}
// return id
type WithId interface {
WithId() (*Id, error)
}
type WithIdVsn interface {
WithIdVsn() (*IdVsn, error)
}
// return without id
type WithFilePath interface {
WithFilePath() (*FilePath, error)
}
type WithCodeRepo interface {
WithCodeRepo() (*CodeRepository, error)
}