いつもお世話になります。macでhomebrewでgoの1.9をインストールしました。
その後、goのpathを以下のように設定しました。
~/.bash_profile
export GOROOT=/usr/local/opt/go/libexec export GOPATH=$HOME export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
goのpackageをインストールしました。
get -u github.com/gorilla/mux
以下のソースを実行しようと考えています。
package main import ( "fmt" "net/http" "log" "encoding/json" "github.com/gorilla/mux" ) // 単純な構造体 type Data1 struct { Title string `json:"title"` Message string `json:"message"` Status int `json:"status"` } func main(){ // ルーティング router := mux.NewRouter() // URL別設定 router.HandleFunc("/sample1", func(w http.ResponseWriter, r *http.Request){ // 構造体を定義 var data1 = Data1{} data1.Title = "sample1" data1.Message = "hello, sample1" data1.Status = 100 // jsonエンコード outputJson, err := json.Marshal(&data1) if err != nil { panic(err) } // jsonヘッダーを出力 w.Header().Set("Content-Type", "application/json") // jsonデータを出力 fmt.Fprint(w, string(outputJson)) // log log.Print(r.URL.Path) }) // ハンドル割当 http.Handle("/", router) // log log.Print("localhost:9000") // ポート http.ListenAndServe(":9000", nil) }
eclipse上でbuildでしましたが、以下のエラーが発生しました。
ただ、このソースがあるところで、
go build ./json_output.go
go run json_outpug.go
は実行できました。
ここで質問です。どうしてbuildができないのでしょうか。ご教授をお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/21 12:49