Skip to content

Instantly share code, notes, and snippets.

@ykyuen
Created April 8, 2019 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykyuen/3de16893eba858963180d511f8440631 to your computer and use it in GitHub Desktop.
Save ykyuen/3de16893eba858963180d511f8440631 to your computer and use it in GitHub Desktop.
handling-http-request-in-go-echo-framework-1-03
...
func main() {
// Echo instance
e := echo.New()
// Instantiate a template registry with an array of template set
// Ref: https://gist.github.com/rand99/808e6e9702c00ce64803d94abff65678
templates := make(map[string]*template.Template)
templates["home.html"] = template.Must(template.ParseFiles("view/home.html", "view/base.html"))
templates["about.html"] = template.Must(template.ParseFiles("view/about.html", "view/base.html"))
e.Renderer = &TemplateRegistry{
templates: templates,
}
// Route => handler
e.GET("/", handler.HomeHandler)
e.GET("/about", handler.AboutHandler)
// Route => api
e.GET("/api/get-full-name", api.GetFullName)
// Start the Echo server
e.Logger.Fatal(e.Start(":1323"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment