Skip to content

Commit a265a90

Browse files
Merge pull request #74 from fabianoflorentino/development
Development to Main
2 parents 82096cf + 7299d1e commit a265a90

File tree

7 files changed

+259
-95
lines changed

7 files changed

+259
-95
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
golang 1.24.1

build/Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /aprendago
44

55
COPY . .
66

7-
RUN apk update && apk upgrade
7+
RUN apk update && apk upgrade && go mod download
88

99
ENTRYPOINT [ "/bin/sh" ]
1010
CMD [ "-c", "while true; do echo 'Im running...' && sleep 300; done" ]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
services:
33
aprendago:
4-
image: fabianoflorentino/aprendago:v0.1
4+
image: fabianoflorentino/aprendago:v0.0.1
55
build:
66
context: .
77
dockerfile: build/Dockerfile.dev

internal/agrupamento_de_dados/topics.go

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
"fmt"
1212

1313
"github.com/fabianoflorentino/aprendago/pkg/format"
14+
"github.com/fabianoflorentino/aprendago/pkg/logger"
15+
"github.com/fabianoflorentino/aprendago/pkg/section"
16+
"github.com/fabianoflorentino/aprendago/pkg/topic"
1417
)
1518

1619
// rootDir represents the relative path to the directory where data grouping topics are stored.
@@ -19,30 +22,70 @@ const (
1922
rootDir = "internal/agrupamento_de_dados"
2023
)
2124

25+
// Array represents a fixed-size sequence of elements of the same type.
26+
// Arrays in Go have a fixed length, and their size is part of their type.
27+
// They are useful when you know the exact number of elements you need to store.
28+
const (
29+
Array string = "Array"
30+
SliceLiteralComposta string = "Slice: literal composta"
31+
SliceForRange string = "Slice: for range"
32+
SliceFatiandoOuDeletando string = "Slice: fatiando ou deletando de uma fatia"
33+
SliceAnexando string = "Slice: anexando a uma slice"
34+
SliceMake string = "Slice: make"
35+
SliceMultiDimensional string = "Slice: multi dimensional"
36+
SliceSurpresaArraySubjacente string = "Slice: a surpresa do array subjacente"
37+
MapsIntroducao string = "Maps: introdução"
38+
MapsRangeEDeletando string = "Maps: range e deletando"
39+
)
40+
2241
// AgrupamentoDeDados prints a header and executes a series of sections related to data grouping in Go.
2342
// Each section is executed by calling the executeSection function with a specific topic name.
2443
// The topics covered include arrays, slices (with various operations), and maps.
2544
func AgrupamentoDeDados() {
2645
fmt.Printf("\n\n08 - Agrupamento de Dados\n")
27-
listOfTopics()
46+
47+
// listOfTopics is a slice of strings initialized with a length of 0 and a capacity of 10.
48+
// It is used to store a list of topics, allowing dynamic growth up to the specified capacity
49+
// without reallocating memory.
50+
listOfTopics := make([]string, 0, 10)
51+
listOfTopics = append(listOfTopics, // the first element is the list that you want to append new elements to it.
52+
Array,
53+
SliceLiteralComposta,
54+
SliceForRange,
55+
SliceFatiandoOuDeletando,
56+
SliceAnexando,
57+
SliceMake,
58+
SliceMultiDimensional,
59+
SliceSurpresaArraySubjacente,
60+
MapsIntroducao,
61+
MapsRangeEDeletando,
62+
)
63+
64+
content := topic.New()
65+
content.TopicsContents(rootDir, listOfTopics)
2866
}
2967

3068
// MenuAgrupamentoDeDados returns a slice of format.MenuOptions, each representing a menu option
3169
// for different data grouping topics in Go. Each menu option includes a command-line option
3270
// string and an associated function to execute a specific section related to arrays, slices,
3371
// and maps. The function does not take any parameters and returns a slice of format.MenuOptions.
3472
func MenuAgrupamentoDeDados([]string) []format.MenuOptions {
73+
section, err := section.New(rootDir)
74+
if err != nil {
75+
logger.Log("Erro ao criar nova seção: %v", err)
76+
}
77+
3578
return []format.MenuOptions{
36-
{Options: "--array", ExecFunc: func() { executeSection("Array") }},
37-
{Options: "--slice-literal-composta", ExecFunc: func() { executeSection("Slice: literal composta") }},
38-
{Options: "--slice-for-range", ExecFunc: func() { executeSection("Slice: for range") }},
39-
{Options: "--slice-fatiando-ou-deletando-de-uma-fatia", ExecFunc: func() { executeSection("Slice: fatiando ou deletando de uma fatia") }},
40-
{Options: "--slice-anexando-a-uma-slice", ExecFunc: func() { executeSection("Slice: anexando a uma slice") }},
41-
{Options: "--slice-make", ExecFunc: func() { executeSection("Slice: make") }},
42-
{Options: "--slice-multi-dimensional", ExecFunc: func() { executeSection("Slice: multi dimensional") }},
43-
{Options: "--slice-a-surpresa-do-array-subjacente", ExecFunc: func() { executeSection("Slice: a surpresa do array subjacente") }},
44-
{Options: "--maps-introducao", ExecFunc: func() { executeSection("Maps: introdução") }},
45-
{Options: "--maps-range-e-deletando", ExecFunc: func() { executeSection("Maps: range e deletando") }},
79+
{Options: "--array", ExecFunc: func() { section.Format("Array") }},
80+
{Options: "--slice-literal-composta", ExecFunc: func() { section.Format("Slice: literal composta") }},
81+
{Options: "--slice-for-range", ExecFunc: func() { section.Format("Slice: for range") }},
82+
{Options: "--slice-fatiando-ou-deletando-de-uma-fatia", ExecFunc: func() { section.Format("Slice: fatiando ou deletando de uma fatia") }},
83+
{Options: "--slice-anexando-a-uma-slice", ExecFunc: func() { section.Format("Slice: anexando a uma slice") }},
84+
{Options: "--slice-make", ExecFunc: func() { section.Format("Slice: make") }},
85+
{Options: "--slice-multi-dimensional", ExecFunc: func() { section.Format("Slice: multi dimensional") }},
86+
{Options: "--slice-a-surpresa-do-array-subjacente", ExecFunc: func() { section.Format("Slice: a surpresa do array subjacente") }},
87+
{Options: "--maps-introducao", ExecFunc: func() { section.Format("Maps: introdução") }},
88+
{Options: "--maps-range-e-deletando", ExecFunc: func() { section.Format("Maps: range e deletando") }},
4689
}
4790
}
4891

@@ -53,56 +96,19 @@ func MenuAgrupamentoDeDados([]string) []format.MenuOptions {
5396
// function from the format package to display the list of topics.
5497
func HelpMeAgrupamentoDeDados() {
5598
hlp := []format.HelpMe{
56-
{Flag: "--array", Description: "Apresenta o tópico Array.", Width: 0},
57-
{Flag: "--slice-literal-composta", Description: "Apresenta o tópico Slice Literal Composta.", Width: 0},
58-
{Flag: "--slice-for-range", Description: "Apresenta o tópico Slice: for range.", Width: 0},
59-
{Flag: "--slice-fatiando-ou-deletando-de-uma-fatia", Description: "Apresenta o tópico Slice: fatiando ou deletando de uma fatia.", Width: 0},
60-
{Flag: "--slice-fatiando-ou-deletando-de-uma-fatia --resolucao", Description: "Apresenta a resolução do tópico Slice: fatiando ou deletando de uma fatia.", Width: 0},
61-
{Flag: "--slice-anexando-a-uma-slice", Description: "Apresenta o tópico Slice: anexando a uma slice.", Width: 0},
62-
{Flag: "--slice-make", Description: "Apresenta o tópico Slice: Make.", Width: 0},
63-
{Flag: "--slice-multi-dimensional", Description: "Apresenta o tópico Slice: Multi Dimensional.", Width: 0},
64-
{Flag: "--slice-a-surpresa-do-array-subjacente", Description: "Apresenta o tópico Slice: a surpresa do array subjacente.", Width: 0},
65-
{Flag: "--maps-introducao", Description: "Apresenta o tópico Maps: introdução.", Width: 0},
66-
{Flag: "--maps-range-e-deletando", Description: "Apresenta o tópico Maps: Range e Deletando.", Width: 0},
99+
{Flag: "--array", Description: "Apresenta o tópico Array."},
100+
{Flag: "--slice-literal-composta", Description: "Apresenta o tópico Slice Literal Composta."},
101+
{Flag: "--slice-for-range", Description: "Apresenta o tópico Slice: for range."},
102+
{Flag: "--slice-fatiando-ou-deletando-de-uma-fatia", Description: "Apresenta o tópico Slice: fatiando ou deletando de uma fatia."},
103+
{Flag: "--slice-fatiando-ou-deletando-de-uma-fatia --resolucao", Description: "Apresenta a resolução do tópico Slice: fatiando ou deletando de uma fatia."},
104+
{Flag: "--slice-anexando-a-uma-slice", Description: "Apresenta o tópico Slice: anexando a uma slice."},
105+
{Flag: "--slice-make", Description: "Apresenta o tópico Slice: Make."},
106+
{Flag: "--slice-multi-dimensional", Description: "Apresenta o tópico Slice: Multi Dimensional."},
107+
{Flag: "--slice-a-surpresa-do-array-subjacente", Description: "Apresenta o tópico Slice: a surpresa do array subjacente."},
108+
{Flag: "--maps-introducao", Description: "Apresenta o tópico Maps: introdução."},
109+
{Flag: "--maps-range-e-deletando", Description: "Apresenta o tópico Maps: Range e Deletando."},
67110
}
68111

69112
fmt.Println("\nCapítulo 8: Agrupamento de Dados")
70113
format.PrintHelpMe(hlp)
71114
}
72-
73-
// listOfTopics executes each topic in the list.
74-
// It iterates over a predefined list of topics and calls the executeSection
75-
// function for each topic. This function is used to sequentially execute
76-
// and display the content of each section.
77-
func listOfTopics() {
78-
listOfTopics := []string{
79-
"Array",
80-
"Slice: literal composta",
81-
"Slice: for range",
82-
"Slice: fatiando ou deletando de uma fatia",
83-
"Slice: anexando a uma slice",
84-
"Slice: make",
85-
"Slice: multi dimensional",
86-
"Slice: a surpresa do array subjacente",
87-
"Maps: introdução",
88-
"Maps: range e deletando",
89-
}
90-
91-
for _, topic := range listOfTopics {
92-
executeSection(topic)
93-
}
94-
}
95-
96-
// executeSection formats and processes a specific section of data.
97-
// It takes a section name as a string parameter and uses the FormatSection
98-
// function from the format package to format the section within the root directory.
99-
//
100-
// Parameters:
101-
// - section: A string representing the name of the section to be formatted.
102-
//
103-
// Example usage:
104-
//
105-
// executeSection("introduction")
106-
func executeSection(section string) {
107-
format.FormatSection(rootDir, section)
108-
}

internal/aplicacoes/topics.go

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"fmt"
88

99
"github.com/fabianoflorentino/aprendago/pkg/format"
10+
"github.com/fabianoflorentino/aprendago/pkg/logger"
11+
"github.com/fabianoflorentino/aprendago/pkg/section"
12+
"github.com/fabianoflorentino/aprendago/pkg/topic"
1013
)
1114

1215
// rootDir represents the relative path to the "aplicacoes" directory within the internal package.
@@ -15,33 +18,62 @@ const (
1518
rootDir = "internal/aplicacoes"
1619
)
1720

21+
// DocumentacaoJSON represents a topic about JSON documentation in Go programming.
22+
// It provides an overview of how to work with JSON data, including encoding and decoding.
23+
const (
24+
DocumentacaoJSON string = "Documentação JSON"
25+
JSONMarshal string = "JSON marshal (ordenação)"
26+
JSONUnmarshal string = "JSON unmarshal (desornação)"
27+
InterfaceWriter string = "A interface Writer"
28+
PacoteSort string = "O pacote sort"
29+
CustomizandoSort string = "Customizando sort"
30+
Bcrypt string = "bcrypt"
31+
)
32+
1833
// Aplicacoes prints the chapter title and executes a series of sections
1934
// related to various topics such as JSON handling, interfaces, sorting,
2035
// and encryption using bcrypt.
2136
func Aplicacoes() {
2237
fmt.Printf("\n\nCapítulo 16: Aplicações\n")
23-
listOfTopics()
38+
39+
listOfTopics := make([]string, 0, 7)
40+
listOfTopics = append(listOfTopics,
41+
DocumentacaoJSON,
42+
JSONMarshal,
43+
JSONUnmarshal,
44+
InterfaceWriter,
45+
PacoteSort,
46+
CustomizandoSort,
47+
Bcrypt,
48+
)
49+
50+
contents := topic.New()
51+
contents.TopicsContents(rootDir, listOfTopics)
2452
}
2553

2654
// MenuAplicacoes returns a slice of format.MenuOptions, each representing a different command-line option
2755
// and its corresponding execution function. The options cover various topics such as JSON documentation,
2856
// JSON marshal/unmarshal, JSON encoder, interface Writer, sort package, custom sorting, and bcrypt.
2957
// Each option is associated with a specific ExecFunc that executes the relevant section or example.
3058
func MenuAplicacoes([]string) []format.MenuOptions {
59+
section, err := section.New(rootDir)
60+
if err != nil {
61+
logger.Log("Erro ao criar nova seção: %v", err)
62+
}
3163

3264
return []format.MenuOptions{
33-
{Options: "--documentacao-json", ExecFunc: func() { executeSections("Documentação JSON") }},
65+
{Options: "--documentacao-json", ExecFunc: func() { section.Format("Documentação JSON") }},
3466
{Options: "--documentacao-json --example --json-marshal", ExecFunc: func() { UsingJsonMarshal() }},
3567
{Options: "--documentacao-json --example --json-unmarshal", ExecFunc: func() { UsingJsonUnmarshal() }},
3668
{Options: "--documentacao-json --example --json-encoder", ExecFunc: func() { UsingJsonEncoder() }},
37-
{Options: "--json-marshal", ExecFunc: func() { executeSections("JSON marshal (ordenação)") }},
38-
{Options: "--json-unmarshal", ExecFunc: func() { executeSections("JSON unmarshal (desornação)") }},
39-
{Options: "--interface-writer", ExecFunc: func() { executeSections("A interface Writer") }},
40-
{Options: "--pacote-sort", ExecFunc: func() { executeSections("O pacote sort") }},
69+
{Options: "--json-marshal", ExecFunc: func() { section.Format("JSON marshal (ordenação)") }},
70+
{Options: "--json-unmarshal", ExecFunc: func() { section.Format("JSON unmarshal (desornação)") }},
71+
{Options: "--interface-writer", ExecFunc: func() { section.Format("A interface Writer") }},
72+
{Options: "--pacote-sort", ExecFunc: func() { section.Format("O pacote sort") }},
4173
{Options: "--pacote-sort --example", ExecFunc: func() { UsingPackageSort() }},
42-
{Options: "--customizando-sort", ExecFunc: func() { executeSections("Customizando sort") }},
74+
{Options: "--customizando-sort", ExecFunc: func() { section.Format("Customizando sort") }},
4375
{Options: "--customizando-sort --example", ExecFunc: func() { UsingCustomSort() }},
44-
{Options: "--bcrypt", ExecFunc: func() { executeSections("bcrypt") }},
76+
{Options: "--bcrypt", ExecFunc: func() { section.Format("bcrypt") }},
4577
}
4678
}
4779

@@ -66,29 +98,3 @@ func HelpMeAplicacoes() {
6698
fmt.Printf("\nCapítulo 16: Aplicações\n")
6799
format.PrintHelpMe(hlp)
68100
}
69-
70-
func listOfTopics() {
71-
listOfTopics := []string{
72-
"Documentação JSON",
73-
"JSON marshal (ordenação)",
74-
"JSON unmarshal (desornação)",
75-
"A interface Writer",
76-
"O pacote sort",
77-
"Customizando sort",
78-
"bcrypt",
79-
}
80-
81-
for _, topic := range listOfTopics {
82-
executeSections(topic)
83-
}
84-
}
85-
86-
// executeSections processes a given section by formatting it.
87-
// It takes a section name as a string parameter and applies the FormatSection
88-
// function from the format package to the section, using the rootDir as the base directory.
89-
//
90-
// Parameters:
91-
// - section: The name of the section to be formatted.
92-
func executeSections(section string) {
93-
format.FormatSection(rootDir, section)
94-
}

0 commit comments

Comments
 (0)