generated from VLADIMIR/template
add test story
This commit is contained in:
parent
77854681a0
commit
3a2980e9d0
15
.vscode/launch.json
vendored
15
.vscode/launch.json
vendored
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,8 +1,12 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"Приложение",
|
||||
"Текст",
|
||||
"Точка",
|
||||
"точки",
|
||||
"AUTOINCREMENT",
|
||||
"gwmux",
|
||||
"localtime",
|
||||
"palces"
|
||||
]
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
BIN
data/db/store_09.06.2025.db
Normal file
BIN
data/db/store_09.06.2025.db
Normal file
Binary file not shown.
11
internal/config/config.go
Normal file
11
internal/config/config.go
Normal 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"
|
||||
}
|
@ -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
internal/tests/story.json
Normal file
10
internal/tests/story.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"places": [
|
||||
{
|
||||
"code": "Т-1",
|
||||
"name": "Точка 1",
|
||||
"text": "Текст точки 1",
|
||||
"applications": [{ "name": "application 1" }]
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user