Herokuããããããããããªãï¼
ã²ããã¶ãã«æ¸ãã¦ã¾ãã
æè¿ã¯Google App EngineãiPhone/Androidã¢ããªã«ãã¤ã¤ãæããã¦ãã¦ãRubyé¢é£æ
å ±ãå
¨ããã£ããã¢ããã§ãã¦ãã¾ããã§ããã
ããããããHerokuã天ä¸ãã¨ãããããªããã¨æãããã調æ»ãå§ãã¾ããã
調ã¹ã¦ãããã¡ã«ç¥ããªãã¯ã¼ããããããã§ã¦ãã¦ããã¯ãªã
ã²ã¨ã¾ãæ°ã«ãªããã®
- Bundler
- rubygemsã¨ã¡ããã®ï¼
- Padrino
- Sinatraã¨Railsã®ä¸éãããã®è¦æ¨¡ã®ãã¬ã¼ã ã¯ã¼ã¯ããããé¢ç½ãã
ãããã調ã¹ã¤ã¤Twitterã®BOTã§ãæ¸ãã¦ã¿ã¦ãªãããªãã¦ã¿ãã
Goã§ã¤ãã¬ã¼ã¿
goroutineã¨channelã¨rangeã¤ããã°å·§ãäºãã£ã¦ããã¾ããã
package main import ( "log"; "time"; ) func FibIter(n int) chan uint64 { ch := make(chan uint64); go func() { var a, b uint64 = 0, 1; for i := 0; i < n; i++ { ch <- a; a, b = b, a + b; } close(ch); }(); return ch; } func main() { for i := range FibIter(50) { log.Stdout(i); time.Sleep(1e8); } }
Goã§ãµã¼ãã¼å®è£ ã®ãã¿ã¼ã³
Goè¨èªããããããã
Goã§ã®ãµã¼ãã¼å®è£
ã®æ¹æ³ããããç¨åº¦ãã¿ã¼ã³åãã¦ãã®ã§è¦ãã¦ãããã
ããã§è¨ããµã¼ãã¼ã¯ã¨ã³ã¼ãµã¼ãã¼ãmemcachedã¿ãããªãã¤ãã¹
package main import ( "net"; "fmt"; ) func handler(conn net.Conn) { defer conn.Close(); // 4 buf := make([]byte, 16); l, err := conn.Read(buf); if err == nil { conn.Write(buf[0:l]); } } func main() { sock, err := net.Listen("tcp", "127.0.0.1:1983"); if err != nil { fmt.Printf("error %s", err); return; } // 1 for { // 2 conn, err := sock.Accept(); if err != nil { fmt.Printf("error %s", err); return; } // 3 go handler(conn); } }
1ã§ã«ã¼ããã2ã§Acceptãããã¦3ã§ã³ãã¯ã·ã§ã³ãgoroutineã§åãããhandlerã«æ¸¡ãã
æå¾ã«ãã¸ãã¯ã4ã«æ¸ãã°åºæ¥ä¸ããã
ã¯ã©ã¤ã¢ã³ããåãããã«ããããã ãªã¼ãã®ãããªã¼
åè
GitHub - dustin/gomemcached: A memcached binary protocol toolkit for go.
GO
GOã®ä»æ§ãç´ æµã ãªãã
Dè¨èªã£ã½ããæããã®ã¯åã ãã ãããã
ã¤ãã
ã¡ãã£ã¨åã«ã¯httpã®testã«ããã¦ããã©releaseå¤ãã¦cloneãã¦ã¿ããtestéã£ã
hg clone https://go.googlecode.com/hg/ $GOROOT
追è¨ã®è¿½è¨
Makeã®ä»çµã¿ãç¨æããã¦ã¦å¬ããã£ããGOFILES並ã¹ãã ãã
include $(GOROOT)/src/Make.$(GOARCH) TARG=hello GOFILES=\ hello.go include $(GOROOT)/src/Make.cmd
httpã¤ãã£ã¦ã¿ã
package main import ( "fmt"; "http"; ) func main() { if res, _, err := http.Get("http://www.google.com/"); err == nil { for key, value := range res.Header { fmt.Printf("%s: %s\n", key, value); } } }
ãããã
goroutine使ã£ã¦ã¿ã
package main import ( "fmt"; "time"; ) func generate(ch chan string) { for i := 0; ; i++ { ch <- fmt.Sprintf("hogehogeurl%d", i); } } func download(in, out chan string) { for { prime := <-in; fmt.Printf("download: %s\n", prime); out <- "ok"; time.Sleep(1 * 1e9); } } func main() { in := make(chan string); out := make(chan string); go generate(in); for i := 0; i < 3; i++ { go download(in, out); } for i := 0; i < 20; i++ { <-out; } }
ããã¯æ¥½ãã
ãã
ããããæ¸ããããã¨ãããã©æ¸ãã¦ãªããªã¼
ãã¤ãæ¸ãããã®ã¡ã¢
ã»C,C++ãã¿
ãæè¿ã¯CãC++ãã¡ã¤ã³ã§ä½¿ã£ã¦ãã®ã§
ã»ç»åå¦çãã¿
ãé«éã«ç¶ºéºãªãµã ãã¤ã«ãã¤ããCã©ã¤ãã©ãªãæ¸ãã
ã»Python+GAEãã¿
ãWebãµã¼ãã¹ä½ãã¯ä»å¾GAEã§ããäºå®
Snow Leopardããã
ãªã«ãã¨ä¸ä¾¿ãªãã¨ãå¤ãã£ãããLeopardã«æ»ãã
Sinatra+æºå¸¯+çµµæå
ããã°ãæ¾ç½®ããããªã®ã§ç´¹ä»ãã¾ãã
ããå æ¸é£½ãã¦ããæãã®ããSinatraã§æºå¸¯ãµã¤ããéçºããã¨ãã®çµµæåExtensionã§ãã
èªãµã¤ãã§çµµæåã®ã¿ä½¿ãããã£ãã®ã§å®è£
ãã¾ããã
ç¾å¨ã¯åºæ¬çµµæåã®ã¿ï¼ãã¾ããã¹ããã¦ãªãã¨ããé©å½ä»æ§ã§ãã
rack-ketaiã使ããã°ããã§è¯ãã£ã¦è©±ãããã¾ãã
http://github.com/gioext/sinatra-emoji
使ãæ¹ã¯READMEãè¦ãã°æ¦ãåãããã¨æãã¾ãã念ã®ãããããã«ãè¼ãã¦ããã¾ãã
注æç¹ã¯é常ã®erb,hamlãç½®ãæãã¦ãæåã³ã¼ããå¤æãã¦ããã®ã§ãã®ã§ãå¤æãå¿
è¦ãªãå ´åã¯__erb__,__haml__ã使ãã¾ãããã
sudo gem install gioext-sinatra-emoji
require 'rubygems' require 'sinatra' require 'sinatra/emoji' get '/' do erb :index end helpers do # use __erb__ def partial(sym) __erb__ sym, :layout => false end end configure do # default set :output_encoding_sjis, true end __END__ @@ layout <html> <head><title>test</title></head> <body> <%= yield %> </body> </html> @@ index <%= emoji(0) %> <%= partial(:parts) %> @@parts <%= emoji(1) %> <br /> ã¯ãã¼
ããã¾ã