Created
October 23, 2020 23:07
-
-
Save namp10010/83820a59dc8d419e1aed49d343ee82b2 to your computer and use it in GitHub Desktop.
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 main | |
import "fmt" | |
func main() { | |
myEmail := &Email{} | |
myEmail.withFrom("sender"). | |
withTo("recipient"). | |
withSubject("hello"). | |
withBody("howdy?") | |
fmt.Println("my email: ", *myEmail) | |
} | |
type Email struct { | |
from string | |
to string | |
subject string | |
body string | |
} | |
func (e *Email) withFrom(fr string) *Email { | |
e.from = fr | |
return e | |
} | |
func (e *Email) withTo(to string) *Email { | |
e.to = to | |
return e | |
} | |
func (e *Email) withSubject(s string) *Email { | |
e.subject = s | |
return e | |
} | |
func (e *Email) withBody(b string) *Email { | |
e.body = b | |
return e | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment