2017-03-13 14:16:12 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/cache"
|
2020-09-10 10:24:23 +02:00
|
|
|
"github.com/kataras/iris/v12/middleware/basicauth"
|
2017-03-13 14:16:12 +01:00
|
|
|
)
|
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
var markdownContents = []byte(`## Hello Markdown
|
2017-03-13 14:16:12 +01:00
|
|
|
|
|
|
|
This is a sample of Markdown contents
|
|
|
|
|
|
|
|
Features
|
|
|
|
--------
|
|
|
|
|
|
|
|
All features of Sundown are supported, including:
|
|
|
|
|
|
|
|
* **Compatibility**. The Markdown v1.0.3 test suite passes with
|
|
|
|
the --tidy option. Without --tidy, the differences are
|
|
|
|
mostly in whitespace and entity escaping, where blackfriday is
|
|
|
|
more consistent and cleaner.
|
2020-09-10 10:24:23 +02:00
|
|
|
`)
|
2017-03-13 14:16:12 +01:00
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Cache should not be used on handlers that contain dynamic data.
|
|
|
|
// Cache is a good and a must-feature on static content, i.e "about page" or for a whole blog site.
|
2017-03-13 14:16:12 +01:00
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2017-11-02 04:50:56 +01:00
|
|
|
app.Logger().SetLevel("debug")
|
2017-07-10 17:32:42 +02:00
|
|
|
app.Get("/", cache.Handler(10*time.Second), writeMarkdown)
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// saves its content on the first request and serves it instead of re-calculating the content.
|
2019-06-07 20:07:08 +02:00
|
|
|
// After 10 seconds it will be cleared and reset.
|
2017-03-13 14:16:12 +01:00
|
|
|
|
2020-09-10 10:24:23 +02:00
|
|
|
pages := app.Party("/pages")
|
|
|
|
pages.Use(cache.Handler(10 * time.Second)) // Per Party.
|
|
|
|
pages.Get("/", pagesIndex)
|
|
|
|
pages.Post("/", pagesIndexPost)
|
|
|
|
|
|
|
|
// Note: on authenticated requests
|
|
|
|
// the cache middleare does not run at all (see iris/cache/ruleset).
|
|
|
|
auth := basicauth.Default(map[string]string{
|
|
|
|
"admin": "admin",
|
|
|
|
})
|
|
|
|
app.Get("/protected", auth, cache.Handler(5*time.Second), protected)
|
|
|
|
|
|
|
|
// Set custom cache key/identifier,
|
|
|
|
// for the sake of the example
|
|
|
|
// we will SHARE the keys on both GET and POST routes
|
|
|
|
// so the first one is executed that's the body
|
|
|
|
// for both of the routes. Please don't do that
|
|
|
|
// on production, this is just an example.
|
|
|
|
custom := app.Party("/custom")
|
|
|
|
custom.Use(cache.WithKey("shared"))
|
|
|
|
custom.Use(cache.Handler(10 * time.Second))
|
|
|
|
custom.Get("/", customIndex)
|
|
|
|
custom.Post("/", customIndexPost)
|
|
|
|
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
}
|
2017-03-13 14:16:12 +01:00
|
|
|
|
2017-08-27 19:35:23 +02:00
|
|
|
func writeMarkdown(ctx iris.Context) {
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// tap multiple times the browser's refresh button and you will
|
|
|
|
// see this println only once every 10 seconds.
|
|
|
|
println("Handler executed. Content refreshed.")
|
2017-03-13 14:16:12 +01:00
|
|
|
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
ctx.Markdown(markdownContents)
|
2017-03-13 14:16:12 +01:00
|
|
|
}
|
2018-01-25 15:19:45 +01:00
|
|
|
|
2020-09-10 10:24:23 +02:00
|
|
|
func pagesIndex(ctx iris.Context) {
|
|
|
|
println("Handler executed. Content refreshed.")
|
|
|
|
ctx.WriteString("GET: hello")
|
|
|
|
}
|
|
|
|
|
|
|
|
func pagesIndexPost(ctx iris.Context) {
|
|
|
|
println("Handler executed. Content refreshed.")
|
|
|
|
ctx.WriteString("POST: hello")
|
|
|
|
}
|
|
|
|
|
|
|
|
func protected(ctx iris.Context) {
|
|
|
|
username, _, _ := ctx.Request().BasicAuth()
|
|
|
|
ctx.Writef("Hello, %s!", username)
|
|
|
|
}
|
|
|
|
|
|
|
|
func customIndex(ctx iris.Context) {
|
|
|
|
ctx.WriteString("Contents from GET custom index")
|
|
|
|
}
|
|
|
|
|
|
|
|
func customIndexPost(ctx iris.Context) {
|
|
|
|
ctx.WriteString("Contents from POST custom index")
|
|
|
|
}
|
|
|
|
|
2019-06-21 18:43:25 +02:00
|
|
|
/* Note that `HandleDir` does use the browser's disk caching by-default
|
|
|
|
therefore, register the cache handler AFTER any HandleDir calls,
|
2018-01-25 15:19:45 +01:00
|
|
|
for a faster solution that server doesn't need to keep track of the response
|
2023-08-20 02:12:46 +02:00
|
|
|
navigate to https://github.com/kataras/iris/blob/main/_examples/cache/client-side/main.go.
|
2020-09-10 10:24:23 +02:00
|
|
|
|
|
|
|
The `HandleDir` has its own cache mechanism, read the 'file-server' examples. */
|