Please do learn how net/http std package works, first.
This folder provides easy to understand code snippets on how to get started with iris web framework.
It doesn't always contain the "best ways" but it does cover each important feature that will make you so excited to GO with iris!
- Install the Go Programming Language, version 1.12+ from https://golang.org/dl.
- Install Iris
- Install any external packages that required by the examples
External packages
cd _examples && go get ./...
And run each example you wanna see, e.g.
$ cd $GOPATH/src/github.com/kataras/iris/_examples/overview
$ go run main.go
Test the examples by opening a terminal window and execute:
go test -v ./...
- Hello world!
- Hello WebAssemply!
- Glimpse
- Tutorial: Online Visitors
- Tutorial: A Todo MVC Application using Iris and Vue.js
- Tutorial: URL Shortener using BoltDB
- Tutorial: How to turn your Android Device into a fully featured Web Server (MUST)
- POC: Convert the medium-sized project "Parrot" from native to Iris
- POC: Isomorphic react/hot reloadable/redux/css-modules starter kit
- Tutorial: DropzoneJS Uploader
- Tutorial: Caddy
- Tutorial:Iris Go Framework + MongoDB
- Tutorial: API for Apache Kafka
Nothing stops you from using your favorite folder structure. Iris is a low level web framework, it has got MVC first-class support but it doesn't limit your folder structure, this is your choice.
Structuring depends on your own needs. We can't tell you how to design your own application for sure but you're free to take a closer look to the examples below; you may find something useful that you can borrow for your app;
- Bootstrapper
- MVC with Repository and Service layer Overview
- Login (MVC with Single Responsibility package)
- Login (MVC with Datamodels, Datasource, Repository and Service layer)
- Common, with address
- UNIX socket file
- TLS
- Letsencrypt (Automatic Certifications)
- Notify on shutdown
- Custom TCP Listener
- Custom HTTP Server
- Graceful Shutdown
app.Get("{userid:int min(1)}", myHandler)
app.Post("{asset:path}", myHandler)
app.Put("{custom:string regexp([a-z]+)}", myHandler)
Note: unlike other routers you'd seen, iris' router can handle things like these:
// Matches all GET requests prefixed with "/assets/"
app.Get("/assets/{asset:path}", assetsWildcardHandler)
// Matches only GET "/"
app.Get("/", indexHandler)
// Matches only GET "/about"
app.Get("/about", aboutHandler)
// Matches all GET requests prefixed with "/profile/"
// and followed by a single path part
app.Get("/profile/{username:string}", userHandler)
// Matches only GET "/profile/me" because
// it does not conflict with /profile/{username:string}
// or the root wildcard {root:path}
app.Get("/profile/me", userHandler)
// Matches all GET requests prefixed with /users/
// and followed by a number which should be equal or bigger than 1
app.Get("/user/{userid:int min(1)}", getUserHandler)
// Matches all requests DELETE prefixed with /users/
// and following by a number which should be equal or bigger than 1
app.Delete("/user/{userid:int min(1)}", deleteUserHandler)
// Matches all GET requests except "/", "/about", anything starts with "/assets/" etc...
// because it does not conflict with the rest of the routes.
app.Get("{root:path}", rootWildcardHandler)
Navigate through examples for a better understanding.
- Overview
- Basic
- Controllers
- Custom HTTP Errors
- Dynamic Path
- Write your own custom parameter types
- Reverse routing
- Custom Router (high-level)
- Custom Wrapper UPDATED
- Custom Context
- Route State
- Writing a middleware
- Hello world
- Regexp NEW
- Session Controller
- Overview - Plus Repository and Service layers
- Login showcase - Plus Repository and Service layers
- Singleton
- Websocket Controller UPDATED
- Register Middleware
- Vue.js Todo MVC
- From func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- From http.Handler or http.HandlerFunc
- From func(http.HandlerFunc) http.HandlerFunc
- Overview
- Hi
- A simple Layout
- Layouts:
yield
andrender
tmpl funcs - The
urlpath
tmpl func - The
url
tmpl func - Inject Data Between Handlers
- Embedding Templates Into App Executable File
- Write to a custom
io.Writer
- Greeting with Pug (Jade)`
- Pug (Jade) Actions`
- Pug (Jade) Includes`
- Pug (Jade) Extends`
- Jet NEW
- Jet Embedded NEW
You can serve quicktemplate and hero templates files too, simply by using the context#ResponseWriter
, take a look at the http_responsewriter/quicktemplate and http_responsewriter/herotemplate examples.
- Favicon
- Basic UPDATED
- Embedding Files Into App Executable File UPDATED
- Embedding Gziped Files Into App Executable File UPDATED
- Send/Force-Download Files
- Single Page Applications
- Read JSON
- Read XML
- Read YAML NEW
- Read Form
- Read Query NEW
- Read Custom per type
- Read Custom via Unmarshaler
- Read Many times
- Upload/Read File
- Upload multiple files with an easy way
- Extract referrer from "referer" header or URL query parameter
The
context.Request()
returns the same *http.Request you already know, these examples show some places where the Context uses this object. Besides that you can use it as you did before iris.
- Content Negotiation NEW
- Write
valyala/quicktemplate
templates - Write
shiyanhui/hero
templates - Text, Markdown, HTML, JSON, JSONP, XML, Binary
- Write Gzip
- Stream Writer
- Transactions
- SSE
- SSE (third-party package usage for server sent events)
The
context/context#ResponseWriter()
returns an enchament version of a http.ResponseWriter, these examples show some places where the Context uses this object. Besides that you can use it as you did before iris.
- HTTP Method Override NEW
- Request Logger
- Localization and Internationalization
- Recovery
- Profiling (pprof)
- Internal Application File Logger
- Google reCAPTCHA
- Casbin wrapper
- Casbin middleware
- Cloudwatch
- CORS
- JWT
- Newrelic
- Prometheus
- Secure
- Tollboothic
- Cross-Site Request Forgery Protection
https://github.com/kataras/iris/tree/master/middleware#third-party-handlers
The httptest
package is your way for end-to-end HTTP testing, it uses the httpexpect library created by our friend, gavv.
iris cache library lives on its own package.
- Simple
- Client-Side (304) - part of the iris context core
You're free to use your own favourite caching package if you'd like so.
iris session manager lives on its own package.
You're free to use your own favourite sessions package if you'd like so.
- Basic NEW
- Native Messages UPDATED
- TLS Enabled
typescript automation tools have their own repository: https://github.com/kataras/iris/tree/master/typescript it contains examples
I'd like to tell you that you can use your favourite but I don't think you will find such a thing anywhere else.
Developers should read the godocs and https://docs.iris-go.com for a better understanding.
Psst, I almost forgot; do not forget to star or watch the project in order to stay updated with the latest tech trends, it never takes more than a second!