ng generate component component-name
, but for your own projectsng generate component component-name
go mod init github.com/edwardtanguay/datapod-for-react-go-json
package mainimport "fmt"func main() {fmt.Println("this will create a new page in the app")}
package mainimport "fmt"func main() {fmt.Println("this will parse data in a text file into a JSON file")}
"cp": "cd scripts/cmd/create-page && go run .","pd": "cd scripts/cmd/parse-data && go run .",
npm run cp
npm run pd
npm i
npm run dev
itand it will take some timee ci vorrà del tempoitthis will ensure that you getcìo garantirà di ottenereesthis has certain advantagesest tiene ciertas ventajasesin such a way thatde tal manera que
package utilsimport "fmt"/*Output information in console in a uniform waydevlog("no files are locked")devlog(fmt.Sprintf("There are %d flashcards.", len(flashcards)))*/func Devlog(line string) {fmt.Printf("DEBUG ### %s ################################\n", line)}
package utilsimport ("os""strings")/*Get all lines from a file as a slice of stringslines := getLinesFromFile("../../notes.txt")use relative path*/func GetLinesFromFile(fileName string) []string {byteContents, err := os.ReadFile(fileName)if err != nil {panic(err)}contents := string(byteContents)lines := strings.Split(contents, "\n")for i, line := range lines {lines[i] = strings.TrimSpace(line)}return lines}
package mainimport ("datapod-for-react-go-json/utils")func main() {utils.Devlog("this will create a page")}
/*...*/
comment block above your utility functions will show up in these editors as well, which gives you context-related help on the functions you are usingpackage mainimport ("datapod-for-react-go-json/utils""fmt")func main() {utils.Devlog("this shows the lines of the text file")lines := utils.GetLinesFromFile("../../../data/flashcards.txt")for i, line := range lines {fmt.Printf("%03d: %s\n", i+1, line)}}
npm run pd
package utilsimport ("crypto/rand""math/big")/*Return a random suuid (short uuid = 6 characters)suuid := GenerateShortUUID()returns e.g. "q35HZa"*/func GenerateShortUUID() string {const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"const length = 6bytes := make([]byte, length)for i := 0; i < length; i++ {randomByte, err := rand.Int(rand.Reader, big.NewInt(int64(len(charset))))if err != nil {panic(err)}bytes[i] = charset[randomByte.Int64()]}return string(bytes)}
package mainimport ("datapod-for-react-go-json/utils""encoding/json""fmt""os""strings")type Flashcard struct {Suuid string `json:"suuid"`Category string `json:"category"`Front string `json:"front"`Back string `json:"back"`}func main() {fmt.Println("parsing flashcards.txt into flashcards.json...")lines := utils.GetLinesFromFile("../../../data/flashcards.txt")var flashcards []Flashcardfor i := 0; i < len(lines); i += 4 {if i+3 > len(lines) {break}category := strings.TrimSpace(lines[i])front := strings.TrimSpace(lines[i+1])back := strings.TrimSpace(lines[i+2])flashcards = append(flashcards, Flashcard{Suuid: utils.GenerateShortUUID(),Category: category,Front: front,Back: back,})}jsonData, err := json.MarshalIndent(flashcards, "", "\t")if err != nil {fmt.Printf("Error marshaling JSON: %v\n", err)return}err = os.WriteFile("../../../datajson/flashcards.json", jsonData, 0644)if err != nil {fmt.Printf("Error writing JSON file: %v\n", err)return}fmt.Println("successfully updated flashcards.json")}
npm run pd
command, a new flashcard will appear on your site