Skip to content

Instantly share code, notes, and snippets.

View nunnatsa's full-sized avatar

Nahshon Unna Tsameret nunnatsa

View GitHub Profile
@nunnatsa
nunnatsa / README.md
Last active January 28, 2021 08:17
Return a 3-State Value from a golang Method

Return a 3-State Value from a golang Function

Note: The solution I'm going to present here is for private functions, a function that are well known to the author of the package; for example, a function that was split out of a larger funtion, in order to have cleaner code.

Functions in golang often returns an erorr value, letting the caller to deciede what to do with them. But there are cases where a binary response is not enough.

For example, let's say my software reads an optional configuration file for a non-critical activity. The implementation function for this activity will be totally OK with the absence of this configuration file. It will just exit with no error.

package main
/*
Description:
Parsing an NMTOKENS XML tag into a slice of strings
*/
import (
"encoding/xml"
"strings"
"time"