Skip to content

Releases: DehuaZhao/go-web-go

Step-9 Validation

18 Aug 14:52
Compare
Choose a tag to compare
  • Use regexp package and create the global variable validPath to store our validation expression.
  • Add the function getTitle that uses the validPath expression to validate path and extract the page title.
  • Put a call to getTitle in each of the handlers.

Step-8 Template Caching

18 Aug 14:51
Compare
Choose a tag to compare
  • Refactor to call ParseFiles once at program initialization, parsing all templates into a single *Template.
  • Create the global variable named templates, and initialize it with ParseFiles.
  • Modify the renderTemplate function to call the templates.ExecuteTemplate method with the name of the appropriate template.

Step-7 More Error Handling

18 Aug 14:51
Compare
Choose a tag to compare
  • Handle errors in renderTemplate.
  • Handle errors in saveTemplate.

Step-6 Saving Pages

18 Aug 14:40
Compare
Choose a tag to compare
  • Implement the saveHandler and uncommenting the related line in main.

Step-5 Refactor

18 Aug 14:33
Compare
Choose a tag to compare
  • Move all templating code to its own function.
  • Handle non-existent pages in viewHandler.

Step-4 Better HTML

18 Aug 14:22
Compare
Choose a tag to compare
  • Use html/template to keep the HTML in a separate file.
  • Keep hard-coded HTMLs in separate files.

Step-3 Editing Pages

18 Aug 14:20
Compare
Choose a tag to compare
  • Add the editHandler

Step-2 Serve Pages

18 Aug 14:16
Compare
Choose a tag to compare
  • Use net/http package to serve our wiki pages.
  • Add the viewHandler to handle URLs.
  • create some page data like test.txt

Step-10 Using Function Literals and Closures

18 Aug 15:02
Compare
Choose a tag to compare
  • Re-write the function definition of each of the handlers to accept a title string.
  • Define the wrapper function that takes a function of the above type, and returns a function of type http.HandlerFunc.
  • Wrap the handler functions with makeHandler in main.
  • Remove the calls to getTitle from the handler functions, making them much simpler.

Step-1 Error Handling

18 Aug 14:13
Compare
Choose a tag to compare
  • Modify the loadPage to let it return an error if ReadFile encounters one.