You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
656 B
35 lines
656 B
package audio
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
type AudioFile struct {
|
|
FileName string
|
|
Contents []byte
|
|
}
|
|
|
|
type AudioMemoryStorage struct {
|
|
Data map[string]AudioFile
|
|
}
|
|
|
|
func NewAudioMemoryStorage() *AudioMemoryStorage {
|
|
return &AudioMemoryStorage{Data: map[string]AudioFile{}}
|
|
}
|
|
|
|
func (audio *AudioMemoryStorage) put(a AudioFile) (err error) {
|
|
_, ok := audio.Data[a.FileName]
|
|
if !ok {
|
|
audio.Data[a.FileName] = a
|
|
return nil
|
|
}
|
|
return errors.New("already exists")
|
|
}
|
|
|
|
func (audio *AudioMemoryStorage) get(filename string) (a AudioFile, err error) {
|
|
val, ok := audio.Data[filename]
|
|
if ok {
|
|
return val, nil
|
|
}
|
|
return AudioFile{}, errors.New("not found")
|
|
}
|
|
|