Releases: DehuaZhao/go-web-go
Releases · DehuaZhao/go-web-go
Step-9 Validation
- Use
regexp
package and create the global variablevalidPath
to store our validation expression. - Add the function
getTitle
that uses thevalidPath
expression to validate path and extract the page title. - Put a call to
getTitle
in each of the handlers.
Step-8 Template Caching
- Refactor to call
ParseFiles
once at program initialization, parsing all templates into a single*Template
. - Create the global variable named
templates
, and initialize it withParseFiles
. - Modify the
renderTemplate
function to call thetemplates.ExecuteTemplate
method with the name of the appropriate template.
Step-7 More Error Handling
- Handle errors in
renderTemplate
. - Handle errors in
saveTemplate
.
Step-6 Saving Pages
- Implement the
saveHandler
and uncommenting the related line inmain
.
Step-5 Refactor
- Move all templating code to its own function.
- Handle non-existent pages in
viewHandler
.
Step-4 Better HTML
- Use
html/template
to keep the HTML in a separate file. - Keep hard-coded HTMLs in separate files.
Step-3 Editing Pages
- Add the
editHandler
Step-2 Serve Pages
- 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
- 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
inmain
. - Remove the calls to
getTitle
from the handler functions, making them much simpler.
Step-1 Error Handling
- Modify the
loadPage
to let it return an error ifReadFile
encounters one.