Posts

Showing posts with the label go-templates

Golang template generate array of strings

Image
Clash Royale CLAN TAG #URR8PPP Golang template generate array of strings I want to generate the following app1 && app2 && app3 app1 && app2 && app3 My template look like following {{- range ExeApp .}} {{ .Command }} {{- end}} My code looks like following with command which is array of strings type App struct { Data string Command string } func ExeApp(m models) App { switch m.Type { case “apps": return App{ {"# running apps", string{“app1", “app2", “app3"}}, } … Currently its generated like [app1 app2 app3] And I need it like app1 && app2 && app3 , app1 && app2 && app3 I try to play with the template by adding && before the .Command which doesn’t help and in addition I don’t know how to remove the array before and after the apps, any idea what I’m doing wrong here ? By c...

Golang HTML/template return 404 file not found

Image
Clash Royale CLAN TAG #URR8PPP Golang HTML/template return 404 file not found I'm trying to render home.html on port 8080. server.go package main import ( "html/template" "net/http" ) var homeT = template.Must(template.ParseFiles("exhibit-b/home.html")) func home(w http.ResponseWriter, r *http.Request) { homeT.Execute(w, nil) } func main() { http.HandleFunc("/home", home) http.ListenAndServe(":8080", nil) } home.html <!DOCTYPE html> <html> <title>Learning Go</title> <body> <h1>Yes I understand!</h1> <h2>... and I would like to do something more interesting</h2> </body> </html> But when I run the above code go run server.go the server starts but when I go to localhost:8080 I just see 404 error go run server.go By clicking "Post Your Answer", you acknowledge that y...