add test story

This commit is contained in:
2025-06-14 21:28:46 +07:00
parent 77854681a0
commit 3a2980e9d0
7 changed files with 50 additions and 5 deletions
+6 -4
View File
@@ -2,7 +2,8 @@ package story_service
import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strings"
)
@@ -44,11 +45,12 @@ type StoryService struct {
story *Story
}
func NewStoryService() (*StoryService, error) {
data, err := os.ReadFile("./data/story/story.json")
func NewStoryService(filepath string) (*StoryService, error) {
data, err := os.ReadFile(filepath)
if err != nil {
return nil, errors.New("Файл истории не найден")
return nil, fmt.Errorf("story file %s not found", filepath)
}
log.Printf("load story from: %s", filepath)
story := &Story{}
if err := json.Unmarshal(data, story); err != nil {
return nil, err