Created
April 1, 2018 16:23
-
-
Save napicella/e2c2edca128cae1cf94faa8a7b8208ea to your computer and use it in GitHub Desktop.
Golang-patterns function type
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 functiontype | |
import "fmt" | |
type Greeting func(name string) string | |
func GreetingService(request Request, greeting Greeting) string { | |
return fmt.Sprintf("Service says: %s", greeting(request.user)) | |
} | |
func ExampleFunctionType() { | |
request := Request{user: "Mickey"} | |
fmt.Println( | |
GreetingService(request, func(name string) string { | |
return fmt.Sprintf("Hola %s!", name) | |
}), | |
) | |
// Output: Service says: Hola Mickey! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment