generated from VLADIMIR/template
add test story
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user