ch5ex18

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

README

= Exercise 5.18
// Refs:
:url-base: https://github.com/fenegroni/TGPL-exercise-solutions
:workflow: workflows/Exercise 5.18
:action: actions/workflows/ch5ex18.yml
:url-workflow: {url-base}/{workflow}
:url-action: {url-base}/{action}
:badge-exercise: image:{url-workflow}/badge.svg?branch=main[link={url-action}]

{badge-exercise}

Without changing its behaviour, rewrite the `fetch` function to use `defer` to close the writable file.

== Test

We want to test that the file is correctly closed by defer.
We don't need to set up a server, and the file can be assumed to be local.
What we want is to make sure the file is closed correctly.

=== Implementation

We validate that defer works using an anonymous function to print a log line.
The output is validated using the 'deferred close call' sentence.

NOTE: A better strategy is to implement the OS file handle count.
Unfortunately this requires system calls to find out
if a file descriptor is in use by a process.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch

func Fetch(url string) (string, int64, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL