Skip to content

Instantly share code, notes, and snippets.

@napicella
Created April 1, 2018 16:23
Show Gist options
  • Save napicella/e2c2edca128cae1cf94faa8a7b8208ea to your computer and use it in GitHub Desktop.
Save napicella/e2c2edca128cae1cf94faa8a7b8208ea to your computer and use it in GitHub Desktop.
Golang-patterns function type
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