Output file named export-data.csv : id,name,lastname,username,organization 0001a,Jon,Pan,Jon999,Amazon 0002b,Jack,Jonsson,Jackjon,Amazon 0003c,Antony,King,KinKong007,GoogleĬool! … As you can see use CSV files with golang is easy and you could use this code as a base code nd start doing your implementations. Main.go package main import ( "encoding/csv" "fmt" "os" ) type user struct We need to define a structure to map the CSV values.For this example, we going to use the encoding/csv package.(In this case, we going to use only the main file). Reading user input or writing to a file are some of the basic input/output (IO) operations developers need to perform as they get started with programming in Go. And now let us define the code of the main.Flush: We use flush after writing to the file to ensure all the writes are executed before the program terminates. Here: We write the string 'ABC' to a file on the disk. We must use os.Create (not os.Open) to write a file. Id,name,lastname,username,organization 0001a,Jon,Pan,Jon999,Amazon 0002b,Jack,Jonsson,Jackjon,Amazon 0003c,Antony,King,KinKong007,Google The file handle we pass to NewWriter must have write access. The sample users_to_import.csv defines inside the following:.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |