examples

module
v12.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2019 License: MIT

README

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.

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

Table of Contents

Examples are tested using Windows 10, Ubuntu 16.10 with Microsoft's Visual Studio Code and built using the Go 1.9.

Run

  1. Install the Go Programming Language, version 1.13 from here.
  2. Install Iris: go get github.com/kataras/iris/v12@latest
  3. Download the examples and copy-paste them to your $GOPATH/src/github.com/iris-contrib/examples

And run

$ cd $GOPATH/src/github.com/iris-contrib/examples/overview
$ 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

Su, 04 June 2017

This repository is just a minor of the https://github.com/kataras/iris/master/_examples folder.

Directories

Path Synopsis
apidoc
authentication
cache
client-side
Package main shows how you can use the `WriteWithExpiration` based on the "modtime", if it's newer than the request header then it will refresh the contents, otherwise will let the client (99.9% the browser) to handle the cache mechanism, it's faster than iris.Cache because server-side has nothing to do and no need to store the responses in the memory.
Package main shows how you can use the `WriteWithExpiration` based on the "modtime", if it's newer than the request header then it will refresh the contents, otherwise will let the client (99.9% the browser) to handle the cache mechanism, it's faster than iris.Cache because server-side has nothing to do and no need to store the responses in the memory.
configuration
convert-handlers
cookies
dependency-injection
jwt/contrib Module
desktop
webview Module
desktop-app
experimental-handlers
csrf
This middleware provides Cross-Site Request Forgery protection.
This middleware provides Cross-Site Request Forgery protection.
jwt
iris provides some basic middleware, most for your learning curve.
iris provides some basic middleware, most for your learning curve.
file-server
hero
http-listening
listen-letsencrypt
Package main provide one-line integration with letsencrypt.org
Package main provide one-line integration with letsencrypt.org
http-server
http3-quic Module
http_request
read-form
package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
read-json-struct-validation
Package main shows the validator(latest, version 9) integration with Iris.
Package main shows the validator(latest, version 9) integration with Iris.
read-query
package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
http_responsewriter
content-negotiation
Package main contains three different ways to render content based on the client's accepted.
Package main contains three different ways to render content based on the client's accepted.
herotemplate/template
Code generated by hero.
Code generated by hero.
sse
Package main shows how to send continuous event messages to the clients through SSE via a broker.
Package main shows how to send continuous event messages to the clients through SSE via a broker.
miscellaneous
mvc
middleware
Package main shows how you can add middleware to an mvc Application, simply by using its `Router` which is a sub router(an iris.Party) of the main iris app.
Package main shows how you can add middleware to an mvc Application, simply by using its `Router` which is a sub router(an iris.Party) of the main iris app.
middleware/per-method
If you want to use it as middleware for the entire controller you can use its router which is just a sub router to add it as you normally do with standard API: I'll show you 4 different methods for adding a middleware into an mvc application, all of those 4 do exactly the same thing, select what you prefer, I prefer the last code-snippet when I need the middleware to be registered somewhere else as well, otherwise I am going with the first one: “`go // 1 mvc.Configure(app.Party("/user"), func(m *mvc.Application) { m.Router.Use(cache.Handler(10*time.Second)) }) “` “`go // 2 // same: userRouter := app.Party("/user") userRouter.Use(cache.Handler(10*time.Second)) mvc.Configure(userRouter, ...) “` “`go // 3 // same: userRouter := app.Party("/user", cache.Handler(10*time.Second)) mvc.Configure(userRouter, ...) “` “`go // 4 // same: app.PartyFunc("/user", func(r iris.Party){ r.Use(cache.Handler(10*time.Second)) mvc.Configure(r, ...) }) “` If you want to use a middleware for a single route, for a single controller's method that is already registered by the engine and not by custom `Handle` (which you can add the middleware there on the last parameter) and it's not depend on the `Next Handler` to do its job then you just call it on the method: “`go var myMiddleware := myMiddleware.New(...) // this should return an iris/context.Handler type UserController struct{} func (c *UserController) GetSomething(ctx iris.Context) { // ctx.Proceed checks if myMiddleware called `ctx.Next()` // inside it and returns true if so, otherwise false.
If you want to use it as middleware for the entire controller you can use its router which is just a sub router to add it as you normally do with standard API: I'll show you 4 different methods for adding a middleware into an mvc application, all of those 4 do exactly the same thing, select what you prefer, I prefer the last code-snippet when I need the middleware to be registered somewhere else as well, otherwise I am going with the first one: “`go // 1 mvc.Configure(app.Party("/user"), func(m *mvc.Application) { m.Router.Use(cache.Handler(10*time.Second)) }) “` “`go // 2 // same: userRouter := app.Party("/user") userRouter.Use(cache.Handler(10*time.Second)) mvc.Configure(userRouter, ...) “` “`go // 3 // same: userRouter := app.Party("/user", cache.Handler(10*time.Second)) mvc.Configure(userRouter, ...) “` “`go // 4 // same: app.PartyFunc("/user", func(r iris.Party){ r.Use(cache.Handler(10*time.Second)) mvc.Configure(r, ...) }) “` If you want to use a middleware for a single route, for a single controller's method that is already registered by the engine and not by custom `Handle` (which you can add the middleware there on the last parameter) and it's not depend on the `Next Handler` to do its job then you just call it on the method: “`go var myMiddleware := myMiddleware.New(...) // this should return an iris/context.Handler type UserController struct{} func (c *UserController) GetSomething(ctx iris.Context) { // ctx.Proceed checks if myMiddleware called `ctx.Next()` // inside it and returns true if so, otherwise false.
middleware/without-ctx-next
Package main is a simple example of the behavior change of the execution flow of the handlers, normally we need the `ctx.Next()` to call the next handler in a route's handler chain, but with the new `ExecutionRules` we can change this default behavior.
Package main is a simple example of the behavior change of the execution flow of the handlers, normally we need the `ctx.Next()` to call the next handler in a route's handler chain, but with the new `ExecutionRules` we can change this default behavior.
regexp
Package main shows how to match "/xxx.json" in MVC handler.
Package main shows how to match "/xxx.json" in MVC handler.
orm
xorm
Package main shows how an orm can be used within your web app it just inserts a column and select the first.
Package main shows how an orm can be used within your web app it just inserts a column and select the first.
macros
Package main shows how you can register a custom parameter type and macro functions that belongs to it.
Package main shows how you can register a custom parameter type and macro functions that belongs to it.
sessions
structuring
subdomains
redirect
Package main shows how to register a simple 'www' subdomain, using the `app.WWW` method, which will register a router wrapper which will redirect all 'mydomain.com' requests to 'www.mydomain.com'.
Package main shows how to register a simple 'www' subdomain, using the `app.WWW` method, which will register a router wrapper which will redirect all 'mydomain.com' requests to 'www.mydomain.com'.
single
Package main register static subdomains, simple as parties, check ./hosts if you use windows
Package main register static subdomains, simple as parties, check ./hosts if you use windows
wildcard
Package main an example on how to catch dynamic subdomains - wildcard.
Package main an example on how to catch dynamic subdomains - wildcard.
www
testing
tutorial
view
template_html_3
Package main an example on how to naming your routes & use the custom 'url path' HTML Template Engine, same for other template engines.
Package main an example on how to naming your routes & use the custom 'url path' HTML Template Engine, same for other template engines.
template_html_4
Package main an example on how to naming your routes & use the custom 'url' HTML Template Engine, same for other template engines.
Package main an example on how to naming your routes & use the custom 'url' HTML Template Engine, same for other template engines.
template_jet_0
Package main shows how to use jet template parser with ease using the Iris built-in Jet view engine.
Package main shows how to use jet template parser with ease using the Iris built-in Jet view engine.
template_jet_1_embedded
Package main shows how to use jet templates embedded in your application with ease using the Iris built-in Jet view engine.
Package main shows how to use jet templates embedded in your application with ease using the Iris built-in Jet view engine.
template_pug_1
Package main shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
Package main shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
webassembly
websocket
socketio Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL