Last active
April 1, 2018 14:36
-
-
Save napicella/d5ba583f0da4b9f5e0fa1f479be6cb25 to your computer and use it in GitHub Desktop.
Golang-patterns Chain example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chain | |
import "fmt" | |
func ExampleChain() { | |
endpoint, _ := chain( | |
loadEndpointFromConfigFile, | |
loadEndpointFromEnvVariables, | |
loadEndpointFromDatabase, | |
).get() | |
fmt.Println(endpoint) | |
// Output: some-endpoint | |
} | |
func loadEndpointFromEnvVariables() (string, error) { | |
return "", nil | |
} | |
func loadEndpointFromConfigFile() (string, error) { | |
return "", nil | |
} | |
func loadEndpointFromDatabase() (string, error) { | |
return "some-endpoint", nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment