SlideShare a Scribd company logo
1 of 38
Download to read offline
Core Concepts
• flamingo.App
• Dingo
• Config
• Routing
Flamingo Bootstrap
Bootstrap
• Define the configuration Areas

• Load default configuration

• Load the current configuration and routing information

• Load overriding configuration

• Register additional Handlers

• Run the main command / Start a router
flamingo.App
flamingo.App
• Main entry point, starts the Flamingo instance

• Configures dingo dependency injection and runs the root
command
flamingo.App / Changes
• flamingo.App(..., flamingo.AppAutorun(false))

• Allows external control of the App lifecycle
Dingo Modules
Dingo
• Flamingo Dependency Injection

• Interface similar to Guice

• Supports Singleton, Multi-/Mapbindings
Dingo
type HelloController struct {
responder *web.Responder
}
func (c *HelloController) Inject(responder *web.Responder) {
c.responder = responder
}
General
• Bind dependencies on application startup (in code)

• (future support for compile-type bindings)

• Config-Tree based injector-trees: It's possible to inject
different services/adapters for certain configuration areas
Binding
• General Syntax:

injector.Bind(new(Iface)).To(IfaceImpl{})
• .To(type) binds to a type

• .ToInstance(instance) binds to an instance

• .ToProvider(func() instance) binds to a provider
Annotation
• Default annotation is empty

injector.Bind(new(Iface)).AnnotatedWith("special-case").To(IfaceImpl{})
• Inject via

func (instance *MyType) Inject(annotated *struct{
IfaceInstance Iface `inject:"special-case"`
}) {
instance.iface = annotated.IfaceInstance
}
• Used by configuration for configuration values
Singleton Scopes
• If really necessary it is possible to use singletons

• .AsEagerSingleton() binds as a singleton, and loads it
when the application is initialized

• .In(dingo.Singleton) makes it a global singleton

• .In(dingo.ChildSingleton) makes it a singleton limited to
the config area
MultiBindings
• Allows to bind multiple instances/providers/types for one
type
func (*Module) Configure(injector *dingo.Injector) {
injector.BindMulti(new(Iface)).To(IfaceImpl1{})
injector.BindMulti(new(Iface)).To(IfaceImpl2{})
}
func (*MyService) Inject(ifaces []Iface) {}
MapBindings
• Similiar to Multibindings, but with a key instead of a list
func (*Module) Configure(injector *dingo.Injector) {
injector.BindMap(new(Iface), "key1").To(IfaceImpl1{})
injector.BindMap(new(Iface), "key2").To(IfaceImpl2{})
}
func (*MyService) Inject(ifaces map[string]Iface) {}
Provider
• If you need to make sure bindings are lazy evaluated, or
need multiple instances of a certain type, it is possible to
inject provider

• Define a type which ends with Provider, and gives you
what you need:
type IfaceProvider func() Iface
func (*Service) Inject(provider IfaceProvider) {
ifaceInstance := provider()
}
Provider
• It is possible to get provider for map/multibindings

• It is possible to get provider for provider

• Use with care: this might be an indicator of too complicated
code
Configuration
config.Map
• config.Map is a container for string -> interface{}

• configuration is available via annotated injection

• MyConfig string inject:"config:my.config"
• My config.Map `inject:"config:my"`
• Numbers: int is also float64
Config Merging
• Dot . separated config keys

• Every . donates one level in the tree:
my.config.value: hello
my:
config:
value: hello
Config Merging
• Config Maps are deep merged

• Allows overriding sub-keys:
my:
foo: bar
config:
value: hello
value2: world
my.config.value: myhello
Config Loading
• YAML Loader (others might follow)

• ENV Substitution via %%ENV:something%%default%
%

• config.yml

• config_$CONTEXT.yml

• config_local.yml

• $CONTEXTFILE
Configuration Areas
Configuration Areas
• Flamingo Config is hierarchical

• Config Areas can have multiple children, they inherit
config and dependency injection bindings

• Config is loaded based on file-system layout
Config
Upcoming Changes
• Cuelang support

• Allows Schema validation and much more
Default Configuration
• Modules in Flamingo can provide a default config, and
override existing config during the bootstrap

• The default configuration is loaded before the config
folder

• The override configuration can manipulate configuration
afterwards (use with care!)
Default Configuration
func (m *Module) DefaultConfig() config.Map {
return config.Map{
"my.config.test": "default value",
}
}
Overridden Configuration
func (m *Module) OverrideConfig(current config.Map) config.Map {
if oldvalue, ok := current.Get("my.config.test"); ok {
log.Println("Overriding", oldvalue)
} else {
log.Println("No old value")
}
return config.Map{
"my.config.test": "overriden value",
}
}
Routing
Routing: Paths
• Named Parameters: /route/:name

• Match everything until the following /

• Regex Parameters: /route/$name<[a-z]{2,}>

• Match everything which is captured by the regex (if
possible)

• Wildcard Parameters: /route/*name

• Match everything (everything until the end of the route)
Routing: Controller
• Map a route to a controller, either in routes.yml or in code

• my.controller

• Gets all URL parameters

• my.controller(name="foo")

• Sets name to foo

• my.controller(name?="foo")

• Sets name to foo if not set by a GET parameter

• my.controller(name?)

• Sets name to the value of the name GET parameter, if available
Routing: Reverse
• Reverse URLs are build based on available routes

• web.ReverseRouter

• Newest routes take precendence

• Router parameters are taken into account, meaning:

• /home -> cms.view(page="home")

• url("cms.view", router.P{"page": "home"}) -> /home
web.RouterRegistry
• HandleGet(context.Context, *web.Request) web.Result for
GET

• HandlePost(context.Context, *web.Request) web.Result for
POST

• Same for HEAD, DELETE, PUT

• HandleAny

• HandleData(context.Context, *web.Request) interface{} for
internal data requests
web.RouterRegistry
type routes struct {
controller *controller
}
func (r *routes) Inject(controller *controller) {
r.controller = controller
}
func (r *routes) Routes(registry *web.RouterRegistry) {
registry.Route("/", "home")
registry.HandleAny("home", r.controller.action)
}
core.Prefixrouter
• The core.Prefixrouter module provides a HTTP Router
which routes requests based on hostname/path

• When starting Flamingo the module will create HTTP
listener for all config Areas with a prefixrouter.baseurl
configuration
core.Cmd Package
core.Cmd
• Based on spf13/cobra

• Inject *cobra.Command with annotation flamingo to get
the main command

• Bind to cobra.Command to add custom commands

More Related Content

What's hot

Js interpreter interpreted
Js interpreter interpretedJs interpreter interpreted
Js interpreter interpretedMartha Schumann
 
Managing VMware VMs with Ansible
Managing VMware VMs with AnsibleManaging VMware VMs with Ansible
Managing VMware VMs with Ansiblejtyr
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World OptimizationDavid Golden
 
Virtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitVirtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitAndreas Heim
 
Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationDinesh Manajipet
 
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiUsing Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiInfluxData
 
Altitude San Francisco 2018: WebAssembly Tools & Applications
Altitude San Francisco 2018: WebAssembly Tools & ApplicationsAltitude San Francisco 2018: WebAssembly Tools & Applications
Altitude San Francisco 2018: WebAssembly Tools & ApplicationsFastly
 
Devoxx UK 2018 - A cloud application journey with helm and kubernetes
Devoxx UK 2018 - A cloud application journey with helm and kubernetesDevoxx UK 2018 - A cloud application journey with helm and kubernetes
Devoxx UK 2018 - A cloud application journey with helm and kubernetesAna-Maria Mihalceanu
 
RedisGears: Meir Shpilraien
RedisGears: Meir ShpilraienRedisGears: Meir Shpilraien
RedisGears: Meir ShpilraienRedis Labs
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixInfluxData
 
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...Pôle Systematic Paris-Region
 
Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014alex_perry
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptMark Shelton
 
Optimizing the Grafana Platform for Flux
Optimizing the Grafana Platform for FluxOptimizing the Grafana Platform for Flux
Optimizing the Grafana Platform for FluxInfluxData
 
Take Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play FrameworkTake Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play FrameworkAsher Glynn
 
GoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGautam Rege
 

What's hot (20)

C++ programming basics
C++ programming basicsC++ programming basics
C++ programming basics
 
Js interpreter interpreted
Js interpreter interpretedJs interpreter interpreted
Js interpreter interpreted
 
Managing VMware VMs with Ansible
Managing VMware VMs with AnsibleManaging VMware VMs with Ansible
Managing VMware VMs with Ansible
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
 
Virtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profitVirtualize and automate your development environment for fun and profit
Virtualize and automate your development environment for fun and profit
 
Elixir at Evercam (By Milos Mosic)
Elixir at Evercam (By Milos Mosic)Elixir at Evercam (By Milos Mosic)
Elixir at Evercam (By Milos Mosic)
 
Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt application
 
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob LisiUsing Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
Using Grafana with InfluxDB 2.0 and Flux Lang by Jacob Lisi
 
Altitude San Francisco 2018: WebAssembly Tools & Applications
Altitude San Francisco 2018: WebAssembly Tools & ApplicationsAltitude San Francisco 2018: WebAssembly Tools & Applications
Altitude San Francisco 2018: WebAssembly Tools & Applications
 
Devoxx UK 2018 - A cloud application journey with helm and kubernetes
Devoxx UK 2018 - A cloud application journey with helm and kubernetesDevoxx UK 2018 - A cloud application journey with helm and kubernetes
Devoxx UK 2018 - A cloud application journey with helm and kubernetes
 
RedisGears: Meir Shpilraien
RedisGears: Meir ShpilraienRedisGears: Meir Shpilraien
RedisGears: Meir Shpilraien
 
RedisGears
RedisGearsRedisGears
RedisGears
 
C# 4.0 dynamic
C# 4.0 dynamicC# 4.0 dynamic
C# 4.0 dynamic
 
Flux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul DixFlux and InfluxDB 2.0 by Paul Dix
Flux and InfluxDB 2.0 by Paul Dix
 
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
PyParis2017 / Function-as-a-service - a pythonic perspective on severless com...
 
Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014Regular expressions, Alex Perry, Google, PyCon2014
Regular expressions, Alex Perry, Google, PyCon2014
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Optimizing the Grafana Platform for Flux
Optimizing the Grafana Platform for FluxOptimizing the Grafana Platform for Flux
Optimizing the Grafana Platform for Flux
 
Take Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play FrameworkTake Flight - Using Fly with the Play Framework
Take Flight - Using Fly with the Play Framework
 
GoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPHGoFFIng around with Ruby #RubyConfPH
GoFFIng around with Ruby #RubyConfPH
 

Similar to Flamingo Core Concepts

Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to GriffonJames Williams
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScriptQiangning Hong
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to GriffonJames Williams
 
Qubell — Component Model
Qubell — Component ModelQubell — Component Model
Qubell — Component ModelRoman Timushev
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical StuffPetr Dvorak
 
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James WilliamsSF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James WilliamsPhilip Stehlik
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6Andy Butland
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)wonyong hwang
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java DevelopersYakov Fain
 
PTW Rails Bootcamp
PTW Rails BootcampPTW Rails Bootcamp
PTW Rails BootcampMat Schaffer
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
ITT 2014 - Peter Steinberger - Architecting Modular Codebases
ITT 2014 - Peter Steinberger - Architecting Modular CodebasesITT 2014 - Peter Steinberger - Architecting Modular Codebases
ITT 2014 - Peter Steinberger - Architecting Modular CodebasesIstanbul Tech Talks
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
How to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah CrowleyHow to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah CrowleyInfluxData
 
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxDataBuilding a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxDataInfluxData
 
Angular 1.6 typescript application
Angular 1.6 typescript applicationAngular 1.6 typescript application
Angular 1.6 typescript applicationYitzchak Meirovich
 
Facebook C++网络库Wangle调研
Facebook C++网络库Wangle调研Facebook C++网络库Wangle调研
Facebook C++网络库Wangle调研vorfeed chen
 

Similar to Flamingo Core Concepts (20)

Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to Griffon
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
What is your money doing?
What is your money doing?What is your money doing?
What is your money doing?
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Qubell — Component Model
Qubell — Component ModelQubell — Component Model
Qubell — Component Model
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical Stuff
 
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James WilliamsSF Grails - Ratpack - Compact Groovy Webapps - James Williams
SF Grails - Ratpack - Compact Groovy Webapps - James Williams
 
ASP.Net 5 and C# 6
ASP.Net 5 and C# 6ASP.Net 5 and C# 6
ASP.Net 5 and C# 6
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
PTW Rails Bootcamp
PTW Rails BootcampPTW Rails Bootcamp
PTW Rails Bootcamp
 
Python, do you even async?
Python, do you even async?Python, do you even async?
Python, do you even async?
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
ITT 2014 - Peter Steinberger - Architecting Modular Codebases
ITT 2014 - Peter Steinberger - Architecting Modular CodebasesITT 2014 - Peter Steinberger - Architecting Modular Codebases
ITT 2014 - Peter Steinberger - Architecting Modular Codebases
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
How to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah CrowleyHow to Build a Telegraf Plugin by Noah Crowley
How to Build a Telegraf Plugin by Noah Crowley
 
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxDataBuilding a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
Building a Telegraf Plugin by Noah Crowly | Developer Advocate | InfluxData
 
Angular 1.6 typescript application
Angular 1.6 typescript applicationAngular 1.6 typescript application
Angular 1.6 typescript application
 
Facebook C++网络库Wangle调研
Facebook C++网络库Wangle调研Facebook C++网络库Wangle调研
Facebook C++网络库Wangle调研
 

More from i-love-flamingo

Flamingo Commerce Module Details
Flamingo Commerce Module DetailsFlamingo Commerce Module Details
Flamingo Commerce Module Detailsi-love-flamingo
 
Flamingo Commerce Ports and Adapters
Flamingo Commerce Ports and AdaptersFlamingo Commerce Ports and Adapters
Flamingo Commerce Ports and Adaptersi-love-flamingo
 
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...i-love-flamingo
 
Flamingo Hello World Tutorial
Flamingo Hello World TutorialFlamingo Hello World Tutorial
Flamingo Hello World Tutoriali-love-flamingo
 

More from i-love-flamingo (6)

Flamingo Carotene
Flamingo CaroteneFlamingo Carotene
Flamingo Carotene
 
Flamingo Commerce Module Details
Flamingo Commerce Module DetailsFlamingo Commerce Module Details
Flamingo Commerce Module Details
 
Flamingo Commerce Intro
Flamingo Commerce IntroFlamingo Commerce Intro
Flamingo Commerce Intro
 
Flamingo Commerce Ports and Adapters
Flamingo Commerce Ports and AdaptersFlamingo Commerce Ports and Adapters
Flamingo Commerce Ports and Adapters
 
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
Flamingo Microservice based E-Commerce / Motivations,Backgrounds, Short Intro...
 
Flamingo Hello World Tutorial
Flamingo Hello World TutorialFlamingo Hello World Tutorial
Flamingo Hello World Tutorial
 

Recently uploaded

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 

Recently uploaded (20)

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 

Flamingo Core Concepts

  • 2. • flamingo.App • Dingo • Config • Routing
  • 4. Bootstrap • Define the configuration Areas • Load default configuration • Load the current configuration and routing information • Load overriding configuration • Register additional Handlers • Run the main command / Start a router
  • 6. flamingo.App • Main entry point, starts the Flamingo instance • Configures dingo dependency injection and runs the root command
  • 7. flamingo.App / Changes • flamingo.App(..., flamingo.AppAutorun(false)) • Allows external control of the App lifecycle
  • 9. Dingo • Flamingo Dependency Injection • Interface similar to Guice • Supports Singleton, Multi-/Mapbindings
  • 10. Dingo type HelloController struct { responder *web.Responder } func (c *HelloController) Inject(responder *web.Responder) { c.responder = responder }
  • 11. General • Bind dependencies on application startup (in code) • (future support for compile-type bindings) • Config-Tree based injector-trees: It's possible to inject different services/adapters for certain configuration areas
  • 12. Binding • General Syntax: injector.Bind(new(Iface)).To(IfaceImpl{}) • .To(type) binds to a type • .ToInstance(instance) binds to an instance • .ToProvider(func() instance) binds to a provider
  • 13. Annotation • Default annotation is empty injector.Bind(new(Iface)).AnnotatedWith("special-case").To(IfaceImpl{}) • Inject via func (instance *MyType) Inject(annotated *struct{ IfaceInstance Iface `inject:"special-case"` }) { instance.iface = annotated.IfaceInstance } • Used by configuration for configuration values
  • 14. Singleton Scopes • If really necessary it is possible to use singletons • .AsEagerSingleton() binds as a singleton, and loads it when the application is initialized • .In(dingo.Singleton) makes it a global singleton • .In(dingo.ChildSingleton) makes it a singleton limited to the config area
  • 15. MultiBindings • Allows to bind multiple instances/providers/types for one type func (*Module) Configure(injector *dingo.Injector) { injector.BindMulti(new(Iface)).To(IfaceImpl1{}) injector.BindMulti(new(Iface)).To(IfaceImpl2{}) } func (*MyService) Inject(ifaces []Iface) {}
  • 16. MapBindings • Similiar to Multibindings, but with a key instead of a list func (*Module) Configure(injector *dingo.Injector) { injector.BindMap(new(Iface), "key1").To(IfaceImpl1{}) injector.BindMap(new(Iface), "key2").To(IfaceImpl2{}) } func (*MyService) Inject(ifaces map[string]Iface) {}
  • 17. Provider • If you need to make sure bindings are lazy evaluated, or need multiple instances of a certain type, it is possible to inject provider • Define a type which ends with Provider, and gives you what you need: type IfaceProvider func() Iface func (*Service) Inject(provider IfaceProvider) { ifaceInstance := provider() }
  • 18. Provider • It is possible to get provider for map/multibindings • It is possible to get provider for provider • Use with care: this might be an indicator of too complicated code
  • 20. config.Map • config.Map is a container for string -> interface{} • configuration is available via annotated injection • MyConfig string inject:"config:my.config" • My config.Map `inject:"config:my"` • Numbers: int is also float64
  • 21. Config Merging • Dot . separated config keys • Every . donates one level in the tree: my.config.value: hello my: config: value: hello
  • 22. Config Merging • Config Maps are deep merged • Allows overriding sub-keys: my: foo: bar config: value: hello value2: world my.config.value: myhello
  • 23. Config Loading • YAML Loader (others might follow) • ENV Substitution via %%ENV:something%%default% % • config.yml • config_$CONTEXT.yml • config_local.yml • $CONTEXTFILE
  • 25. Configuration Areas • Flamingo Config is hierarchical • Config Areas can have multiple children, they inherit config and dependency injection bindings • Config is loaded based on file-system layout
  • 26. Config Upcoming Changes • Cuelang support • Allows Schema validation and much more
  • 27. Default Configuration • Modules in Flamingo can provide a default config, and override existing config during the bootstrap • The default configuration is loaded before the config folder • The override configuration can manipulate configuration afterwards (use with care!)
  • 28. Default Configuration func (m *Module) DefaultConfig() config.Map { return config.Map{ "my.config.test": "default value", } }
  • 29. Overridden Configuration func (m *Module) OverrideConfig(current config.Map) config.Map { if oldvalue, ok := current.Get("my.config.test"); ok { log.Println("Overriding", oldvalue) } else { log.Println("No old value") } return config.Map{ "my.config.test": "overriden value", } }
  • 31. Routing: Paths • Named Parameters: /route/:name • Match everything until the following / • Regex Parameters: /route/$name<[a-z]{2,}> • Match everything which is captured by the regex (if possible) • Wildcard Parameters: /route/*name • Match everything (everything until the end of the route)
  • 32. Routing: Controller • Map a route to a controller, either in routes.yml or in code • my.controller • Gets all URL parameters • my.controller(name="foo") • Sets name to foo • my.controller(name?="foo") • Sets name to foo if not set by a GET parameter • my.controller(name?) • Sets name to the value of the name GET parameter, if available
  • 33. Routing: Reverse • Reverse URLs are build based on available routes • web.ReverseRouter • Newest routes take precendence • Router parameters are taken into account, meaning: • /home -> cms.view(page="home") • url("cms.view", router.P{"page": "home"}) -> /home
  • 34. web.RouterRegistry • HandleGet(context.Context, *web.Request) web.Result for GET • HandlePost(context.Context, *web.Request) web.Result for POST • Same for HEAD, DELETE, PUT • HandleAny • HandleData(context.Context, *web.Request) interface{} for internal data requests
  • 35. web.RouterRegistry type routes struct { controller *controller } func (r *routes) Inject(controller *controller) { r.controller = controller } func (r *routes) Routes(registry *web.RouterRegistry) { registry.Route("/", "home") registry.HandleAny("home", r.controller.action) }
  • 36. core.Prefixrouter • The core.Prefixrouter module provides a HTTP Router which routes requests based on hostname/path • When starting Flamingo the module will create HTTP listener for all config Areas with a prefixrouter.baseurl configuration
  • 38. core.Cmd • Based on spf13/cobra • Inject *cobra.Command with annotation flamingo to get the main command • Bind to cobra.Command to add custom commands