Created
March 29, 2021 01:26
-
-
Save krishbhanushali/5cc971e67442001232985de7d00ca66e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
| "text/template" | |
| "os" | |
| "log" | |
| "strings" | |
| ) | |
| type Paragraph struct { | |
| Title string | |
| UpperCaseSentence string | |
| LowerCaseSentence string | |
| } | |
| func main() { | |
| funcMap := template.FuncMap{ | |
| "ToUpper": strings.ToUpper, | |
| "ToLower": strings.ToLower, | |
| "ToTitle": strings.Title, | |
| } | |
| const sample = ` | |
| {{.Title | ToTitle}} | |
| {{.UpperCaseSentence | ToUpper}} | |
| {{.LowerCaseSentence | ToLower}} | |
| ` | |
| t := template.Must(template.New("sampleTest").Funcs(funcMap).Parse(sample)) | |
| p := Paragraph{ | |
| Title: "this is a title", | |
| UpperCaseSentence: "this is an upper case sentence", | |
| LowerCaseSentence: "THIS IS A LOWER CASE SENTENCE", | |
| } | |
| err := t.Execute(os.Stdout, p) | |
| if err != nil { | |
| log.Println(err.Error()) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment