Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Zh.javascript.info | 8,013 | 2 days ago | 6 | other | HTML | |||||
现代 JavaScript 教程(The Modern JavaScript Tutorial) | ||||||||||
Rails_apps_composer | 1,439 | 8 | 1 | 5 years ago | 254 | September 23, 2018 | 53 | Ruby | ||
A gem with recipes to create Rails application templates for Rails starter apps. | ||||||||||
Tinyraycaster | 1,233 | 4 years ago | 1 | wtfpl | C++ | |||||
486 lines of C++: old-school FPS in a weekend | ||||||||||
Blcmods | 715 | 8 days ago | 1 | other | Python | |||||
This is a repository for Community Mods made for the Borderlands series | ||||||||||
Coffeescript Cookbook.github.io | 572 | 3 years ago | 10 | other | CSS | |||||
CoffeeScript Recipes, Examples and Tutorials | ||||||||||
Orchid | 481 | 1 | 16 | 3 days ago | 22 | October 27, 2017 | 40 | gpl-3.0 | Kotlin | |
Build and deploy beautiful documentation sites that grow with you | ||||||||||
Androidageratutorial | 392 | 6 years ago | apache-2.0 | Java | ||||||
Android Agera Example | ||||||||||
Apriltag_ros | 279 | 4 days ago | 21 | other | C++ | |||||
A ROS wrapper of the AprilTag 3 visual fiducial detector | ||||||||||
Full Fledged Hledger | 253 | 6 months ago | 1 | bsd-3-clause | Haskell | |||||
Tutorial on Hledger setup with multi-year files, multi-source imports and a range of auto-generated reports | ||||||||||
Oppia Android | 229 | 13 hours ago | 534 | apache-2.0 | Kotlin | |||||
A free, online & offline learning platform to make quality education accessible for all. |
A Golang Wiki Page Tutorial Web Application
This Application takes a Go leaner through the process of building a web application using package net/http
and html/template
from Go standard library.
This is a stepping coding instructor to a tutorial article by golang.org. Each tagged commit is a separate teaching towards a very simple web app.
net/http
package to build web applicationshtml/template
package to process HTML templatesregexp
package to validate user inputYou can check out any point of the tutorial using:
$ git checkout step-?
To see the changes made between any two lessons use the git diff command:
$ git diff step-?..step-?
Page struct
.save
and loadPage
function.main
function to test what we've written.loadPage
to let it return an error if ReadFile
encounters one.You can compile and run the program like this:
$ go build gowiki.go
$ ./gowiki
This is a sample page.
net/http
package to serve our wiki pages.viewHandler
to handle URLs.Let's compile, run our code and visit http://localhost:8080/view/test to see what we have by far.
editHandler
.Now we have an editing page http://localhost:8080/edit/test.
As you might have noticed, we comment out the registration of saveHandler
in main
. We will come back on that later.
html/template
to keep the HTML in a separate file.In this step, we will not be adding any new functionality to our application. Instead, we are going to take a step back, refactor our codebase and fix a potential issue.
viewHandler
.Recompile the code, run and visit http://localhost:8080/view/APageThatDoesntExist
saveHandler
and uncommenting the related line in main
.renderTemplate
.saveTemplate
.ParseFiles
once at program initialization, parsing all templates into a single *Template
.templates
, and initialize it with ParseFiles
.renderTemplate
function to call the templates.ExecuteTemplate
method with the name of the appropriate template.regexp
package and create the global variable validPath
to store our validation expression.getTitle
that uses the validPath
expression to validate path and extract the page title.getTitle
in each of the handlers.http.HandlerFunc
.makeHandler
in main
.getTitle
from the handler functions, making them much simpler.Now we have finished our little wiki page application. Recompile the code, and run the app:
$ go build gowiki.go
$ ./gowiki
Visiting http://localhost:8080/view/ANewPage should present you with the page edit form. You should then be able to enter some text, click 'Save', and be redirected to the newly created page.
In the article there are some simple tasks left for readers:
tmpl/
and page data in data/
./view/FrontPage
.[PageName]
to
<a href="/view/PageName">PageName</a>
. (hint: you could use regexp.ReplaceAllFunc
to do this)And we will continue Go with these extra tasks.
tmpl/
and page data in data/
.save()
, loadPage()
and templates
.