Chapter 11th "Go Web Development Revel+mgo" deployed to Heroku

Source: Internet
Author: User
Tags heroku toolbelt

Demo Address http://gblog-revel.herokuapp.com/
1. Application MONGOHQ about how to register Heroku and MONGOHQ account, I have in the previous blog inside the description, http://blog.csdn.net/joveth/article/details/19999535 here simply say , do you remember the line that was annotated in the Newdao method in our Models/dao.go file?
Session, Err: = MgO. Dial ("Mongodb://omind:[email protected]:10000/ominds")

Yes, this is the free DB service we apply for in MONGOHQ, which is very useful (albeit slow in response). This is MONGOHQ's registered address: Https://bridge.mongohq.com/signup (this site is very card, we have to be patient to use it, you know, the wall or something ...) After registering, select a free database type and give the database a name, see:

In the figure, the Red box section, for the two free to enter and optional, is created and then enters the following layout:


First, we need to add a user to the database. Click Admin in the Red box and click Users to access the user Management page. Fill in the user name and password at username and password respectively:

Db.adduser (' Omind ', ' jov.omind ')

Click Add User.

So our DB warehouse has been built, how to use it? Please see:


The URI in the red box is for the content we want to use, and the user and password are replaced by the users just added. (The contents of the black box above are linked to the MONGOHQ via the console, if it is a Windows environment, switch to the Mongodb/bin directory to use the remote db)
Replace the string in your code with your own URI and open the comment for this code to comment out the local session.
Good.
2. Application Herokuheroku is also a free service that provides us with a demo. Of course, an account can only have 5 apps, I can only say oh oh.
Registered Address: https://www.heroku.com/

Below we need to install Heroku toolbelt:https://toolbelt.heroku.com/.

Note: If you have Git installed on your PC, choose Custom Installation and remove the option to install git when you install it, or choose Full installation.

After the installation is successful, open Git Bash, enter heroku login , and enter the account number and password to sign in Heroku. Git detects if there is an SSH key, if so, uses the key and uploads it, and if not, creates a key and uploads it. (You can also use the Heroku keys command to see if there is a keys, if not, you can use Heroku Add:keys add keys)

In the root directory of the project, create a new. godir file, such as my gblog/.godir add content:

Gblog

Yes, that's the name of your project.

Open Git Bash, switch to your project directory below (Windows environment, if you want to switch disk using CD E: command), enter:




Yes, the above command is for us to deploy an application on Herokuapp, for which the buildpack can be referenced here: Https://github.com/robfig/heroku-buildpack-go-revel ( Say this builpack has many versions, finally only this eldest brother can do normal use, eldest brother .... Class Nunam noodles AH)
However, after the deployment is complete, in the browser access, found unexpectedly error, what reason, this is the blogger and the struggle of the day of the bug Ah, finally in the patient was erased before the solution, or really want to vomit, remember we in the latest blog reminder when (the 9th chapter of the blog), There is a piece of code in header.html:
{{if. recentcnt}}                {{if GT. recentcnt 0}}                <span class= "Navbar-news" title= "last 1 hours {{. recentcnt}} Update" >{{.recentCnt}}</span> {{                end}} {{                End}}

One of the IF GT is Revel self-contained template method, your sister Ah, I also think you bring the things, will certainly pack compiled into put, didn't think Ah, this reason wasted my day time (according to the Code a section to check, did not think the header will have problems), then how to solve it, You can do it by yourself.
In the Init.go method, join as before:
Revel. templatefuncs["GT"] = func (A, b int) bool {return a>b}

Well, we submit at the time:
git Add. Git commit-m "update" Git push Heroku Master

Open it again this time, finally good.
Then some classmates may say, ah, it gave us the name of the creation is very lame, I want to change one, how to do? You can log in to Heroku's website, find your app, and then change the name in the setting inside (in other words, after modifying the name, my app has changed, again submit not, how to do, delete the retransmission, and then modify the name. )
Demo Address http://gblog-revel.herokuapp.com/
Baidu statistics what to do OH
At this point, but the regret in my heart, more comfortable ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.