Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ваш комментарий #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .gitignore
Binary file not shown.
53 changes: 49 additions & 4 deletions encoding/encoding.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package encoding

import (
"encoding/json"
"io/ioutil"

"github.com/Yandex-Practicum/final-project-encoding-go/models"
"gopkg.in/yaml.v3"
)

// JSONData тип для перекодирования из JSON в YAML
Expand All @@ -23,18 +27,59 @@ type MyEncoder interface {
Encoding() error
}

// Encoding перекодирует файл из JSON в YAML
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Скопировала строчку?)

// Encoding перекодирует файл из JSON в YAML
func (j *JSONData) Encoding() error {
// ниже реализуйте метод
// ...
jsonContent, err := ioutil.ReadFile(j.FileInput)
if err != nil {
return err
}

// Создаем новый экземпляр DockerCompose
j.DockerCompose = &models.DockerCompose{}

err = yaml.Unmarshal(jsonContent, j.DockerCompose)
if err != nil {
return err
}

yamlContent, err := yaml.Marshal(j.DockerCompose)
if err != nil {
return err
}

err = ioutil.WriteFile(j.FileOutput, yamlContent, 0644)
if err != nil {
return err
}

return nil
}

// Encoding перекодирует файл из YAML в JSON
func (y *YAMLData) Encoding() error {
// Ниже реализуйте метод
// ...
yamlContent, err := ioutil.ReadFile(y.FileInput)
if err != nil {
return err
}

// Создаем новый экземпляр DockerCompose
y.DockerCompose = &models.DockerCompose{}

err = yaml.Unmarshal(yamlContent, y.DockerCompose)
if err != nil {
return err
}

jsonContent, err := json.Marshal(y.DockerCompose)
if err != nil {
return err
}

err = ioutil.WriteFile(y.FileOutput, jsonContent, 0644)
if err != nil {
return err
}

return nil
}
1 change: 1 addition & 0 deletions jsonInput.json
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А файлы с фикстурами точно надо было коммитить?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а как правильно надо было сделать?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну в игнор добавить файлы просто

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"3","services":{"web":{"build":".","ports":["5000:5000"],"volumes":["/usercode/:/code"],"links":["database:backenddb"]},"database":{"image":"mysql/mysql-server:5.7","environment":["MYSQL_ROOT_PASSWORD=root","MYSQL_USER=testuser","MYSQL_PASSWORD=admin123","MYSQL_DATABASE=backend"],"volumes":["/usercode/db/init.sql:/docker-entrypoint-initdb.d/init.sql"]}}}
1 change: 1 addition & 0 deletions jsonOutput.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"3","services":{"web":{"build":".","ports":["5000:5000"],"volumes":["/usercode/:/code"],"links":["database:backenddb"]},"database":{"image":"mysql/mysql-server:5.7","environment":["MYSQL_ROOT_PASSWORD=root","MYSQL_USER=testuser","MYSQL_PASSWORD=admin123","MYSQL_DATABASE=backend"],"volumes":["/usercode/db/init.sql:/docker-entrypoint-initdb.d/init.sql"]}}}
19 changes: 19 additions & 0 deletions yamlInput.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3"
services:
web:
build: .
ports:
- 5000:5000
volumes:
- /usercode/:/code
links:
- database:backenddb
database:
image: mysql/mysql-server:5.7
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=testuser
- MYSQL_PASSWORD=admin123
- MYSQL_DATABASE=backend
volumes:
- /usercode/db/init.sql:/docker-entrypoint-initdb.d/init.sql
19 changes: 19 additions & 0 deletions yamlOutput.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3"
services:
web:
build: .
ports:
- 5000:5000
volumes:
- /usercode/:/code
links:
- database:backenddb
database:
image: mysql/mysql-server:5.7
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=testuser
- MYSQL_PASSWORD=admin123
- MYSQL_DATABASE=backend
volumes:
- /usercode/db/init.sql:/docker-entrypoint-initdb.d/init.sql