From da242596bdab678eadb82c7e2d3af11dfa9a8acd Mon Sep 17 00:00:00 2001 From: Pedro Correa Date: Mon, 26 May 2025 18:48:03 -0300 Subject: [PATCH] :sparkles: (Go) parse yaml files --- Go/yaml-config/figlet.yaml | 2 ++ Go/yaml-config/go.mod | 5 +++++ Go/yaml-config/go.sum | 4 ++++ Go/yaml-config/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100755 Go/yaml-config/figlet.yaml create mode 100644 Go/yaml-config/go.mod create mode 100644 Go/yaml-config/go.sum create mode 100644 Go/yaml-config/main.go diff --git a/Go/yaml-config/figlet.yaml b/Go/yaml-config/figlet.yaml new file mode 100755 index 0000000..afafcbc --- /dev/null +++ b/Go/yaml-config/figlet.yaml @@ -0,0 +1,2 @@ +name: figlet +image: docker.io/functions/figlet:latest diff --git a/Go/yaml-config/go.mod b/Go/yaml-config/go.mod new file mode 100644 index 0000000..2a8a55c --- /dev/null +++ b/Go/yaml-config/go.mod @@ -0,0 +1,5 @@ +module github.com/Tulkdan/Languages/Go/yaml-config + +go 1.23.2 + +require gopkg.in/yaml.v3 v3.0.1 diff --git a/Go/yaml-config/go.sum b/Go/yaml-config/go.sum new file mode 100644 index 0000000..a62c313 --- /dev/null +++ b/Go/yaml-config/go.sum @@ -0,0 +1,4 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/Go/yaml-config/main.go b/Go/yaml-config/main.go new file mode 100644 index 0000000..cfe9f1f --- /dev/null +++ b/Go/yaml-config/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "os" + + yaml "gopkg.in/yaml.v3" +) + +type Spec struct { + Name string `yaml:"name"` + Image string `yaml:"image"` + Environment map[string]string `yaml:"environment,omitempty"` + Limits *FunctionResources `yaml:"limits,omitempty"` +} + +type FunctionResources struct { + Memory string `yaml:"memory"` + CPU string `yaml:"cpu"` +} + +func main() { + spec := Spec{ + Image: "docker.io/functions/figlet:latest", + Name: "figlet", + } + + bytesOut, err := yaml.Marshal(spec) + if err != nil { + panic(err) + } + + if err := os.WriteFile("figlet.yaml", bytesOut, os.ModePerm); err != nil { + panic(err) + } + + fmt.Printf("Wrote: figlet.yaml.. Ok.\n") +} -- 2.51.2