examples icon indicating copy to clipboard operation
examples copied to clipboard

This repository contains small and practical examples for the Iris Web Framework.

Examples

Build Status License CHANGELOG/HISTORY

This repository provides easy to understand code snippets on how to get started with web development with the Go programming language using the Iris web framework. This branch contains the latest iris master examples. For the stable's version examples navigate through the v12 branch.

To read the Iris documentation please navigate to the wiki pages instead.

Examples are tested using Windows 11, Ubuntu 22.04 LTS, macOS 12 Monterey with Microsoft's Visual Studio Code and built using the Go 1.19.rc2.

Table of Contents

  • Serverless
  • REST API for Apache Kafka
  • URL Shortener
  • Dropzone.js
  • Caddy
  • Bootstrapper
  • Project Structure :fire:
  • Monitor
    • Simple Process Monitor (includes UI) NEW
    • Heap, MSpan/MCache, Size Classes, Objects, Goroutines, GC/CPU fraction (includes UI) NEW
  • Database
    • MySQL, Groupcache & Docker
    • MongoDB
    • Sqlx
    • Gorm
    • Reform
    • x/sqlx NEW
  • HTTP Server
    • HOST:PORT
    • Public Test Domain
    • UNIX socket file
    • TLS
    • Letsencrypt (Automatic Certifications)
    • Socket Sharding (SO_REUSEPORT)
    • Graceful Shutdown
    • Notify on shutdown
    • Custom TCP Listener
      • Common net.Listener
    • Custom HTTP Server
      • Pass a custom Server
      • Use Iris as a single http.Handler
      • Multi Instances
      • HTTP/3 Quic
      • H2C NEW
    • Timeout
  • HTTP Client
    • Weather Client
  • Configuration
    • Functional
    • Configuration Struct
    • Using Viper
    • Import from YAML
      • Share Configuration across instances
    • Import from TOML
    • Multi Environment Configuration NEW
  • Routing
    • Party Controller NEW
    • Overview
    • Basic
    • Custom HTTP Errors
    • HTTP Wire Errors NEW
      • Custom Validation Errors
    • Not Found - Intelligence
      • Not Found - Suggest Closest Paths
    • Dynamic Path
      • Root Wildcard
      • Implement a Parameter Type
      • Same Path Pattern but Func
    • Middleware
      • Per Route
      • Globally
      • Remove a Handler
      • Share Values
        • Share Services
        • Share Functions
      • Handlers Execution Rule
      • Route Register Rule
      • Convert net/http Handlers
        • From func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
        • From http.Handler or http.HandlerFunc
        • From func(http.Handler) http.Handler
        • Convert by your own: sentry/raven middleware
    • Rewrite Middleware
    • Route State
    • Remove Route
    • Reverse Routing
    • Router Wrapper
    • Custom Router
    • Subdomains
      • Single
      • Multi
      • Wildcard
      • WWW
        • WWW Method
      • Redirection
        • Multi Instances
      • HTTP Errors View
    • HTTP Method Override
    • API Versioning
    • Sitemap
  • Logging
    • Application File Logger
    • Application JSON Logger
    • Rollbar
    • AccessLog
      • Log Requests to a JSON File
      • Using Log Rotation and more
      • Custom Fields and Template
      • Listen and render Logs to a Client
      • The CSV Formatter
      • Create your own Formatter
      • Root and Proxy AccessLog instances
      • Slack integration example
  • API Documentation
  • Testing
  • Recovery
    • Panic and custom Error Handler with Compression
  • Profiling
  • File Server
    • File Server
    • HTTP/2 Push Targets
    • HTTP/2 Push Targets (Embedded)
    • HTTP/2 Push Targets (Gzipped Embedded)
    • Favicon
    • Basic
    • Embedding Files Into App Executable File
    • Embedding Gzipped Files Into App Executable File
    • Send Files (rate limiter included)
    • Single Page Applications
      • Vue Router
      • Basic SPA
      • Embedded Single Page Application and iris.PrefixDir
      • Embedded Single Page Application with other routes
    • Upload File
    • Upload Multiple Files
    • WebDAV
  • View
    • Overview
    • Layout
      • Ace
      • Amber
      • Blocks
      • Django
      • Handlebars
      • HTML
      • Jet
      • Pug
    • Basic
    • A simple Layout
    • Layouts: yield and render tmpl funcs
    • The urlpath template func
      • HTML
      • Django
    • The url template func
    • Inject Data Between Handlers
    • Inject Engine Between Handlers
    • Embedding Templates Into App Executable File
    • Write to a custom io.Writer
    • Parse a Template from Text
      • HTML, Pug and Ace
      • Django
      • Amber
      • Jet
      • Handlebars
    • Blocks
    • Blocks Embedded
    • Pug: Actions
    • Pug: Includes
    • Pug Embedded`
    • Ace
    • Django
    • Amber
    • Amber Embedded
    • Jet
    • Jet Embedded
    • Jet 'urlpath' tmpl func
    • Jet Template Funcs from Struct
    • Handlebars
    • Third-Parties
      • Render valyala/quicktemplate templates
      • Render shiyanhui/hero templates
  • Request ID
  • Request Rate Limit
  • Request Referrer
  • Webassembly
  • Request Body
    • Bind JSON
      • JSON Stream and disable unknown fields
      • Struct Validation
    • Bind XML
    • Bind MsgPack
    • Bind YAML
    • Bind Form
      • Checkboxes
    • Bind Query
    • Bind Params
    • Bind URL
    • Bind Headers
    • Bind Body
    • Add Converter
    • Bind Custom per type
    • Bind Custom via Unmarshaler
    • Bind Many times
  • Response Writer
    • Content Negotiation
    • Text, Markdown, YAML, HTML, JSON, JSONP, Msgpack, XML and Binary
    • Protocol Buffers
    • HTTP/2 Server Push
    • Stream Writer
    • Server-Sent Events
      • SSE 3rd-party (r3labs/sse)
      • SSE 3rd-party (alexandrevicenzi/go-sse)
    • Cache
      • Simple
      • Client-Side (304)
  • Compression
    • Server-Side
    • Client-Side
    • Client-Side (using Iris)
  • Localization and Internationalization
    • Basic
    • Ttemplates and Functions
    • Pluralization and Variables
  • Authentication, Authorization & Bot Detection
    • Recommended: Auth package and Single-Sign-On NEW (GO 1.18 Generics required)
    • Basic Authentication
      • Basic
      • Load from a slice of Users
      • Load from a file & encrypted passwords
      • Fetch & validate a User from a Database (MySQL)
    • CORS
    • JSON Web Tokens
      • Basic
      • Middleware
      • Blocklist
      • Refresh Token
      • Tutorial
    • JWT (community edition)
    • OAUth2
    • Manage Permissions
    • Google reCAPTCHA
    • hCaptcha
  • Cookies
    • Basic
    • Options
    • Encode/Decode (with securecookie)
  • Sessions
    • Overview: Config
      • Overview: Routes
    • Basic
    • Secure Cookie
    • Flash Messages
    • Databases
      • Badger
      • BoltDB
      • Redis
    • View Data
  • Websocket
    • Gorilla FileWatch (3rd-party)
    • Basic
      • Server
      • Go Client
      • Browser Client
      • Browser NPM Client (browserify)
    • Native Messages
    • TLS
    • Online Visitors
  • Dependency Injection
    • Overview (Movies Service)
    • Basic
      • Middleware
    • Sessions
    • Smart Contract
    • JWT
      • JWT (iris-contrib)
    • Register Dependency from Context
  • MVC
    • Overview
    • Repository and Service layers
    • Hello world
    • Basic
      • Wildcard
    • Default request values
    • Singleton
    • Regexp
    • Session Controller
    • Authenticated Controller
    • Versioned Controller
    • Websocket Controller
      • Websocket + Authentication (Single-Sign-On) NEW (GO 1.18 Generics required)
    • Register Middleware
    • gRPC
    • gRPC Bidirectional Stream
    • Login (Repository and Service layers)
    • Login (Single Responsibility)
    • Vue.js Todo App
    • HTTP Error Handler
    • Error Handler
    • Handle errors using mvc.Result
    • Handle errors using PreflightResult
    • Handle errors by hijacking the result
  • Desktop Applications
    • The blink package
    • The lorca package
    • The webview package
  • Middlewares (Community)

Run

  1. Install the Go Programming Language, version 1.18+ from here.
  2. Download the examples and copy-paste them to your $GOPATH/src/github.com/iris-contrib/examples
  3. Install Iris with go get -u github.com/kataras/iris/[email protected]

To run an example, open a terminal session and execute:

$ cd $GOPATH/src/github.com/iris-contrib/examples/compression
$ go mod init
$ go run main.go

Do not forget to star or watch the Iris project.

Any troubles with examples?

https://github.com/iris-contrib/examples/issues