visual studio codeのインストール(Ruby on Rails 開発甩)
rails の勉強してます。
そろそろIDEが欲しかったので、探した所RubyMineがよさげだったのですが有料のため代替を探したところVisual Studio Codeというのがあったので使うこととした。
Visual Studio Code - Microsoft
Microsoft製品ですが無料。
Visual Studio Code - Visual Studio
Mac版インストールして起動。以上
go言語でシンプルなwebサーバーとテンプレートを使うところまで
続き。
フォルダ構成
chat templates chat.html main.go
main.go
package main import ( "net/http" "log" "sync" "html/template" "path/filepath" ) type templateHandler struct { once sync.Once filename string templ *template.Template } // ServeHTTPはHTTPリクエストを処理 func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { t.once.Do(func() { t.templ = template.Must(template.ParseFiles(filepath.Join("templates", t.filename))) t.templ.Execute(w, nil) }) } func main() { // htmlベタ書きするとき //http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // w.Write([]byte("htmlコード")) //}) http.Handle("/",&templateHandler{filename:"chat.html"}) if err := http.ListenAndServe(":8080", nil); err != nil { log.Fatal("ListenAndServe", err) } }
chat.html
<html> <body> チャットしましょう!(テンプレートより) </body> </html>
起動して
http://localhost:8080 で確認。
おわり。
haruproject.hateblo.jp
haruproject.hateblo.jp
haruproject.hateblo.jp
go言語の開発環境をIntelliJ IDEA 15でつくる
続き
IntelliJ IDEAをダウンロードしにいく
www.jetbrains.com
Ultimateをダウンロード※ライセンスがあるので
いつものように配置
GO SDKのインストールは以下の手順
インストールが終わったらIDEAを再起動する。
動作確認。サンプルコードをこんな感じで用意
main.go
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
こんな感じで実行
コンソールに出力される
おわり
go言語でnet/httpでWEBサーバをたてる
続き。
routetest.go
package main import ( "fmt" "log" "net/http" ) func hello(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World!") } func main() { http.HandleFunc("/", hello) err := http.ListenAndServe(":9090", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } }
$ go run routetest.go
http://localhost:9090/helloでアクセス
終わり。
go言語でhello worldを"go fmt"してみる
続き。
before
hello.go
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
hello.goがあるフォルダで。
$ go fmt
after
hello.go
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
コードが整形される。以上。