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
+11
View File
@@ -0,0 +1,11 @@
package config
import "os"
func GetStoryFilePath() string {
storyFilename := os.Getenv("STORY_FILENAME")
if storyFilename != "" {
return storyFilename
}
return "./data/story/story.json"
}
+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
+10
View File
@@ -0,0 +1,10 @@
{
"places": [
{
"code": "Т-1",
"name": "Точка 1",
"text": "Текст точки 1",
"applications": [{ "name": "application 1" }]
}
]
}