👔 Created simple static use case implementation
This commit is contained in:
parent
7d8246e901
commit
77fa1b0b5e
|
@ -0,0 +1,37 @@
|
|||
package usecase
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"source.toby3d.me/toby3d/home/internal/domain"
|
||||
"source.toby3d.me/toby3d/home/internal/static"
|
||||
)
|
||||
|
||||
type staticUseCase struct {
|
||||
statics static.Repository
|
||||
}
|
||||
|
||||
func NewStaticUseCase(statics static.Repository) static.UseCase {
|
||||
return &staticUseCase{
|
||||
statics: statics,
|
||||
}
|
||||
}
|
||||
|
||||
func (ucase *staticUseCase) Do(ctx context.Context, p string) (*domain.File, error) {
|
||||
p = strings.TrimPrefix(path.Clean(p), "/")
|
||||
|
||||
if ext := path.Ext(p); ext == ".html" || ext == ".md" {
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
|
||||
f, err := ucase.statics.Get(ctx, p)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get static file: %w", err)
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
Loading…
Reference in New Issue