generated from VLADIMIR/template
add actions and auth
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package story_service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Story struct {
|
||||
Places []*Place `json:"places"`
|
||||
}
|
||||
|
||||
type Place struct {
|
||||
Code string `json:"code"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type StoryService struct {
|
||||
story *Story
|
||||
}
|
||||
|
||||
func NewStoryService() (*StoryService, error) {
|
||||
data, err := os.ReadFile("./story/story.json")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
story := &Story{}
|
||||
if err := json.Unmarshal(data, story); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StoryService{story: story}, nil
|
||||
}
|
||||
|
||||
func (s *StoryService) GetPlace(code string) (*Place, error) {
|
||||
for _, place := range s.story.Places {
|
||||
if place.Code == code {
|
||||
return place, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.New("place not found")
|
||||
}
|
||||
Reference in New Issue
Block a user