Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
GDG DevFest Kyoto 2014 
䝷䜲䝣 
䛣䜜䛛䜙䛾Go䛾ヰ䜢䛧䜘䛖 
䜏䜣䛺䛾 
GDG⚄ᡞ䚷㔝⏣ᝅᚿ
⮬ᕫ⤂௓䛳䛶኱஦䛰䜘䛽 
㔝⏣䛷䛩䚹 ௨ୖ
⎔ቃ 
OS 
䚷Ubuntu14.04 x64 (VMware Player 6) 
Go Version 
䚷1.3.3䚷(୍㒊1.2.2)
㛤Ⓨ⎔ቃ 䍦䚷Vim
୓䛸ゝ䜟䛪ி䛾୍䛾ᛕ䛾ᛕ䛾ᛕ䛾䛯䜑 
Vim䜲䞁䝇䝖䞊䝹 
䚷$ sudo apt-get install vim 
.profile䛻GOROOT䛸GOPATH䜢タᐃ 
䚷export GOROOT=/usr/local/go 
䚷expor...
୓䛸ゝ䜟䛪ி䛾୍䛾ᛕ䛾ᛕ䛾ᛕ䛾䛯䜑 
git䛸hg䝁䝬䞁䝗䛜౑䛘䜛䜘䛖䛻䜲䞁䝇䝖䞊䝹 
䚷$ sudo apt-get install git 
䚷$ sudo apt-get install mercurial 
Github䜔GoogleC...
gocode 
䜲䞁䝔䝸䝉䞁䝇䜢౑䛘䜛䜘䛖䛻䛺䜛 
䚷$ go get -u github.com/nsf/gocode 
Vim䛾ሙྜ䚸"."䛾ᚋ䛻<C-x><C-o>䛷⿵᏶䛥䜜䜛
go get䛩䜛䛸䚸GOPATH௨ୗ䛻bin䚸pkg䚸src䛜⮬ືⓗ䛻స䜙 
䜜䜛 
ᚲせ䛺䛔䝕䜱䝺䜽䝖䝸䛿స䜙䜜䛺䛔 
⮬ศ䛷సᡂ䛧䛯䝋䞊䝇䜢go install䛧䛶䝟䝑䜿䞊䝆䜢స䜛ሙྜ䚸 
GOPATH௨ୗ䛾src䛸ྠ㝵ᒙ䛻䛒䜛pkg䛻䝟䝑...
.vimrc (൅䛾䛿䛣䜣䛺ឤ䛨) 
filetype off 
filetype plugin off "indent off 
set runtimepath+=$GOROOT/misc/vim 
exe "set runtimepath+...
䜽䝻䝇䝁䞁䝟䜲䝹
᭱ึ䛻ᑐ㇟䛸䛺䜛䝥䝷䝑䝖䝣䜷䞊䝮䛾䜽䝻䝇䝁䞁䝟䜲䝹⎔ቃ䜢స 
ᡂ䛩䜛ᚲせ䛜䛒䜛 
GOOS䛻ᑐ㇟OS䚸GOARCH䛻ᑐ㇟䜰䞊䜻䝔䜽䝏䝱䜢ᣦᐃ 
䚷$ cd $GOROOT/src 
䚷$ sudo GOOS=windows GOARCH=amd...
GOOS䚸GOARCH䜢ᣦᐃ䛧䛶go build䛩䜛䛸䚸ᑐ㇟䝥䝷䝑䝖 
䝣䜷䞊䝮䛾ᐇ⾜䝣䜯䜲䝹䛜సᡂ䛥䜜䜛 
䚷$ GOOS=windows GOARCH=amd64 go build sample.go
SQL
SQL Driver 
SQL Driver䛾୍ぴ 
https://code.google.com/p/go-wiki/ 
source/browse/SQLDrivers.wiki?repo=wiki 
MyMySQL 
https://g...
MyMySQL䜢ྲྀ䛳䛶䛟䜛 
䚷$ go get github.com/ziutek/mymysql/thrsafe 
䚷$ go get github.com/ziutek/mymysql/autorc 
䚷$ go get github.c...
import䛻 
䚷_ "github.com/ziutek/mymysql/thrsafe" 
䜢ධ䜜䛶䛚䛟 
import ( 
"fmt" 
"github.com/ziutek/mymysql/mysql" 
_ "github.com...
┤᥋౑䛖䜟䛡䛨䜓䛺䛔䛡䛹䚸thrsafe.go䛾init㛵ᩘ䛜࿧䜀䜜䚸 
DB᥋⥆䛾‽ഛ䜢䛩䜛 
thrsafe䛿䝇䝺䝑䝗䝉䞊䝣䛺DB᥋⥆䛻䛺䜛 
_ "github.com/ziutek/mymysql/native" 
䜢thrsafe䛾௦...
DB᥋⥆᝟ሗ䜢సᡂ䛧䚸᥋⥆䛩䜛 
➨஧ᘬᩘ䛿䝻䞊䜹䝹䜰䝗䝺䝇䚹➨୕ᘬᩘ䛜䝃䞊䝞䜰䝗䝺䝇 
db := mysql.New("tcp", "", "127.0.0.1:3306", "sampleuser", 
"samplepw", "samp...
㐜ᘏᐇ⾜䛷DB䜢㛢䛨䜘䛖䛻䛧䛶䛚䛟 
defer func() { 
db.Close() 
}()
䜽䜶䝸䜢ᐇ⾜䛩䜛䛻䛿Query䜢౑䛖 
➨୍ᘬᩘ䛻䜽䜶䝸䚸➨஧ᘬᩘ䛻䝟䝷䝯䞊䝍(ྍኚ)䜢タᐃ䛩䜛 
sqlstr := "INSERT INTO sample_table (name) VALUES 
('test_%d')" 
db.Quer...
SELECTᩥ䛾ᐇ⾜⤖ᯝ䛾䝬䝑䝢䞁䜾 
sqlstr := "SELECT * FROM sample_table" 
rows, res, _ := db.Query(sqlstr) 
id := res.Map("id") 
name :=...
䝺䝁䞊䝗䛿䛣䜣䛺ឤ䛨䛷ぢ䜜䜛 
for _, row := range rows { 
// ⤖ᯝ䜢1⾜䛪䛴⾲♧䛩䜛 
fmt.Printf("| %d | %s |n", row.Int(id), row.Str(name)) 
}
䝖䝷䞁䝄䜽䝅䝵䞁䛿䛣䜣䛺ឤ䛨 
tr, err := db.Begin() 
sqlstr := "UPDATE sample_table SET name='test'" 
_, err = tr.Start(sqlstr) 
䝁䝭䝑䝖䛿tr...
OpenCV
OpenCV䜢䜲䞁䝇䝖䞊䝹 
䚷$ sudo apt-get install ocl-icd-libopencl1 
䚷$ sudo apt-get install libopencv-dev 
1䛴┠䛾䜢䜲䞁䝇䝖䞊䝹䛧䛺䛔䛸䚸ḟᅇ䝻䜾䜲䞁᫬䛻...
OpenCV䛜౑䛘䜛䜘䛖䛻䛩䜛(䝞䜲䞁䝕䜱䞁䜾䛧䛶䛟䜜䜛) 
䚷$ go get github.com/lazywei/go-opencv 
$GOPATH/src/github.com/lazywei/go-opencv/samples 
䛻...
Demo
Gobot
Gobot 
http://gobot.io/ 
Arduino䜔Sphero(2.0)䚸ARDrone䛺䛹11䛾䝥䝷䝑䝖䝣䜷䞊䝮䛻 
ᑐᛂ 
௒ᅇ䛿Arduino(Arduino UNO R3)䛷LED䜢ග䜙䛫䜛䜘
Firmata 
Firmata(䝣䜵䝹䝬䞊䝍)䛸䛔䛖䝥䝻䝖䝁䝹䜢౑䛖 
䜎䛪䛿Arduino UNO R3䛻Firmata䜢᭩䛝㎸䜐 
Arduino UNO R3䜢᥋⥆䛧䚸ArduinoIDE䛛䜙䚸 
File -> Examples ->...
Gobot䜢ྲྀ䛳䛶䛝䛶䚸ྛ䝟䝑䜿䞊䝆䜢⏝ព䛩䜛 
䚷$ go get -u github.com/hybridgroup/gobot 
䚷$ go install github.com/hybridgroup/gobot/platforms/f...
gobot/examples䛾ୗ䛾firmata_blink.go 
䝫䞊䝖␒ྕ䛺䛹㐺ᐅኚ᭦ 
firmataAdaptor := firmata.NewFirmataAdaptor("arduino", 
"/dev/ttyACM0") 
l...
Demo
ぢ䛶䜏䜝䜘䚸LEDග䛳䛶䜛䛰䜝䠛 
䛣䜜䚸Go䛷ື䛔䛶䜛䜣䛰䛬䟿
೵Ṇ䛩䜛䛻䛿Ctrl+C 
䜒䛧䛂open /dev/ttyACM0: "Permission denied"䛃䛸ฟ䜛ሙྜ 
$ sudo chown (䝴䞊䝄ྡ) /dev/ttyACM0
GoAndroid
GoAndroid 
Android䛻䛿JNI䛸䛔䛖䝛䜲䝔䜱䝤ゝㄒ䜢Java⤒⏤䛷ᐇ⾜䛩䜛௙ 
⤌䜏䛜䛒䜛 
Go䜢JNI䛷ᐇ⾜䛷䛝䜛䜘䛖䛻䛧䛯䛾䛜GoAndroid䛸䛔䛖䝟䝑䝏 
䝟䝑䝏䛺䛾䛷Go䝋䞊䝇䛛䜙䝡䝹䝗䛩䜛ᚲせ䛜䛒䜛䜘
䜎䛪䛿Android SDK䛸䛛JDK䛸䛛䜒䜝䜒䜝ྲྀ䛳䛶䛟䜛 
Android SDK 
http://developer.android.com/sdk/index.html 
SDK䛰䛡䛷䛔䛔䛺䜙䚸䛂 VIEW ALL DOWNLOADS ...
JDK䚸ant䚸adb䜢ධ䜜䜛 
䚷$ sudo apt-get install openjdk-7-jdk 
䚷$ sudo apt-get install ant 
䚷$ sudo apt-get install android-tools...
JNI䜢฼⏝䛩䜛䛻䛿Android NDK䛜ᚲせ 
https://developer.android.com/intl/ja/tools/sdk/ndk/index.html 
ᒎ㛤䛩䜛 
䚷$ chmod a+x android-ndk-r...
㐺⏝䛺䛸䛣䜝䛻ᒎ㛤䛧䛶.profile䛻ୗグ䜢㏣ຍ 
export NDK=$HOME/android-ndk 
䝞䞊䝆䝵䞁㑧㨱䛰䛳䛯䛾䛷 android-ndk䛻䝸䝛䞊䝮䛧䛶䜛䜘
NDKToolchain䜢సᡂ䛩䜛 
Androidྥ䛡䝷䜲䝤䝷䝸䜢స䜛᫬䛻౑䛖䜏䛯䛔 
$ $NDK/build/tools/make-standalone-toolchain.sh -- 
toolchain=arm-linux-andro...
䞉toolchain 
䚷ᑐ㇟➃ᮎ䛾䜰䞊䜻䝔䜽䝏䝱タᐃ 
䚷䛂arm-linux-androideabi-4.x䛃䛿ARM➃ᮎ 
䚷䛂x86-4.x䛃䛿x86➃ᮎ 
䚷䛂mipsel-linux-android-4.x䛃䛿MIPS➃ᮎ 
䚷 
...
䞉install-dir 
䚷NDKToolchain䛾సᡂඛ䝕䜱䝺䜽䝖䝸 
ndk-toolchain䝕䜱䝺䜽䝖䝸䛜సᡂ䛥䜜䛯䜙䚸NDK_ROOT䜢タᐃ 
䛧䛶䛚䛟 
export NDK_ROOT=$HOME/ndk-toolchain
GoAndroid 
https://github.com/eliasnaur/goandroid 
ARMv7௨㝆䛾CPU䛻ᑐᛂ䛧䛶䛔䜛 
Go1.2䛻ᑐᛂ䚹Go1.3䛿䝃䝫䞊䝖ᑐ㇟እ 
䛘䞊䛳䛶ឤ䛨䛰䛡䛹䚸䛭䜜䛻䛴䛔䛶䛿ᚋ㏙
䛸䜚䛒䛘䛪௒ᅇ䛿Go䝋䞊䝇䛿1.2.2䜢ྲྀ䛳䛶䛟䜛 
䚷$ hg clone -u go1.2.2 https://code.google.com/p/go 
᪤䛻ྲྀᚓ῭䜏䛷 1.2.2䛷䛺䛔䛺䜙䝤䝷䞁䝏䜢ษ䜚᭰䛘䜛 
䚷$ hg update...
GoAndroid䜢ྲྀ䛳䛶䛟䜛 
䚷$ git clone https://github.com/eliasnaur/goandroid.git 
goandroid䝕䜱䝺䜽䝖䝸䛻⛣ື䛧䚸patches䝕䜱䝺䜽䝖䝸 
䜢$GOROOT௨ୗ䜈䝁䝢...
$GOROOT/.hg/hgrc䛻ୗグ䜢㏣グ䛩䜛 
username䛿㐺ᙜ䛻ኚ䛘䜛䛸䛔䛔䜘 
[extensions] 
mq = 
codereview = ! 
[ui] 
username = name<sample@mail.com>
䝟䝑䝏䜢䛒䛶䜛 
䚷$ cd $GOROOT/src 
䚷$ hg qpush -a 
䝡䝹䝗䛩䜛 
䚷$ CGO_ENABLED=0 GOOS=linux GOARCH=arm ./make.bash 
CC="$NDK_ROOT/bin/a...
䝃䞁䝥䝹䜢ᐇ⾜䛧䛶䜏䜛 
goandroid/hello-gl2/䜈⛣ື 
build.sh䜢㛤䛝䚸 
$GOANDROID/bin/go 
䜢 
$GOROOT/bin/go 
䛻᭩䛝᥮䛘䜛
䝡䝹䝗ᐇ⾜ 
䚷$ ./build.sh 
android䝕䜱䝺䜽䝖䝸䛾project.properties䜢㛤䛝䚸 
౑⏝䛩䜛API䝞䞊䝆䝵䞁䛻᭩䛝᥮䛘 
൅䛾Nexus7(2013)䛾ሙྜ䚸target=android-18䛸䛩䜛
➃ᮎ䜢PC䛻⧅䛞䚸䜲䞁䝇䝖䞊䝹 
䚷$ ant -f android/build.xml clean debug install 
䛂BUILD SUCCESSFUL䛃 
䛸ฟຊ䛥䜜䛶䛔䜜䜀ᡂຌ 
➃ᮎ䛻䛂Go GL2!䛃䛸䛔䛖䜰䝥䝸䛜䛒䜛䛿䛪
Demo
ぢ䛶䜏䜝䜘 
䛣䜜䚸Go䛷ື䛔䛶䜛䜣䛰䛬䟿
䜒䛧 
䛂error while loading shared libraries: libz.so.1: cannot open 
shared object file: No such file or directory䛃 
䛾䜶䝷䞊䛷ኻᩋ...
䛱䜗䛳䛸䛰䛡 
䛣䜜䛛䜙䛾Go䜢⪃䛘䛶䜏䜛
GoAndroid䛷䛿䚸Go1.3䛿䝃䝫䞊䝖ᑐ㇟እ 
䛺䚸䛺䜣䛰䛳䛶䞊䟿䛳䛶ឤ䛨䛰䛡䛹䚸䛹䛖䜔䜙䚸Go1.4䛻ྥ䛡䛶 
‽ഛ䛧䛶䛔䜛䜏䛯䛔 
შ䛷䛿䚸GoAndroid䜢⤌䜏㎸䜣䛷䚸Go1.4䛛䜙GOOS䛻 
android䛜㏣ຍ䛥䜜䜛䛛䜒䟿 ...
䛣䜜䛛䜙䜒⇕䛔䛬䟿 
golang䟿
䛤Ύ⫈ 
䛒䜚䛜䛸䛖䛤䛦䛔䜎䛧䛯
䛚䜎䛡 
GopherCon2014 
http://confreaks.com/events/gophercon2014 
௒ᖺ䛾᫓䛤䜝䛻䜔䛳䛶䛯䚸Go䛾䜲䝧䞁䝖䛾ື⏬ 
௒ᅇ䛾Gobot䛿䛣䛣䛛䜙ぢ䛴䛡䛶䛝䛯䜘
Upcoming SlideShare
Loading in …5
×

GDG DevFest Kyoto 2014 これからのGoの話をしよう

1,242 views

Published on

GDG DevFest Kyoto 2014 これからのGoの話をしよう

Published in: Engineering

GDG DevFest Kyoto 2014 これからのGoの話をしよう

  1. 1. GDG DevFest Kyoto 2014 䝷䜲䝣 䛣䜜䛛䜙䛾Go䛾ヰ䜢䛧䜘䛖 䜏䜣䛺䛾 GDG⚄ᡞ䚷㔝⏣ᝅᚿ
  2. 2. ⮬ᕫ⤂௓䛳䛶኱஦䛰䜘䛽 㔝⏣䛷䛩䚹 ௨ୖ
  3. 3. ⎔ቃ OS 䚷Ubuntu14.04 x64 (VMware Player 6) Go Version 䚷1.3.3䚷(୍㒊1.2.2)
  4. 4. 㛤Ⓨ⎔ቃ 䍦䚷Vim
  5. 5. ୓䛸ゝ䜟䛪ி䛾୍䛾ᛕ䛾ᛕ䛾ᛕ䛾䛯䜑 Vim䜲䞁䝇䝖䞊䝹 䚷$ sudo apt-get install vim .profile䛻GOROOT䛸GOPATH䜢タᐃ 䚷export GOROOT=/usr/local/go 䚷export GOPATH=$HOME/go 䚷export PATH=$GOPATH/bin:$GOROOT/bin:$PATH GOPATH䛿go get䛷䝷䜲䝤䝷䝸䛜᱁⣡䛥䜜䜛䝕䜱䝺䜽䝖䝸䚹㐺ᙜ䛷 OK 䛒䛸䚸䝋䞊䝇䝣䜯䜲䝹䛿 GOPATH௨ୗ䛾src䝕䜱䝺䜽䝖䝸䛻స䛳䛶䛔䛟䛸Ⰻ䛔䜘 (ᚋ䛷ㄝ᫂)
  6. 6. ୓䛸ゝ䜟䛪ி䛾୍䛾ᛕ䛾ᛕ䛾ᛕ䛾䛯䜑 git䛸hg䝁䝬䞁䝗䛜౑䛘䜛䜘䛖䛻䜲䞁䝇䝖䞊䝹 䚷$ sudo apt-get install git 䚷$ sudo apt-get install mercurial Github䜔GoogleCode䛛䜙Ⰽ䚻ྲྀ䛳䛶䛟䜛䛛䜙
  7. 7. gocode 䜲䞁䝔䝸䝉䞁䝇䜢౑䛘䜛䜘䛖䛻䛺䜛 䚷$ go get -u github.com/nsf/gocode Vim䛾ሙྜ䚸"."䛾ᚋ䛻<C-x><C-o>䛷⿵᏶䛥䜜䜛
  8. 8. go get䛩䜛䛸䚸GOPATH௨ୗ䛻bin䚸pkg䚸src䛜⮬ືⓗ䛻స䜙 䜜䜛 ᚲせ䛺䛔䝕䜱䝺䜽䝖䝸䛿స䜙䜜䛺䛔 ⮬ศ䛷సᡂ䛧䛯䝋䞊䝇䜢go install䛧䛶䝟䝑䜿䞊䝆䜢స䜛ሙྜ䚸 GOPATH௨ୗ䛾src䛸ྠ㝵ᒙ䛻䛒䜛pkg䛻䝟䝑䜿䞊䝆䛜సᡂ䛥 䜜䜛 䛺䛾䛷䚸GOPATH௨ୗ䛾src䛻䝋䞊䝇䝣䜯䜲䝹స䛳䛶䛔䛟䛸Ⰻ䛔䜘䛳䛶ヰ
  9. 9. .vimrc (൅䛾䛿䛣䜣䛺ឤ䛨) filetype off filetype plugin off "indent off set runtimepath+=$GOROOT/misc/vim exe "set runtimepath+=".globpath($GOPATH, "src/github.com/nsf/gocode/vim") set number "⾜␒ྕ䜢⾲♧ set tabstop=4 "䜲䞁䝕䞁䝖䜢䝇䝨䞊䝇4䛴ศ䛻タᐃ set smartindent "ᨵ⾜᫬䛾䜸䞊䝖䜲䞁䝕䞁䝖 set completeopt=menuone "䝁䞊䝗⿵᏶᫬䛾䝥䝺䝡䝳䞊䜢↓ຠ䛻䛩䜛 set ignorecase "኱ᩥᏐ/ᑠᩥᏐ䛾༊ู䛺䛟᳨⣴䛩䜛 set incsearch "᳨⣴䝣䝺䞊䝈䛻㒊ศ䝬䝑䝏䛧䛶䛔䜛㒊ศ䜢⾲♧䛩䜛 set hlsearch "䝬䝑䝏䛩䜛䛩䜉䜢ᙉㄪ⾲♧䛩䜛 set smartcase "᳨⣴ᩥᏐิ䛻኱ᩥᏐ䛜ྵ䜎䜜䛶䛔䜛ሙྜ䛿༊ู䛧䛶᳨⣴䛩䜛 "䝞䝑䝣䜯䛾๓ᚋษ䜚᭰䛘 nmap <C-p> :bp<CR> nmap <C-n> :bn<CR> filetype plugin on "indent on
  10. 10. 䜽䝻䝇䝁䞁䝟䜲䝹
  11. 11. ᭱ึ䛻ᑐ㇟䛸䛺䜛䝥䝷䝑䝖䝣䜷䞊䝮䛾䜽䝻䝇䝁䞁䝟䜲䝹⎔ቃ䜢స ᡂ䛩䜛ᚲせ䛜䛒䜛 GOOS䛻ᑐ㇟OS䚸GOARCH䛻ᑐ㇟䜰䞊䜻䝔䜽䝏䝱䜢ᣦᐃ 䚷$ cd $GOROOT/src 䚷$ sudo GOOS=windows GOARCH=amd64 ./make.bash GOOS䛸GOARCH䛾⤌䜏ྜ䜟䛫䛿ୗグཧ↷ http://golang.org/doc/install/source
  12. 12. GOOS䚸GOARCH䜢ᣦᐃ䛧䛶go build䛩䜛䛸䚸ᑐ㇟䝥䝷䝑䝖 䝣䜷䞊䝮䛾ᐇ⾜䝣䜯䜲䝹䛜సᡂ䛥䜜䜛 䚷$ GOOS=windows GOARCH=amd64 go build sample.go
  13. 13. SQL
  14. 14. SQL Driver SQL Driver䛾୍ぴ https://code.google.com/p/go-wiki/ source/browse/SQLDrivers.wiki?repo=wiki MyMySQL https://github.com/ziutek/mymysql MySQL䛿ධ䜜䛸䛔䛶䛽䟿௒ᅇ䛿 MySQL5.5䜢౑䛳䛶䜛䜘
  15. 15. MyMySQL䜢ྲྀ䛳䛶䛟䜛 䚷$ go get github.com/ziutek/mymysql/thrsafe 䚷$ go get github.com/ziutek/mymysql/autorc 䚷$ go get github.com/ziutek/mymysql/godrv
  16. 16. import䛻 䚷_ "github.com/ziutek/mymysql/thrsafe" 䜢ධ䜜䛶䛚䛟 import ( "fmt" "github.com/ziutek/mymysql/mysql" _ "github.com/ziutek/mymysql/thrsafe" "os" )
  17. 17. ┤᥋౑䛖䜟䛡䛨䜓䛺䛔䛡䛹䚸thrsafe.go䛾init㛵ᩘ䛜࿧䜀䜜䚸 DB᥋⥆䛾‽ഛ䜢䛩䜛 thrsafe䛿䝇䝺䝑䝗䝉䞊䝣䛺DB᥋⥆䛻䛺䜛 _ "github.com/ziutek/mymysql/native" 䜢thrsafe䛾௦䜟䜚䛻import䛧䛶䜒Ⰻ䛔 mysql.go䛾init㛵ᩘ䛜࿧䜀䜜䚸ྠ䛨䛟DB᥋⥆䛾‽ഛ䜢䛩䜛 thrsafe䛸䛾㐪䛔䛿䚸䛣䛳䛱䛿䝇䝺䝑䝗䜰䞁䝉䞊䝣䛺DB᥋⥆䛻䛺 䜛
  18. 18. DB᥋⥆᝟ሗ䜢సᡂ䛧䚸᥋⥆䛩䜛 ➨஧ᘬᩘ䛿䝻䞊䜹䝹䜰䝗䝺䝇䚹➨୕ᘬᩘ䛜䝃䞊䝞䜰䝗䝺䝇 db := mysql.New("tcp", "", "127.0.0.1:3306", "sampleuser", "samplepw", "sampledb") db.Connect()
  19. 19. 㐜ᘏᐇ⾜䛷DB䜢㛢䛨䜘䛖䛻䛧䛶䛚䛟 defer func() { db.Close() }()
  20. 20. 䜽䜶䝸䜢ᐇ⾜䛩䜛䛻䛿Query䜢౑䛖 ➨୍ᘬᩘ䛻䜽䜶䝸䚸➨஧ᘬᩘ䛻䝟䝷䝯䞊䝍(ྍኚ)䜢タᐃ䛩䜛 sqlstr := "INSERT INTO sample_table (name) VALUES ('test_%d')" db.Query(sqlstr, 1)
  21. 21. SELECTᩥ䛾ᐇ⾜⤖ᯝ䛾䝬䝑䝢䞁䜾 sqlstr := "SELECT * FROM sample_table" rows, res, _ := db.Query(sqlstr) id := res.Map("id") name := res.Map("name")
  22. 22. 䝺䝁䞊䝗䛿䛣䜣䛺ឤ䛨䛷ぢ䜜䜛 for _, row := range rows { // ⤖ᯝ䜢1⾜䛪䛴⾲♧䛩䜛 fmt.Printf("| %d | %s |n", row.Int(id), row.Str(name)) }
  23. 23. 䝖䝷䞁䝄䜽䝅䝵䞁䛿䛣䜣䛺ឤ䛨 tr, err := db.Begin() sqlstr := "UPDATE sample_table SET name='test'" _, err = tr.Start(sqlstr) 䝁䝭䝑䝖䛿tr.Commit()䚸䝻䞊䝹䝞䝑䜽䛿tr.Rollback()䜢࿧䜆
  24. 24. OpenCV
  25. 25. OpenCV䜢䜲䞁䝇䝖䞊䝹 䚷$ sudo apt-get install ocl-icd-libopencl1 䚷$ sudo apt-get install libopencv-dev 1䛴┠䛾䜢䜲䞁䝇䝖䞊䝹䛧䛺䛔䛸䚸ḟᅇ䝻䜾䜲䞁᫬䛻 XWindow䛜䛣䛡䛶 䝻䜾䜲䞁䛷䛝䛺䛟䛺䜛䝞䜾䛜䛒䜛䛳䜍䛔 http://computationaldiary.blogspot.jp/2013/11/ubuntu-1310-opencv-245-apt-get.html
  26. 26. OpenCV䛜౑䛘䜛䜘䛖䛻䛩䜛(䝞䜲䞁䝕䜱䞁䜾䛧䛶䛟䜜䜛) 䚷$ go get github.com/lazywei/go-opencv $GOPATH/src/github.com/lazywei/go-opencv/samples 䛻Ⰽ䚻䝃䞁䝥䝹ධ䛳䛶䜛䜘䚹
  27. 27. Demo
  28. 28. Gobot
  29. 29. Gobot http://gobot.io/ Arduino䜔Sphero(2.0)䚸ARDrone䛺䛹11䛾䝥䝷䝑䝖䝣䜷䞊䝮䛻 ᑐᛂ ௒ᅇ䛿Arduino(Arduino UNO R3)䛷LED䜢ග䜙䛫䜛䜘
  30. 30. Firmata Firmata(䝣䜵䝹䝬䞊䝍)䛸䛔䛖䝥䝻䝖䝁䝹䜢౑䛖 䜎䛪䛿Arduino UNO R3䛻Firmata䜢᭩䛝㎸䜐 Arduino UNO R3䜢᥋⥆䛧䚸ArduinoIDE䛛䜙䚸 File -> Examples -> Firmata -> StandardFirmata 䜢㛤䛔䛶䚸Upload ArduinoIDE http://arduino.cc/en/main/software
  31. 31. Gobot䜢ྲྀ䛳䛶䛝䛶䚸ྛ䝟䝑䜿䞊䝆䜢⏝ព䛩䜛 䚷$ go get -u github.com/hybridgroup/gobot 䚷$ go install github.com/hybridgroup/gobot/platforms/firmata 䚷$ go install github.com/hybridgroup/gobot/platforms/gpio 䝅䝸䜰䝹㏻ಙ䛜ฟ᮶䜛䜘䛖䛻goserial䜒ධ䜜䜛 䚷$ go get -u github.com/tarm/goserial Gobot䛾䝞䞊䝆䝵䞁☜ㄆ䛿ୗグ䛷ฟ᮶䜛䜘䛖䛻䛺䜛䜘 䚷$ go get -u github.com/hybridgroup/gobot/gobot 䚷$ gobot -v
  32. 32. gobot/examples䛾ୗ䛾firmata_blink.go 䝫䞊䝖␒ྕ䛺䛹㐺ᐅኚ᭦ firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "led", "7")
  33. 33. Demo
  34. 34. ぢ䛶䜏䜝䜘䚸LEDග䛳䛶䜛䛰䜝䠛 䛣䜜䚸Go䛷ື䛔䛶䜛䜣䛰䛬䟿
  35. 35. ೵Ṇ䛩䜛䛻䛿Ctrl+C 䜒䛧䛂open /dev/ttyACM0: "Permission denied"䛃䛸ฟ䜛ሙྜ $ sudo chown (䝴䞊䝄ྡ) /dev/ttyACM0
  36. 36. GoAndroid
  37. 37. GoAndroid Android䛻䛿JNI䛸䛔䛖䝛䜲䝔䜱䝤ゝㄒ䜢Java⤒⏤䛷ᐇ⾜䛩䜛௙ ⤌䜏䛜䛒䜛 Go䜢JNI䛷ᐇ⾜䛷䛝䜛䜘䛖䛻䛧䛯䛾䛜GoAndroid䛸䛔䛖䝟䝑䝏 䝟䝑䝏䛺䛾䛷Go䝋䞊䝇䛛䜙䝡䝹䝗䛩䜛ᚲせ䛜䛒䜛䜘
  38. 38. 䜎䛪䛿Android SDK䛸䛛JDK䛸䛛䜒䜝䜒䜝ྲྀ䛳䛶䛟䜛 Android SDK http://developer.android.com/sdk/index.html SDK䛰䛡䛷䛔䛔䛺䜙䚸䛂 VIEW ALL DOWNLOADS AND SIZES䛃->䛂SDK Tools Only䛃䛛䜙 㐺ᙜ䛺䛸䛣䜝䛻ᒎ㛤䛧䛶.profile䛻ୗグ䜢㏣ຍ export ANDROID_HOME=$HOME/android-sdk-linux
  39. 39. JDK䚸ant䚸adb䜢ධ䜜䜛 䚷$ sudo apt-get install openjdk-7-jdk 䚷$ sudo apt-get install ant 䚷$ sudo apt-get install android-tools-adb ヨ䛧䛻➃ᮎ䛜ㄆ㆑䛥䜜䜛䛛☜ㄆ䛧䛶䛚䛟䚹䜒䛧ㄆ㆑䛥䜜䛶䛔䛺䛔ሙྜ䛿 rules䝣䜯䜲䝹䜢సᡂ䛧䛶䛽 䚷$ adb devices SDKManager䜢㉳ື䛧䚸➃ᮎ䛾API䝺䝧䝹䛻ྜ䜟䛫䛶䚸 䜲䞁䝇䝖䞊䝹 䚷$ $ANDROID_HOME/tools/android
  40. 40. JNI䜢฼⏝䛩䜛䛻䛿Android NDK䛜ᚲせ https://developer.android.com/intl/ja/tools/sdk/ndk/index.html ᒎ㛤䛩䜛 䚷$ chmod a+x android-ndk-r10c-linux-x86_64.bin 䚷$ ./android-ndk-r10c-linux-x86_64.bin Linux䛾x86䛿ၥ㢟䛺䛛䛳䛯䜣䛰䛡䛹䚸 x64䛾᪉䛿඲↛ᒎ㛤䛥䜜䛺䛔 … 䛷䚸ㄪ䜉䛶䜏䛯䜙 Issue䛻䛿ୖ䛜䛳䛶䛯 ( https://code.google.com/p/android/issues/detail?id=78148 ) ௨ୗ䜢ᐇ⾜䛧䛶ᒎ㛤䛩䜜䜀 OK䜏䛯䛔 䚷$ sudo dpkg --add-architecture i386 䚷$ sudo apt-get update 䚷$ sudo apt-get install libstdc++6:i386
  41. 41. 㐺⏝䛺䛸䛣䜝䛻ᒎ㛤䛧䛶.profile䛻ୗグ䜢㏣ຍ export NDK=$HOME/android-ndk 䝞䞊䝆䝵䞁㑧㨱䛰䛳䛯䛾䛷 android-ndk䛻䝸䝛䞊䝮䛧䛶䜛䜘
  42. 42. NDKToolchain䜢సᡂ䛩䜛 Androidྥ䛡䝷䜲䝤䝷䝸䜢స䜛᫬䛻౑䛖䜏䛯䛔 $ $NDK/build/tools/make-standalone-toolchain.sh -- toolchain=arm-linux-androideabi-4.9 --platform=android-18 --install-dir=ndk-toolchain
  43. 43. 䞉toolchain 䚷ᑐ㇟➃ᮎ䛾䜰䞊䜻䝔䜽䝏䝱タᐃ 䚷䛂arm-linux-androideabi-4.x䛃䛿ARM➃ᮎ 䚷䛂x86-4.x䛃䛿x86➃ᮎ 䚷䛂mipsel-linux-android-4.x䛃䛿MIPS➃ᮎ 䚷 䞉platform 䚷ᑐ㇟➃ᮎ䛾API䝺䝧䝹䛾タᐃ 䚷䚷௒ᅇ䛿Nexus7(2013)䛻ධ䜜䜘䛖䛸ᛮ䛳䛶䜛䛾䛷䚸䛸䜚䛒䛘䛪 18
  44. 44. 䞉install-dir 䚷NDKToolchain䛾సᡂඛ䝕䜱䝺䜽䝖䝸 ndk-toolchain䝕䜱䝺䜽䝖䝸䛜సᡂ䛥䜜䛯䜙䚸NDK_ROOT䜢タᐃ 䛧䛶䛚䛟 export NDK_ROOT=$HOME/ndk-toolchain
  45. 45. GoAndroid https://github.com/eliasnaur/goandroid ARMv7௨㝆䛾CPU䛻ᑐᛂ䛧䛶䛔䜛 Go1.2䛻ᑐᛂ䚹Go1.3䛿䝃䝫䞊䝖ᑐ㇟እ 䛘䞊䛳䛶ឤ䛨䛰䛡䛹䚸䛭䜜䛻䛴䛔䛶䛿ᚋ㏙
  46. 46. 䛸䜚䛒䛘䛪௒ᅇ䛿Go䝋䞊䝇䛿1.2.2䜢ྲྀ䛳䛶䛟䜛 䚷$ hg clone -u go1.2.2 https://code.google.com/p/go ᪤䛻ྲྀᚓ῭䜏䛷 1.2.2䛷䛺䛔䛺䜙䝤䝷䞁䝏䜢ษ䜚᭰䛘䜛 䚷$ hg update -C release-branch.go1.2 1.2.2䛾᪉䛻$GOROOT䜢タᐃ䛩䜛
  47. 47. GoAndroid䜢ྲྀ䛳䛶䛟䜛 䚷$ git clone https://github.com/eliasnaur/goandroid.git goandroid䝕䜱䝺䜽䝖䝸䛻⛣ື䛧䚸patches䝕䜱䝺䜽䝖䝸 䜢$GOROOT௨ୗ䜈䝁䝢䞊䛩䜛 䚷$ cp -a patches $GOROOT/.hg
  48. 48. $GOROOT/.hg/hgrc䛻ୗグ䜢㏣グ䛩䜛 username䛿㐺ᙜ䛻ኚ䛘䜛䛸䛔䛔䜘 [extensions] mq = codereview = ! [ui] username = name<sample@mail.com>
  49. 49. 䝟䝑䝏䜢䛒䛶䜛 䚷$ cd $GOROOT/src 䚷$ hg qpush -a 䝡䝹䝗䛩䜛 䚷$ CGO_ENABLED=0 GOOS=linux GOARCH=arm ./make.bash CC="$NDK_ROOT/bin/arm-linux-androideabi-gcc" GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 $GOROOT/bin/go install -tags android -a -v std
  50. 50. 䝃䞁䝥䝹䜢ᐇ⾜䛧䛶䜏䜛 goandroid/hello-gl2/䜈⛣ື build.sh䜢㛤䛝䚸 $GOANDROID/bin/go 䜢 $GOROOT/bin/go 䛻᭩䛝᥮䛘䜛
  51. 51. 䝡䝹䝗ᐇ⾜ 䚷$ ./build.sh android䝕䜱䝺䜽䝖䝸䛾project.properties䜢㛤䛝䚸 ౑⏝䛩䜛API䝞䞊䝆䝵䞁䛻᭩䛝᥮䛘 ൅䛾Nexus7(2013)䛾ሙྜ䚸target=android-18䛸䛩䜛
  52. 52. ➃ᮎ䜢PC䛻⧅䛞䚸䜲䞁䝇䝖䞊䝹 䚷$ ant -f android/build.xml clean debug install 䛂BUILD SUCCESSFUL䛃 䛸ฟຊ䛥䜜䛶䛔䜜䜀ᡂຌ ➃ᮎ䛻䛂Go GL2!䛃䛸䛔䛖䜰䝥䝸䛜䛒䜛䛿䛪
  53. 53. Demo
  54. 54. ぢ䛶䜏䜝䜘 䛣䜜䚸Go䛷ື䛔䛶䜛䜣䛰䛬䟿
  55. 55. 䜒䛧 䛂error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory䛃 䛾䜶䝷䞊䛷ኻᩋ䛧䛯ሙྜ(䛚䛭䜙䛟x64䛾ሙྜ䛾䜏) 䚷$ sudo apt-get install lib32z1 䛷䚸䜒䛖୍ᗘ䜲䞁䝇䝖䞊䝹ᐇ⾜
  56. 56. 䛱䜗䛳䛸䛰䛡 䛣䜜䛛䜙䛾Go䜢⪃䛘䛶䜏䜛
  57. 57. GoAndroid䛷䛿䚸Go1.3䛿䝃䝫䞊䝖ᑐ㇟እ 䛺䚸䛺䜣䛰䛳䛶䞊䟿䛳䛶ឤ䛨䛰䛡䛹䚸䛹䛖䜔䜙䚸Go1.4䛻ྥ䛡䛶 ‽ഛ䛧䛶䛔䜛䜏䛯䛔 შ䛷䛿䚸GoAndroid䜢⤌䜏㎸䜣䛷䚸Go1.4䛛䜙GOOS䛻 android䛜㏣ຍ䛥䜜䜛䛛䜒䟿 http://www.infoq.com/jp/news/2014/07/golang-google-android-native-dev 䛒䛸Gobot䜒䛒䜛䛧 䛴䛔䛻 PhysicalGo 䛾᫬௦䛛䟿䠛
  58. 58. 䛣䜜䛛䜙䜒⇕䛔䛬䟿 golang䟿
  59. 59. 䛤Ύ⫈ 䛒䜚䛜䛸䛖䛤䛦䛔䜎䛧䛯
  60. 60. 䛚䜎䛡 GopherCon2014 http://confreaks.com/events/gophercon2014 ௒ᖺ䛾᫓䛤䜝䛻䜔䛳䛶䛯䚸Go䛾䜲䝧䞁䝖䛾ື⏬ ௒ᅇ䛾Gobot䛿䛣䛣䛛䜙ぢ䛴䛡䛶䛝䛯䜘

×