mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
initial Go port of streamrip
This commit is contained in:
33
internal/domain/media/media.go
Normal file
33
internal/domain/media/media.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package media
|
||||
|
||||
import "context"
|
||||
|
||||
type Media interface {
|
||||
Rip(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Pending interface {
|
||||
Resolve(ctx context.Context) (Media, error)
|
||||
}
|
||||
|
||||
type MediaFunc struct {
|
||||
RipFn func(ctx context.Context) error
|
||||
}
|
||||
|
||||
func (m MediaFunc) Rip(ctx context.Context) error {
|
||||
if m.RipFn == nil {
|
||||
return nil
|
||||
}
|
||||
return m.RipFn(ctx)
|
||||
}
|
||||
|
||||
type PendingFunc struct {
|
||||
ResolveFn func(ctx context.Context) (Media, error)
|
||||
}
|
||||
|
||||
func (p PendingFunc) Resolve(ctx context.Context) (Media, error) {
|
||||
if p.ResolveFn == nil {
|
||||
return MediaFunc{}, nil
|
||||
}
|
||||
return p.ResolveFn(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user