SlideShare a Scribd company logo
1 of 23
Download to read offline
Go Build Web
github.com/mijia
About Me
• Backend Engineer: Go, Python, Scala
• Frontend Engineer: JavaScript, HTML, CSS,
React
• Platform Engineer: PaaS, Docker, Cluster
Orchestration
• Data Engineer: Python, Go, Spark, Thrift
• github.com/mijia
Web Experiences
• ~ 2007: J2EE with Struts, Spring MVC, Hibernate
• 2008 - 2012: Python Django, Tornado, Flask
• 2013 - 2014: Scala on Play
• 2014 - Present: Go …
Build Web App
• Talk about building web applications*
• Functional Web Server/App Server
• Frameworks vs Packages
• Developer Tools
* Not only just api web servers, frontend stuff involved
* Information may be outdated
Hello World
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, “Hello, ”)
}
func main() {
http.Handle(“/hello”, hello)
log.Fatal(http.ListenAndServe(":8080", nil))
}
// Standard library so good!
// That easy ?!
Routing
Handler
Handler
Handler
Handler
Handler
Requests
Responses
Middleware
Like an Onion
Inside the handler
def handler([context], request, response):
// parse form or query from request
// get some service object from context
// e.g. cache, db, session, user auth
// we use some model objects or POJOs
// user = models.User(name=“john”)
// CRUD the model object, biz logic
// then render the result into response
// html, json, xml and etc…
// or error/panic
Basically
we do stuff
like this
Beyond Hello World
• Stdlib: Request, Response, Server, Protocol, Handler
• Routing/Mux, Middleware
• Context
• Model/ORM
• Render/Template: HTML, JSON, XML
• Errors, Session, Caching, Form Validation, Security,
Log, Config, Encryption, Restful, Graceful Shutdown,
Queue, Jobs …
Go Web Frameworks
• beego.me
• gin-gonic.github.io/gin/
• github.com/go-martini/martini
• github.com/zenazn/goji
• revel.github.io
• ……
net/http Beego Gin Martini Goji Revel
Routing
DefaultMux,
string max-
length
matching
Param, Regex,
Namespace,
Tree Search
Param, Group,
HttpRouter
(Prefix Tree)
Param, Group,
Handler* (any
callable), Linear
DefaultMux,
Param, Regex,
Pattern Iface,
State Machine
Param,
pathtree.Tree
Middleware No Filters
Middleware,
per-group,
per-route
Context/Injector Middleware
Filters,
Interceptors,
per-action
Context
No
x/net/context
beego/context
input, output
gin.Context
(Req, Res,
Metadata
Facade)
Context/Injector
web.C
Params, Envs
No
Model/ORM No
beego/orm
MySQL,
Postgres,
Sqlite3
No No No No
Render
html/template
text/template
html/template
layout support
html/template,
JSON, XML
No No
html/template,
app/views/
*.html
Advanced /debug/…
Lots of utils,
session, log,
Cache,
deploy…
Recovery,
Log, Sentry,
Binding
*No Longer
Maintained, too
magical
Minimalistic
Hot Reload,
Session,
Cache, Debug,
WS, I18N
Go Web Packages
• julienschmidt/httprouter
• dozens of frameworks based on this pkg
• codegangsta/negroni
• Middlewares: dozens of negroni compatible
middleware pkgs on github.com
• www.gorillatoolkit.org
• context, mux, reverse, cookie, session, websocket
• ……
Go Proverbs
• Simple, Poetic, Pithy
• The bigger the interface, the weaker the
abstraction.
• We don’t like all the magic since we are coming
from Scala/Play, :(
• Composing, Interface, Adaptor
Compose and Adapt
// our factory adaptor
type Handler func(
ctx context.Context,
w http.ResponseWriter,
r *http.Request) context.Context
// httprouter/router.go
type Handle func(http.ResponseWriter, *http.Request, Params)
// net/http/server.go
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}
Compose
Into
Big
Handler
Middleware
// Our factory adaptor
type Middleware interface {
ServeHTTP(ctx context.Context, w http.ResponseWriter, r *http.Request,
next Handler) context.Context
}
// Negroni Middleware
type Handler interface {
ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
}
Go Proverbs
A little copying is better than a
little dependency.
Wrap middlewares and router
into the “onion”, compose into
big net/http handler
We Love Go Pkgs
• So we select the best but simple packages to
adapt and compose into our own web toolkit,
which provides routing, context, middleware,
render, form params and validation …… Ain’t
that much magic
• Will love go pkgs more if Go team solved the
vendor/dependency problem, :)
• github.com/mijia/sweb
Developer Tools
• ORMs (why is this here?)
• Frontend Assets (nodejs, npm, webpack…)
• Hot Reload (edit, build, refresh)
• Distribution Packges (make dist)
ORMs / Models
• Most ORMs for Go using reflection
• Proverb: “Clear is better than clever.”
• Proverb: “Reflection is never clear.”
• go generate: generate go code according to
database scheme (Scala Slick)
• github.com/mijia/modelq: it’s a tool
• No joins, sql computations, but we can interface with
“jmoiron/sqlx”
//go:generate modelq -db=root@/xxx -pkg=models -driver=mysql
-schema=xxx -tables=user -template=models/modelq.tmpl
Frontend Assets
• JavaScripts, Stylesheets, Images
• JavaScript compiler/transpiler and bundler: babel,
browserify, CoffeeScript
• CSS: we also have stylus which can be compiled into css
• Images: sprite image (Go Image Lib) and generate
sprite@{1,2,3}x.styl files as stylus variables and mixins
• All assets needs fingerprint for browser cache expires
• Go Template: {{ assets “images/desktop/logo.png” }}
• Why not gulp, grant, webpack … some real frontend toolsets?
Build a tool
• github.com/mijia/gobuildweb
• Assets management: JavaScript, CSS, Images
• Hot reload for rebuild -> kill -> run, also hot reload for templates
• Make distribution package and cross compile
• Don’t recommend to use
• Shift to Webpack + Makefile: let pros to worry about those staff
• @fswatch $(GO_FILES) $(TEMPLATES) | xargs -n1 -I{} make restart
|| make kill
• https://github.com/mijia/web-starter-kit
What we learned
• Go Standard Library is so good.
•
• Love simple, love compose, love interface, love Go Pkgs
• No desire of magic
• Love tools, very easy to make cli tools using Go, to boost
productivity
• Use python to generate Go code, :)
• Equals{Int,Int8,Int16,Int32,Int64,String…}Slice
Thank you

More Related Content

What's hot

Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Marcel Chastain
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Michael Pirnat
 
How to start developing apps for Firefox OS
How to start developing apps for Firefox OSHow to start developing apps for Firefox OS
How to start developing apps for Firefox OSbenko
 
Drupal: an Overview
Drupal: an OverviewDrupal: an Overview
Drupal: an OverviewMatt Weaver
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureBarry Jones
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to RailsBarry Jones
 
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAdler Hsieh
 
Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Ngoc Dao
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafThymeleaf
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
Rails development environment talk
Rails development environment talkRails development environment talk
Rails development environment talkReuven Lerner
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
PyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesPyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesArtur Barseghyan
 
OSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache SlingOSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache SlingCarsten Ziegeler
 
Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...
Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...
Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...Matt Weaver
 

What's hot (20)

Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
 
How to start developing apps for Firefox OS
How to start developing apps for Firefox OSHow to start developing apps for Firefox OS
How to start developing apps for Firefox OS
 
Drupal: an Overview
Drupal: an OverviewDrupal: an Overview
Drupal: an Overview
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
Day 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application ArchitectureDay 9 - PostgreSQL Application Architecture
Day 9 - PostgreSQL Application Architecture
 
Day 2 - Intro to Rails
Day 2 - Intro to RailsDay 2 - Intro to Rails
Day 2 - Intro to Rails
 
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 TaiwanAutomating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
Automating Your Daily Tasks with Scripting - RubyConf 2015 Taiwan
 
Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013
 
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with ThymeleafSpring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
Spring I/O 2012: Natural Templating in Spring MVC with Thymeleaf
 
Day 8 - jRuby
Day 8 - jRubyDay 8 - jRuby
Day 8 - jRuby
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Rails development environment talk
Rails development environment talkRails development environment talk
Rails development environment talk
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
遇見 Ruby on Rails
遇見 Ruby on Rails遇見 Ruby on Rails
遇見 Ruby on Rails
 
PyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slidesPyGrunn 2017 - Django Performance Unchained - slides
PyGrunn 2017 - Django Performance Unchained - slides
 
OSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache SlingOSGi, Scripting and REST, Building Webapps With Apache Sling
OSGi, Scripting and REST, Building Webapps With Apache Sling
 
Day 4 - Models
Day 4 - ModelsDay 4 - Models
Day 4 - Models
 
Rango
RangoRango
Rango
 
Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...
Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...
Ebooks without Vendors: Using Open Source Software to Create and Share Meanin...
 

Similar to 1.6 米嘉 gobuildweb

Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on RailsAvi Kedar
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTTkevinvw
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009Jason Davies
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Pierre Joye
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
Django Overview
Django OverviewDjango Overview
Django OverviewBrian Tol
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsRichard Rodger
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache UsergridDavid M. Johnson
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application developmentzonathen
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then someOhad Kravchick
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and ActivatorKevin Webber
 
HTML5: An Overview
HTML5: An OverviewHTML5: An Overview
HTML5: An OverviewNagendra Um
 

Similar to 1.6 米嘉 gobuildweb (20)

Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
REST easy with API Platform
REST easy with API PlatformREST easy with API Platform
REST easy with API Platform
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Django Overview
Django OverviewDjango Overview
Django Overview
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 
How to Contribute to Apache Usergrid
How to Contribute to Apache UsergridHow to Contribute to Apache Usergrid
How to Contribute to Apache Usergrid
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
What I learned from FluentConf and then some
What I learned from FluentConf and then someWhat I learned from FluentConf and then some
What I learned from FluentConf and then some
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
Be faster then rabbits
Be faster then rabbitsBe faster then rabbits
Be faster then rabbits
 
HTML5: An Overview
HTML5: An OverviewHTML5: An Overview
HTML5: An Overview
 

More from Leo Zhou

第三名 3rd zhyict
第三名 3rd zhyict第三名 3rd zhyict
第三名 3rd zhyictLeo Zhou
 
异常检测在苏宁的实践
异常检测在苏宁的实践异常检测在苏宁的实践
异常检测在苏宁的实践Leo Zhou
 
第二名 2nd 火眼金睛
第二名 2nd 火眼金睛第二名 2nd 火眼金睛
第二名 2nd 火眼金睛Leo Zhou
 
第四名 4th H3C AI Institute
第四名 4th H3C AI Institute第四名 4th H3C AI Institute
第四名 4th H3C AI InstituteLeo Zhou
 
第一名 1st Bocoiops
第一名 1st Bocoiops第一名 1st Bocoiops
第一名 1st BocoiopsLeo Zhou
 
第六名 6th Aurora
第六名 6th Aurora第六名 6th Aurora
第六名 6th AuroraLeo Zhou
 
AI使能网络自动驾驶 AI Building Autonomous Driving Network
AI使能网络自动驾驶 AI Building Autonomous Driving NetworkAI使能网络自动驾驶 AI Building Autonomous Driving Network
AI使能网络自动驾驶 AI Building Autonomous Driving NetworkLeo Zhou
 
2.2 go在阿里云cdn系统的应用
2.2 go在阿里云cdn系统的应用2.2 go在阿里云cdn系统的应用
2.2 go在阿里云cdn系统的应用Leo Zhou
 
1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑Leo Zhou
 
1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用Leo Zhou
 
Protocol libraries the right way
Protocol libraries the right wayProtocol libraries the right way
Protocol libraries the right wayLeo Zhou
 
美团数据库运维平台介绍
美团数据库运维平台介绍美团数据库运维平台介绍
美团数据库运维平台介绍Leo Zhou
 
特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践Leo Zhou
 
我的互联网运维理论与实践
我的互联网运维理论与实践我的互联网运维理论与实践
我的互联网运维理论与实践Leo Zhou
 
如何选择 Docker 监控方案
如何选择 Docker 监控方案如何选择 Docker 监控方案
如何选择 Docker 监控方案Leo Zhou
 
美团数据库运维平台介绍
美团数据库运维平台介绍美团数据库运维平台介绍
美团数据库运维平台介绍Leo Zhou
 
The net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James BennettThe net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James BennettLeo Zhou
 
Hypothesis randomised testing for django
Hypothesis randomised testing for djangoHypothesis randomised testing for django
Hypothesis randomised testing for djangoLeo Zhou
 
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享Leo Zhou
 
动静态混合网站或 APP的CDN优化方法
动静态混合网站或 APP的CDN优化方法动静态混合网站或 APP的CDN优化方法
动静态混合网站或 APP的CDN优化方法Leo Zhou
 

More from Leo Zhou (20)

第三名 3rd zhyict
第三名 3rd zhyict第三名 3rd zhyict
第三名 3rd zhyict
 
异常检测在苏宁的实践
异常检测在苏宁的实践异常检测在苏宁的实践
异常检测在苏宁的实践
 
第二名 2nd 火眼金睛
第二名 2nd 火眼金睛第二名 2nd 火眼金睛
第二名 2nd 火眼金睛
 
第四名 4th H3C AI Institute
第四名 4th H3C AI Institute第四名 4th H3C AI Institute
第四名 4th H3C AI Institute
 
第一名 1st Bocoiops
第一名 1st Bocoiops第一名 1st Bocoiops
第一名 1st Bocoiops
 
第六名 6th Aurora
第六名 6th Aurora第六名 6th Aurora
第六名 6th Aurora
 
AI使能网络自动驾驶 AI Building Autonomous Driving Network
AI使能网络自动驾驶 AI Building Autonomous Driving NetworkAI使能网络自动驾驶 AI Building Autonomous Driving Network
AI使能网络自动驾驶 AI Building Autonomous Driving Network
 
2.2 go在阿里云cdn系统的应用
2.2 go在阿里云cdn系统的应用2.2 go在阿里云cdn系统的应用
2.2 go在阿里云cdn系统的应用
 
1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑1.4 go在数据存储上面的应用—毛剑
1.4 go在数据存储上面的应用—毛剑
 
1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用1.2 刘奇 go在分布式数据库中的应用
1.2 刘奇 go在分布式数据库中的应用
 
Protocol libraries the right way
Protocol libraries the right wayProtocol libraries the right way
Protocol libraries the right way
 
美团数据库运维平台介绍
美团数据库运维平台介绍美团数据库运维平台介绍
美团数据库运维平台介绍
 
特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践特卖场景下的大数据平台和机器学习实践
特卖场景下的大数据平台和机器学习实践
 
我的互联网运维理论与实践
我的互联网运维理论与实践我的互联网运维理论与实践
我的互联网运维理论与实践
 
如何选择 Docker 监控方案
如何选择 Docker 监控方案如何选择 Docker 监控方案
如何选择 Docker 监控方案
 
美团数据库运维平台介绍
美团数据库运维平台介绍美团数据库运维平台介绍
美团数据库运维平台介绍
 
The net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James BennettThe net is dark and full of terrors - James Bennett
The net is dark and full of terrors - James Bennett
 
Hypothesis randomised testing for django
Hypothesis randomised testing for djangoHypothesis randomised testing for django
Hypothesis randomised testing for django
 
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
NoSQL@VIP — 唯品会NoSQL平台⾃动化发展及运维经验分享
 
动静态混合网站或 APP的CDN优化方法
动静态混合网站或 APP的CDN优化方法动静态混合网站或 APP的CDN优化方法
动静态混合网站或 APP的CDN优化方法
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

1.6 米嘉 gobuildweb

  • 2. About Me • Backend Engineer: Go, Python, Scala • Frontend Engineer: JavaScript, HTML, CSS, React • Platform Engineer: PaaS, Docker, Cluster Orchestration • Data Engineer: Python, Go, Spark, Thrift • github.com/mijia
  • 3.
  • 4. Web Experiences • ~ 2007: J2EE with Struts, Spring MVC, Hibernate • 2008 - 2012: Python Django, Tornado, Flask • 2013 - 2014: Scala on Play • 2014 - Present: Go …
  • 5. Build Web App • Talk about building web applications* • Functional Web Server/App Server • Frameworks vs Packages • Developer Tools * Not only just api web servers, frontend stuff involved * Information may be outdated
  • 6. Hello World func hello(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, “Hello, ”) } func main() { http.Handle(“/hello”, hello) log.Fatal(http.ListenAndServe(":8080", nil)) } // Standard library so good! // That easy ?!
  • 8. Inside the handler def handler([context], request, response): // parse form or query from request // get some service object from context // e.g. cache, db, session, user auth // we use some model objects or POJOs // user = models.User(name=“john”) // CRUD the model object, biz logic // then render the result into response // html, json, xml and etc… // or error/panic Basically we do stuff like this
  • 9. Beyond Hello World • Stdlib: Request, Response, Server, Protocol, Handler • Routing/Mux, Middleware • Context • Model/ORM • Render/Template: HTML, JSON, XML • Errors, Session, Caching, Form Validation, Security, Log, Config, Encryption, Restful, Graceful Shutdown, Queue, Jobs …
  • 10. Go Web Frameworks • beego.me • gin-gonic.github.io/gin/ • github.com/go-martini/martini • github.com/zenazn/goji • revel.github.io • ……
  • 11. net/http Beego Gin Martini Goji Revel Routing DefaultMux, string max- length matching Param, Regex, Namespace, Tree Search Param, Group, HttpRouter (Prefix Tree) Param, Group, Handler* (any callable), Linear DefaultMux, Param, Regex, Pattern Iface, State Machine Param, pathtree.Tree Middleware No Filters Middleware, per-group, per-route Context/Injector Middleware Filters, Interceptors, per-action Context No x/net/context beego/context input, output gin.Context (Req, Res, Metadata Facade) Context/Injector web.C Params, Envs No Model/ORM No beego/orm MySQL, Postgres, Sqlite3 No No No No Render html/template text/template html/template layout support html/template, JSON, XML No No html/template, app/views/ *.html Advanced /debug/… Lots of utils, session, log, Cache, deploy… Recovery, Log, Sentry, Binding *No Longer Maintained, too magical Minimalistic Hot Reload, Session, Cache, Debug, WS, I18N
  • 12. Go Web Packages • julienschmidt/httprouter • dozens of frameworks based on this pkg • codegangsta/negroni • Middlewares: dozens of negroni compatible middleware pkgs on github.com • www.gorillatoolkit.org • context, mux, reverse, cookie, session, websocket • ……
  • 13. Go Proverbs • Simple, Poetic, Pithy • The bigger the interface, the weaker the abstraction. • We don’t like all the magic since we are coming from Scala/Play, :( • Composing, Interface, Adaptor
  • 14. Compose and Adapt // our factory adaptor type Handler func( ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context // httprouter/router.go type Handle func(http.ResponseWriter, *http.Request, Params) // net/http/server.go type Handler interface { ServeHTTP(ResponseWriter, *Request) } Compose Into Big Handler
  • 15. Middleware // Our factory adaptor type Middleware interface { ServeHTTP(ctx context.Context, w http.ResponseWriter, r *http.Request, next Handler) context.Context } // Negroni Middleware type Handler interface { ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) } Go Proverbs A little copying is better than a little dependency. Wrap middlewares and router into the “onion”, compose into big net/http handler
  • 16. We Love Go Pkgs • So we select the best but simple packages to adapt and compose into our own web toolkit, which provides routing, context, middleware, render, form params and validation …… Ain’t that much magic • Will love go pkgs more if Go team solved the vendor/dependency problem, :) • github.com/mijia/sweb
  • 17. Developer Tools • ORMs (why is this here?) • Frontend Assets (nodejs, npm, webpack…) • Hot Reload (edit, build, refresh) • Distribution Packges (make dist)
  • 18. ORMs / Models • Most ORMs for Go using reflection • Proverb: “Clear is better than clever.” • Proverb: “Reflection is never clear.” • go generate: generate go code according to database scheme (Scala Slick) • github.com/mijia/modelq: it’s a tool • No joins, sql computations, but we can interface with “jmoiron/sqlx”
  • 19. //go:generate modelq -db=root@/xxx -pkg=models -driver=mysql -schema=xxx -tables=user -template=models/modelq.tmpl
  • 20. Frontend Assets • JavaScripts, Stylesheets, Images • JavaScript compiler/transpiler and bundler: babel, browserify, CoffeeScript • CSS: we also have stylus which can be compiled into css • Images: sprite image (Go Image Lib) and generate sprite@{1,2,3}x.styl files as stylus variables and mixins • All assets needs fingerprint for browser cache expires • Go Template: {{ assets “images/desktop/logo.png” }} • Why not gulp, grant, webpack … some real frontend toolsets?
  • 21. Build a tool • github.com/mijia/gobuildweb • Assets management: JavaScript, CSS, Images • Hot reload for rebuild -> kill -> run, also hot reload for templates • Make distribution package and cross compile • Don’t recommend to use • Shift to Webpack + Makefile: let pros to worry about those staff • @fswatch $(GO_FILES) $(TEMPLATES) | xargs -n1 -I{} make restart || make kill • https://github.com/mijia/web-starter-kit
  • 22. What we learned • Go Standard Library is so good. • • Love simple, love compose, love interface, love Go Pkgs • No desire of magic • Love tools, very easy to make cli tools using Go, to boost productivity • Use python to generate Go code, :) • Equals{Int,Int8,Int16,Int32,Int64,String…}Slice