diff --git a/.vscode/launch.json b/.vscode/launch.json index b7540a2..7ecbabc 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,6 +15,21 @@ ], "cwd": "${workspaceFolder}", "buildFlags": "-tags local" + }, + { + "name": "Local Launch", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}/cmd/evening_detective", + "args": [ + "--local" + ], + "cwd": "${workspaceFolder}", + "buildFlags": "-tags local", + "env": { + "STORY_FILENAME": "./internal/tests/story.json" + } } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index c019ca1..83cdb44 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,12 @@ { "cSpell.words": [ "Приложение", + "Текст", + "Точка", + "точки", "AUTOINCREMENT", "gwmux", + "localtime", "palces" ] } \ No newline at end of file diff --git a/cmd/evening_detective/main.go b/cmd/evening_detective/main.go index 5511999..827fd8e 100644 --- a/cmd/evening_detective/main.go +++ b/cmd/evening_detective/main.go @@ -3,6 +3,7 @@ package main import ( "context" "evening_detective/internal/app" + "evening_detective/internal/config" "evening_detective/internal/services" "evening_detective/internal/services/story_service" proto "evening_detective/proto" @@ -30,7 +31,9 @@ func main() { if err != nil { panic(err) } - storyService, err := story_service.NewStoryService() + + storyFilepath := config.GetStoryFilePath() + storyService, err := story_service.NewStoryService(storyFilepath) if err != nil { log.Fatalln(err) } diff --git a/data/db/store_09.06.2025.db b/data/db/store_09.06.2025.db new file mode 100644 index 0000000..0b16cb3 Binary files /dev/null and b/data/db/store_09.06.2025.db differ diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..c16e730 --- /dev/null +++ b/internal/config/config.go @@ -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" +} diff --git a/internal/services/story_service/service.go b/internal/services/story_service/service.go index e842781..7358b2f 100644 --- a/internal/services/story_service/service.go +++ b/internal/services/story_service/service.go @@ -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 diff --git a/internal/tests/story.json b/internal/tests/story.json new file mode 100644 index 0000000..b9a60d4 --- /dev/null +++ b/internal/tests/story.json @@ -0,0 +1,10 @@ +{ + "places": [ + { + "code": "Т-1", + "name": "Точка 1", + "text": "Текст точки 1", + "applications": [{ "name": "application 1" }] + } + ] +}