Help us understand the problem. What is going on with this article?

gbを知ったのでgojiを使ったWEBアプリケーションプロジェクトを管理してみた

More than 3 years have passed since last update.

インストールpackage

$ go get github.com/constabulary/gb/...

プロジェクトディレクトリ

$ mkdir project

ソース置き場

$ mkdir project/src

demo packageディレクトリ

$ mkdir project/src/demo

サンプルコード

$ cat src/demo/main.go
package main                                            
import (                                                      
        "fmt"                                                 
        "net/http"                                            

        "github.com/zenazn/goji"                              
        "github.com/zenazn/goji/web"                          
)                                                             
func hello(c web.C, w http.ResponseWriter, r *http.Request) { 
        fmt.Fprintf(w, "Hello, %s!", c.URLParams["name"])     
}                                                                                                                        
func main() {                                                 
        goji.Get("/hello/:name", hello)                       
        goji.Serve()                                          
}                                                             

Gojiを使うために必要なパッケージをgbで取得

gb vendor fetchを使います

$ gb vendor fetch github.com/zenazn/goji
$ gb vendor fetch github.com/zenazn/goji/web

この時点でのディレクトリ構成は

~/code/demo-project $ tree -d .       
.                                     
├── bin                               
├── src                               
│   └── hello                         
└── vendor                            
    └── src                           
        └── github.com                
            └── zenazn                
                └── goji              
                    ├── bind          
                    ├── example       
                    ├── graceful      
                    │   └── listener  
                    └── web           
                        ├── middleware
                        └── mutil     

vendor/src ができてた

fetch済みvendor一覧を見る

~/code/demo-project $ gb vendor list                                                                                    
github.com/zenazn/goji  https://github.com/zenazn/goji  master  d198bcf1ddf7d69872b506da7d4c4862121a9d8a                
github.com/zenazn/goji/web      https://github.com/zenazn/goji/web      master  d198bcf1ddf7d69872b506da7d4c4862121a9d8a

パスとURLとリビジョン値

ビルドしてみます

$ gb build
github.com/zenazn/goji/bind              
github.com/zenazn/goji/graceful/listener 
github.com/zenazn/goji/web               
github.com/zenazn/goji/web/mutil         
github.com/zenazn/goji/graceful          
github.com/zenazn/goji/web/middleware    
github.com/zenazn/goji                   
hello                                    

今はhelloというpackageしか存在しないので

bin/     
└── hello

こんな感じになりました

実際に実行できるの?やってみた

$ ./bin/hello
2015/06/21 20:57:16.251830 Starting Goji on [::]:8000

立ち上がったようだ

http://localhost:8000/hello/golang

で確認できるみたいなのでためしてやろうでは無いか!

$ curl http://localhost:8000/hello/golang
Hello, golang!

うむ、お前に今後まかせるとしよう

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away