Skip to content

Instantly share code, notes, and snippets.

@ykyuen
Created April 18, 2019 09:32
Show Gist options
  • Select an option

  • Save ykyuen/d6dbdc3caaa639d969834a62bd04ad4a to your computer and use it in GitHub Desktop.

Select an option

Save ykyuen/d6dbdc3caaa639d969834a62bd04ad4a to your computer and use it in GitHub Desktop.

Revisions

  1. ykyuen created this gist Apr 18, 2019.
    25 changes: 25 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    ...
    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"))
    }