-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9706085
commit c44cffc
Showing
26 changed files
with
10,142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/marianina8/example8/utils" | ||
) | ||
|
||
func main() { | ||
filename := flag.String("file", "", "Input file name") | ||
flag.Parse() | ||
|
||
if *filename == "" { | ||
log.Fatal("Error: no input file specified") | ||
} | ||
|
||
yamlData, err := utils.Transform(*filename) | ||
if err != nil { | ||
log.Fatalf("Error: unable to transform the file; unexpected format: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(string(yamlData)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"title": "Building Modern CLI Applications with Go", | ||
"instructors": [ | ||
{ | ||
"name": "Marian Montagnino", | ||
"email": "mmontagnino@netflix.com" | ||
}, | ||
{ | ||
"name": "Romeric Philogene", | ||
"email": "rphiologene@qovery.com" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
1: Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
2: Sed in leo vestibulum, viverra libero eu, facilisis velit. | ||
3: Fusce faucibus nibh sed turpis sagittis bibendum. | ||
4: Integer luctus leo vel libero molestie, vitae consequat turpis venenatis. | ||
5: Quisque et tortor rutrum, lobortis arcu in, congue metus. | ||
6: Praesent dapibus sapien id nibh suscipit, at commodo quam suscipit. | ||
7: Nullam ullamcorper lorem eu sapien interdum, non posuere ipsum euismod. | ||
8: Pellentesque vel mauris nec turpis ultrices auctor. | ||
9: Curabitur gravida justo vel lacinia tempus. | ||
10: Donec commodo sapien vitae justo finibus sagittis. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/marianina8/example8 | ||
|
||
go 1.19 | ||
|
||
require gopkg.in/yaml.v2 v2.4.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package models | ||
|
||
type Instructor struct { | ||
Name string `json:"name"` | ||
Email string `json:"email"` | ||
} | ||
|
||
type Workshop struct { | ||
Title string `json:"title"` | ||
Instructors []Instructor `json:"instructors"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/marianina8/example8/models" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func Transform(filename string) ([]byte, error) { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
bytes, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var jsonData models.Workshop | ||
err = json.Unmarshal(bytes, &jsonData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
yamlData, err := yaml.Marshal(&jsonData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return yamlData, nil | ||
} |
17 changes: 17 additions & 0 deletions
17
session1/examples/example8/vendor/gopkg.in/yaml.v2/.travis.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
201 changes: 201 additions & 0 deletions
201
session1/examples/example8/vendor/gopkg.in/yaml.v2/LICENSE
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
session1/examples/example8/vendor/gopkg.in/yaml.v2/LICENSE.libyaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.