Thursday, September 08, 2016

Getting Started on Heroku with Go

  1. Created a heroku account.
  2. Installed heroku toolbelt.
  3. Logged in to heroku using the CLI and clone the app locally.

rwatsh@Watshs-MBP ~ heroku login
heroku-cli: Installing CLI... 19.73MB/19.73MB
Enter your Heroku credentials.
Email: watsh.rajneesh@sjsu.edu
Password (typing will be hidden):
Logged in as watsh.rajneesh@sjsu.edu
 rwatsh@Watshs-MBP ~
rwatsh@Watshs-MBP ~ export GOPATH=~/files/git/go
rwatsh@Watshs-MBP ~ go get github.com/heroku/go-getting-started/cmd/...
rwatsh@Watshs-MBP ~/files/git/go cd $GOPATH/src/github.com/heroku/go-getting-started


  1. Deploy the app.

rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master heroku create
Heroku CLI submits usage information back to Heroku. If you would like to disable this, set `skip_analytics: true` in /Users/rwatsh/.heroku/config.json
Creating app... done, safe-plains-74038
https://safe-plains-74038.herokuapp.com/ | https://git.heroku.com/safe-plains-74038.git
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master git push heroku master
Counting objects: 367, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (234/234), done.
Writing objects: 100% (367/367), 206.63 KiB | 0 bytes/s, done.
Total 367 (delta 75), reused 367 (delta 75)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Go app detected
remote: -----> Checking Godeps/Godeps.json file.
remote: -----> Installing go1.6.2... done
remote: -----> Running: go install -v -tags heroku ./...
remote: github.com/heroku/go-getting-started/vendor/gopkg.in/bluesuncorp/validator.v5
remote: github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin/render
remote: github.com/heroku/go-getting-started/vendor/github.com/manucorporat/sse
remote: github.com/heroku/go-getting-started/vendor/github.com/mattn/go-colorable
remote: github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin/binding
remote: github.com/heroku/go-getting-started/vendor/golang.org/x/net/context
remote: github.com/heroku/go-getting-started/vendor/github.com/mattn/go-isatty
remote: github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin
remote: github.com/heroku/go-getting-started/cmd/go-getting-started
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 3.1M
remote: -----> Launching...
remote:        Released v3
remote:        https://safe-plains-74038.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/safe-plains-74038.git
 * [new branch]      master -> master
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master

  1. 5.App gets deployed at - https://safe-plains-74038.herokuapp.com/ url.
  2. 6The app uses the following procfile (a configuration file specific to Heroku) with the following contents, where, web = process type which tells heroku to associate a web listener with the app.

web: go-getting-started


  1. 7The go app runs in a dyno = a heroku container which executes all commands specified in Procfile. A Free dyno goes to sleep after 30 mins of inactivity and a web request will wake it up (there is a delay due to this). A free dyno can be active no more than 18 hrs a day.

heroku ps
Free quota left: 17h 53m
=== web (Free): go-getting-started (1)
web.1: up 2016/05/11 17:04:54 -0700 (~ 6m ago)

  1. 8.There is a Godeps.json which defines the dependency and is how heroku knows the app is a Go app. This app is dependent on Gin, a Http framework.
  2. 9The app can be run locally as: heroku local web
  3. 10.  Create a new route /mark, test locally and then push the changes to heroku.

rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master go get -u github.com/tools/godep
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master godep restore
zsh: command not found: godep
  rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master export PATH=$GOPATH/bin:$PATH
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master godep restore
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master go get -u github.com/russross/blackfriday
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master ls
Godeps    Procfile  README.md app.json  cmd       static    templates vendor
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master vi cmd/go-getting-started/main.go
  rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master ● godep save ./...
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master ● go install ./...
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master ● heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
9:32:09 PM web.1 |  [GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
9:32:09 PM web.1 |   - using env:            export GIN_MODE=release
9:32:09 PM web.1 |   - using code:          gin.SetMode(gin.ReleaseMode)
9:32:09 PM web.1 |  [GIN-debug] GET   /static/*filepath         --> github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (2 handlers)
9:32:09 PM web.1 |  [GIN-debug] HEAD  /static/*filepath         --> github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (2 handlers)
9:32:09 PM web.1 |  [GIN-debug] GET   /                         --> main.main.func1 (2 handlers)
9:32:09 PM web.1 |  [GIN-debug] GET   /mark                     --> main.main.func2 (2 handlers)
9:32:09 PM web.1 |  [GIN-debug] Listening and serving HTTP on :5000
9:32:25 PM web.1 |  [GIN] 2016/05/11 - 21:32:25 | 200 |       85.55µs | [::1]:58944 |   GET     /mark
9:32:25 PM web.1 |  [GIN] 2016/05/11 - 21:32:25 | 404 |          36ns | [::1]:58944 |   GET     /favicon.ico
^C[WARN] Interrupted by User
[DONE] Killing all processes with signal  SIGINT
9:32:46 PM web.1 Exited with exit code null
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master ● git add -A .
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master git commit -m "Markdown demo dependency"
[master 60e5bb8] Markdown demo dependency
 16 files changed, 5612 insertions(+)
 create mode 100644 vendor/github.com/russross/blackfriday/.gitignore
 create mode 100644 vendor/github.com/russross/blackfriday/.travis.yml
 create mode 100644 vendor/github.com/russross/blackfriday/LICENSE.txt
 create mode 100644 vendor/github.com/russross/blackfriday/README.md
 create mode 100644 vendor/github.com/russross/blackfriday/block.go
 create mode 100644 vendor/github.com/russross/blackfriday/html.go
 create mode 100644 vendor/github.com/russross/blackfriday/inline.go
 create mode 100644 vendor/github.com/russross/blackfriday/latex.go
 create mode 100644 vendor/github.com/russross/blackfriday/markdown.go
 create mode 100644 vendor/github.com/russross/blackfriday/smartypants.go
 create mode 100644 vendor/github.com/shurcooL/sanitized_anchor_name/.travis.yml
 create mode 100644 vendor/github.com/shurcooL/sanitized_anchor_name/LICENSE
 create mode 100644 vendor/github.com/shurcooL/sanitized_anchor_name/README.md
 create mode 100644 vendor/github.com/shurcooL/sanitized_anchor_name/main.go
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master   git push heroku master
Counting objects: 27, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (27/27), 41.26 KiB | 0 bytes/s, done.
Total 27 (delta 3), reused 11 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Using set buildpack heroku/go
remote: -----> Go app detected
remote: -----> Checking Godeps/Godeps.json file.
remote: -----> Using go1.6.2
remote: -----> Running: go install -v -tags heroku ./...
remote: github.com/heroku/go-getting-started/vendor/gopkg.in/bluesuncorp/validator.v5
remote: github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin/render
remote: github.com/heroku/go-getting-started/vendor/github.com/manucorporat/sse
remote: github.com/heroku/go-getting-started/vendor/github.com/mattn/go-colorable
remote: github.com/heroku/go-getting-started/vendor/golang.org/x/net/context
remote: github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin/binding
remote: github.com/heroku/go-getting-started/vendor/github.com/shurcooL/sanitized_anchor_name
remote: github.com/heroku/go-getting-started/vendor/github.com/russross/blackfriday
remote: github.com/heroku/go-getting-started/vendor/github.com/gin-gonic/gin
remote: github.com/heroku/go-getting-started/vendor/github.com/mattn/go-isatty
remote: github.com/heroku/go-getting-started/cmd/go-getting-started
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 3.2M
remote: -----> Launching...
remote:        Released v4
remote:        https://safe-plains-74038.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/safe-plains-74038.git
   80d6840..60e5bb8  master -> master
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master heroku open mark
 rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master

  1. 11.  Provision papertrail logging add-on: - this did not work for free account!!

rwatsh@Watshs-MBP ~/files/git/go/src/github.com/heroku/go-getting-started master heroku addons:create papertrail
 !    Please verify your account to install this add-on plan (please enter a credit card) For more information, see https://devcenter.heroku.com/categories/billing Verify now at https://heroku.com/verify

  1. 12.  The deployed app with the new route can be seen at:


On browsing to the above link we can see the text displayed in the browser:
        hi!


References:

No comments:

Popular micro services patterns

Here are some popular Microservice design patterns that a programmer should know: Service Registry  pattern provides a  central location  fo...