LEARN GOLANG| Part-4

  • Reading a File from Local Directory.
  • Manage Dependencies in Go.
  • Creation of Module in Go.
  • Reading little complex configuration files in Go.
  • Generating an output File from Local Directory.
  • Scrapping data from Internet / Website.
  • Parsing the text data into JSON.
  • Here @ line #14, we are specifying the name of the file, from which we are planning to read the data.
  • Here @ line #20, note that, data being read from the file is always in BYTES format and we need to convert the same to string format, to display the same in human readable format.
  • Go Get tool installs one dependency at a time. And it installs the latest version of the package.
  • Using a specific version of the package will also protect you from breaking changes the package might have. In Go 111, we got a new mod tool to handle dependency management.
  • At line #20, we now open the file, and as usual, validate the error, which should be not nil.
  • At line #27, we use a new decoder for toml and then using the same decoder, we would read the configuration file and populate the configuration object directly.
  • Here @ line #13, we are specifying the name of the file, that we are planning to generate.
  • Here @ line #16, we are suggesting to generate a file with data being stored in the variable “content”.
  • In the output section below, it’s evident that a output file has been generated well.
  • Here @ line #19, keyword “defer” is very important, as it shall wait for everything, untill this line executes.
  • Here @ line #12, we are using the http.Get call in order to receive the data from aforementioned URL.
  • Here @ line #17, we are reading the response thus received in the “resp” variable.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
aditya goel

aditya goel

Software Engineer for Big Data distributed systems