(live) build and run golang web server on android.avi
TRANSCRIPT
![Page 3: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/3.jpg)
Disclaimer
The main part of session is live-coding. This slide has only little information.
Inspired by camlistore and outyet
Maybe useless, *just for fun*
![Page 4: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/4.jpg)
Goal Of This Session
Build and run Golang web server on Android
Live Coding
![Page 5: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/5.jpg)
golang: Programming Language
for simple, reliable, and efficient software.
http://blog.golang.org/5years/gophers5th.jpg
![Page 6: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/6.jpg)
Web server
Processes request via HTTP protocol
Web Server Client
![Page 7: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/7.jpg)
Web server
Processes request via HTTP protocol
Listen a socketReceive HTTP request from the socket
Web Server Client
url: /blahblah,method: GET
![Page 8: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/8.jpg)
Web server
Processes request via HTTP protocol
Listen a socketReceive HTTP request from the socketProcess the request
Web Server Client
url: /blahblah,method: GET
![Page 9: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/9.jpg)
Web server
Processes request via HTTP protocol
Listen a socketReceive HTTP request from the socketProcess the requestSend HTTP response to client using the socket
Web Server Client
url: /blahblah,method: GET
Status: OK,Body: <p>welcome</p>
![Page 10: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/10.jpg)
(Live) Simple Golang Webserver
…...
![Page 11: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/11.jpg)
(Live) Simple Golang Webserver
…... complete
net/http rules
The code: https://github.com/sjp38/linuxOutYet/tree/804aa370f5adbf3d4377ee1b1e862cbc49d81c1c
![Page 12: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/12.jpg)
Golang and Android
● Golang Supports Android officially from v1.4○ The support focus on Application; just let .so or .apk
https://blog.golang.org/gopher/gopher.pnghttp://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
![Page 13: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/13.jpg)
Golang and Android
● Golang Supports Android officially from v1.4○ The support focus on Application; just let .so or .apk○ Requires complex build process and client code
https://blog.golang.org/gopher/gopher.pnghttp://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
![Page 14: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/14.jpg)
Golang and Android
● Golang Supports Android officially from v1.4○ The support focus on Application; just let .so or .apk○ Requires complex build process and client code○ Couldn’t be more simple, easier?
https://blog.golang.org/gopher/gopher.pnghttp://upload.wikimedia.org/wikipedia/commons/thumb/d/d7/Android_robot.svg/511px-Android_robot.svg.png
![Page 15: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/15.jpg)
Golang on Android: Background
Android is a variant of Linux system with ARMx86 Android exist, though...
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
![Page 16: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/16.jpg)
Golang on Android: Background
Android is a variant of Linux system with ARMx86 Android exist, though...
Go supports ARM & Linux Officiallywith static-linking
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
![Page 17: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/17.jpg)
Golang on Android: Background
Android is a variant of Linux system with ARMx86 Android exist, though...
Go supports ARM & Linux Officiallywith static-linking
So, why not?
http://www.kitguru.net/wp-content/uploads/2012/03/linux-android.png
![Page 18: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/18.jpg)
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux
![Page 19: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/19.jpg)
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app
![Page 20: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/20.jpg)
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app3. Copy the binary in private space of the app
![Page 21: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/21.jpg)
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app3. Copy the binary in private space of the app4. Give execute permission to the binary
/data/data/com.example.goRunner/files # ls -al-rwxrwxrwx u0_a55 u0_a55 4512840 2014-11-28 17:45 gobin
![Page 22: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/22.jpg)
Golang on Android: Plan
1. Cross compile Go program as ARM / Linux2. Include the binary in assets/ of Android app3. Copy the binary in private space of the app4. Give execute permission to the binary5. Execute it
/data/data/com.example.goRunner/files # ls -al-rwxrwxrwx u0_a55 u0_a55 4512840 2014-11-28 17:45 gobin
![Page 23: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/23.jpg)
(Live) Golang on Android
……
![Page 24: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/24.jpg)
(Live) Golang on Android: Problem
…… Not successful
go binary runner code:https://github.com/sjp38/goOnAndroidFA/releases/tag/devfair2014.gdg.kr
![Page 25: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/25.jpg)
(Live) Golang on Android: Problem
…… Not successful
It has no /etc/hosts
CA Certs path is different with pure Linux/system/etc/security/cacerts
![Page 26: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/26.jpg)
(Live) Golang on Android: Problem
…… Not successful
It has no /etc/hosts
CA Certs path is different with pure Linux/system/etc/security/cacerts
Android is a variant of, not pure LinuxGOOS=android has same problem, too :’(
![Page 27: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/27.jpg)
(Live) Golang on Android: Solution
It has no /etc/hostsGet IP manually
Certifications path is differentUse those certifications
![Page 28: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/28.jpg)
(Live) Golang on Android: Again
……
![Page 29: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/29.jpg)
(Live) Golang on Android
…… Complete
It’s hacky, but works
The code: https://github.com/sjp38/linuxOutYet/releases/tag/devfair2014.gdg.kr
![Page 30: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/30.jpg)
Summary
Golang program can run on Android
![Page 31: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/31.jpg)
Summary
Golang program can run on AndroidOfficially as .so or .apk file
![Page 32: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/32.jpg)
Summary
Golang program can run on AndroidOfficially as .so or .apk fileOr, as elf binary with unofficial, little hack
![Page 33: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/33.jpg)
Summary
Golang program can run on AndroidOfficially as .so or .apk fileOr, as elf binary with unofficial, little hack
Some features don’t work on Android, yetStill need some hacks
![Page 34: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/34.jpg)
Final Source Code
go web server: https://github.com/sjp38/linuxOutYet/releases/tag/devfair2014.gdg.kr
go program runner(Android app): https://github.com/sjp38/goOnAndroidFA/releases/tag/devfair2014.gdg.kr
![Page 35: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/35.jpg)
This slide has been used for
GDG Korea DevFair 2014
GDG Korea Golang Seoul Meetup
![Page 36: (Live) build and run golang web server on android.avi](https://reader034.vdocuments.us/reader034/viewer/2022051112/55a931d31a28ab2b368b460d/html5/thumbnails/36.jpg)
This work by SeongJae Park is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.