Created
April 18, 2019 09:32
-
-
Save ykyuen/d6dbdc3caaa639d969834a62bd04ad4a to your computer and use it in GitHub Desktop.
handling-http-request-in-go-echo-framework-2-02
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
... | |
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) | |
e.POST("/api/post-full-name", api.PostFullName) | |
// 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