22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

インストール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!

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

22
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?