Advices for implementing basic Go functions and unit-test them

I would like to develop various basic and useful functions in Go, so I can re-use them later in my Go programs. To give you an idea:

  • Check if a specific file exists on disk
  • Check if a specific directory exists on disk
  • Create a file for a specified location
  • Create a directory for a specified location
  • Read an array and print all the values and their index
  • Search if specific value is present in an array
  • Check if host computer has internet connectivity
  • Check if we get HTTP 200 from a URL
  • Download a file from a URL
  • Unzip a file
  • etc , etc …

All of those functions should be cross platform (Windows, Linux, Mac) and they all should have unit-tests. I am not experienced with unit-testing, so I am not sure how I can test stuff like “if a file exists” by mocking the filesystem, or “downloading a file”. I would be so thankful if you can provide me with similar examples (e.g. your libraries) or any tips/advices for that matter – and especially for testing them.

I would also like to use library for logs, so I can distinguish between info and error and debug. What would that be your preferable library to do so?

Thanks in advance

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.