home/internal/static/usecase/static_ucase.go

33 lines
595 B
Go

package usecase
import (
"context"
"fmt"
"path"
"strings"
"source.toby3d.me/toby3d/home/internal/domain"
"source.toby3d.me/toby3d/home/internal/static"
)
type staticUseCase struct {
store static.Repository
}
func NewStaticUseCase(store static.Repository) static.UseCase {
return &staticUseCase{
store: store,
}
}
func (ucase *staticUseCase) Do(ctx context.Context, p string) (*domain.Static, error) {
p = strings.TrimPrefix(path.Clean(p), "/")
s, err := ucase.store.Get(ctx, p)
if err != nil {
return nil, fmt.Errorf("cannot get static file: %w", err)
}
return s, nil
}