Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save namp10010/5694edad5b2fd664185a82587b524b62 to your computer and use it in GitHub Desktop.
Save namp10010/5694edad5b2fd664185a82587b524b62 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
var sendEmail emailAction = func(payload string) {
fmt.Printf("sending email: %v\n", payload)
}
action := sendEmail.
authenticate("username:password").
connectToServer("email-server:443")
action("my email")
}
type emailAction func(payload string)
func (a emailAction) connectToServer(server string) emailAction {
return func(payload string) {
fmt.Printf("connecting to server: %v\n", server)
a(payload)
}
}
func (a emailAction) authenticate(cred string) emailAction {
return func(payload string) {
fmt.Printf("authenticating with cred: %v\n", cred)
a(payload)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment