2014-11-26

How to start Martini Golang Project

Martini is another Golang web framework, that the design similar to Sinatra, to install it, just type this command:

go get -u -v github.com/go-martini/martini

Then, just create new source code, for example main.go:

package main
import "github.com/go-martini/martini"
func main() {
  m := martini.Classic()
  m.Get("/", func() string {
    return "Hello world!"
  })
  m.Run()
}

To run the website, just type:

go run main.go

Then visit http://localhost:3000/

We must recompile the source everytime the source code changed, that quite annoying and time consuming, to overcome that problem we could use a tool called gin, this program automatically run a program everytime there are code changed. To install this tool, type:

go get -u -v github.com/codegangsta/gin

Then run it using this command:

gin go run main.go

That command would create a proxy, if there are compilation errors, it would also show on the page.

No comments :

Post a Comment

THINK: is it True? is it Helpful? is it Inspiring? is it Necessary? is it Kind?