Add notes for the new lead maintainer of the open-source iris project and align with @get-ion/ion by @hiveminded
Former-commit-id: da4f38eb9034daa49446df3ee529423b98f9b331
3
.gitattributes
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.go linguist-language=Go
|
||||
vendor/* linguist-vendored
|
||||
_examples/* linguist-documentation
|
6
.github/CODEOWNERS
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# These owners will be the default owners for everything in the repo.
|
||||
* @kataras
|
||||
*.go @hiveminded @kataras
|
||||
*.md @hiveminded @kataras
|
||||
*.html @hiveminded @kataras
|
||||
*.css @hiveminded @kataras
|
75
.github/CONTRIBUTING.md
vendored
|
@ -1 +1,74 @@
|
|||
Please navigate through https://github.com/iris-contrib/community-board first to read how you can contribute. You're awesome!
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at kataras2006@hotmail.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
7
.github/ISSUE_TEMPLATE.md
vendored
|
@ -1,5 +1,2 @@
|
|||
**Do not create** issues or proposals neither request features **here**.
|
||||
|
||||
Navigate to the https://github.com/iris-contrib/community-board instead.
|
||||
|
||||
[FAQ](https://github.com/iris-contrib/community-board#community-board)
|
||||
Documentation for the _iris_ project can be found at
|
||||
<https://github.com/kataras/iris#-learn>.
|
8
.github/PULL_REQUEST_TEMPLATE.md
vendored
|
@ -1,7 +1,3 @@
|
|||
I'd love to see more contributions!
|
||||
We'd love to see contributions!!!
|
||||
|
||||
Please read [how to create a Proposal](https://github.com/iris-contrib/community-board#creating-a-proposal) first, PR may be rejected if it's not designed as it should.
|
||||
|
||||
If you are interested in contributing to the Iris project, please take a time to read and understand the [Code of Conduct](https://github.com/iris-contrib/community-board/blob/master/CODE-OF-CONDUCT.md) before submitting your [PR](https://github.com/kataras/iris/pulls), this is how we make Go great.
|
||||
|
||||
Thanks!
|
||||
Please attach an [issue](http://support.iris-go.com) link which your PR solves otherwise your work may be rejected.
|
4
.gitignore
vendored
|
@ -1,4 +0,0 @@
|
|||
# my own configuration for vs code, my lovely editor, if someone of you want this, contact with me
|
||||
.vscode
|
||||
# turn off these for now
|
||||
specs
|
38
.travis.yml
|
@ -4,22 +4,30 @@ os:
|
|||
- osx
|
||||
go:
|
||||
- go1.8
|
||||
- tip
|
||||
go_import_path: github.com/kataras/iris
|
||||
install:
|
||||
- go get ./...
|
||||
# install test dependencies
|
||||
# - go get golang.org/x/tools/cmd/cover
|
||||
# - go get -v github.com/axw/gocov
|
||||
# - go install github.com/axw/gocov/gocov
|
||||
- go get ./... # for iris-contrib/httpexpect
|
||||
script:
|
||||
# - gocov test | gocov report
|
||||
# the result of gocov is invalid because it tests the vendor too,
|
||||
# which its tests are removed to reduce the dl size.
|
||||
# When I'll push my internal tests to github I'll do it
|
||||
# to do the test coverage all folders except vendor.
|
||||
# For now keep it commented.
|
||||
# - cd ./_examples
|
||||
# - go get ./...
|
||||
# - go test -v -cover ./...
|
||||
# - cd ./...
|
||||
- go test -v -cover ./...
|
||||
after_script:
|
||||
# examples
|
||||
- cd ./_examples
|
||||
- go get ./...
|
||||
- go test -v -cover ./...
|
||||
# cache examples
|
||||
- cd ../cache/_examples
|
||||
- go get ./...
|
||||
- go test -v -cover ./...
|
||||
# sessions examples
|
||||
- cd ../../sessions/_examples
|
||||
- go get ./...
|
||||
- go test -v -cover ./...
|
||||
# websocket examples
|
||||
- cd ../../websocket/_examples
|
||||
- go get ./...
|
||||
- go test -v -cover ./...
|
||||
# typescript examples
|
||||
- cd ../../typescript/_examples
|
||||
- go get ./...
|
||||
- go test -v -cover ./...
|
89
ACQUIRED_HISTORY.md
Normal file
|
@ -0,0 +1,89 @@
|
|||
# 10 July 2017
|
||||
|
||||
## 📈 One and a half years with Iris and You...
|
||||
|
||||
- 7070 github stars
|
||||
- 749 github forks
|
||||
- 1m total views at its documentation
|
||||
- ~800$ at donations (there're a lot for a golang open-source project, thanks to you)
|
||||
- ~550 reported bugs fixed
|
||||
- ~30 community feature requests have been implemented
|
||||
|
||||
## 🔥 Reborn
|
||||
|
||||
As you may have heard I have huge responsibilities on my new position at Dubai nowdays, therefore I don't have the needed time to work on this project anymore.
|
||||
|
||||
After almost a month of negotiations and searching I succeed to find a decent software engineer to continue my work on the open source community.
|
||||
|
||||
The leadership of this, open-source, repository was transfered to [hiveminded](https://github.com/hiveminded).
|
||||
|
||||
These types of projects need heart and sacrifices to continue offer the best developer experience like a paid software, please do support him as you did with me!
|
||||
|
||||
# 02 July 2017
|
||||
|
||||
### DEPRECATED
|
||||
|
||||
Iris has been acquired so development is up to the community, there are two active iris-based communities so far.
|
||||
|
||||
Use one of these projects instead:
|
||||
|
||||
https://github.com/get-ion/ion
|
||||
|
||||
**Ion is a fast, simple and efficient micro web framework for Go. It provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.**
|
||||
|
||||
- a bit faster than Iris version 7, based on `ab`
|
||||
- stable api
|
||||
- more examples
|
||||
- sessions, websockets, typescript and cloud editor(fixed) on different packages
|
||||
- test cov, including examples
|
||||
- slack bot for support automation
|
||||
- has a FAQ page which is part of the gitbook.com beta program
|
||||
- central issue portal
|
||||
- HuHu supported
|
||||
|
||||
https://github.com/go-siris/siris
|
||||
|
||||
**A fast, cross-platform and efficient web framework with robust set of well-designed features, written entirely in Go.**
|
||||
|
||||
- three maintainers
|
||||
- plan to stabilize api, no unneeded changes
|
||||
- plan to increase test-coverage
|
||||
- plan to add more middlewares and examples
|
||||
|
||||
|
||||
> If your team's project is missing from this list, please contact with me.
|
||||
|
||||
# 17 June 2017
|
||||
|
||||
### IRIS HAS BEEN ACQUIRED
|
||||
|
||||
Iris project has been acquired by a Dubai-based startup.
|
||||
|
||||
Both sides agree that every related public data should remain open for at least 30 days.
|
||||
|
||||
After the period of 30 days, company has the proprietary rights to delete or transfer this repository and all its related public data forever without any warnings.
|
||||
|
||||
The company may or may not reveal its true identity to the public.
|
||||
|
||||
Transaction of the public domains still in-progress:
|
||||
|
||||
- http://iris-go.com
|
||||
- https://kataras.rocket.chat/channel/iris
|
||||
|
||||
View-accessed users can clone the current state of the project's public repositories and use without any warranties.
|
||||
|
||||
From now on, Original Author owns a high position to the company's table.
|
||||
|
||||
At any circumstances,
|
||||
|
||||
Original Author keeps the creation rights.
|
||||
|
||||
### About the future of Iris
|
||||
|
||||
Clone the repository today because if I can't find a new lead maintainer for the [v7.2](https://github.com/kataras/iris-v7-29d) you, as community, will have to find a way to communicate about its future, the name "iris go" was taken by the company too, so it will be nice if the future main contributor change its name too, if you don't do it I will not beat you but I don't know the full company's law-plan for this, yet.
|
||||
|
||||
All donators, without any exception, will have my support for at least 6 months (for all iris versions), we have a private room at the [chat](https://kataras.rocket.chat/channel/iris).
|
||||
|
||||
Don't worry **I will not let you down**, we're trying to find a decent open-source contributor to continue the Iris' open-source codebase. I'm already in touch with some good gophers but **If you're willing to maintain this project** please [send](#contact) me details about your experience, general bio and your github username.
|
||||
|
||||
**I am really thankful for all of your support to me and the community, all donations, all bug reports, all comments without any exception. I did proceeded with all my physical abilities so far but unfortunately there weren't enough for my survivor. I'm really sorry if the latest news made iris open-source community disappointed but you have to see things from my point view, I was one step before bankruptcy, I had no other choice but accept the offer.**
|
5
AUTHORS
Normal file
|
@ -0,0 +1,5 @@
|
|||
# This is the official list of Iris authors for copyright
|
||||
# purposes.
|
||||
|
||||
Gerasimos Maropoulos <kataras2006@hotmail.com>
|
||||
Bill Qeras, Jr. <hiveminded@tutanota.com>
|
|
@ -1,41 +0,0 @@
|
|||
# Iris Open Source Code of Conduct
|
||||
|
||||
This code of conduct outlines expectations for participation in kataras-managed open source communities, as well as steps for reporting unacceptable behavior. We are committed to providing a welcoming and inspiring community for all. People violating this code of conduct may be banned from the community.
|
||||
|
||||
Our open source communities strive to:
|
||||
|
||||
* **Be friendly and patient**: Remember you might not be communicating in someone else's primary spoken or programming language, and others may not have your level of understanding.
|
||||
* **Be welcoming**: Our communities welcome and support people of all backgrounds and identities. This includes, but is not limited to members of any race, ethnicity, culture, national origin, color, immigration status, social and economic class, educational level, sex, sexual orientation, gender identity and expression, age, size, family status, political belief, religion, and mental and physical ability.
|
||||
* **Be respectful**: We are a world-wide community of professionals, and we conduct ourselves professionally. Disagreement is no excuse for poor behavior and poor manners. Disrespectful and unacceptable behavior includes, but is not limited to:
|
||||
* Violent threats or language.
|
||||
* Discriminatory or derogatory jokes and language.
|
||||
* Posting sexually explicit or violent material.
|
||||
* Posting, or threatening to post, people's personally identifying information ("doxing").
|
||||
* Insults, especially those using discriminatory terms or slurs.
|
||||
* Behavior that could be perceived as sexual attention.
|
||||
* Advocating for or encouraging any of the above behaviors.
|
||||
* **Understand disagreements**: Disagreements, both social and technical, are useful learning opportunities. Seek to understand the other viewpoints and resolve differences constructively.
|
||||
* This code is not exhaustive or complete. It serves to capture our common understanding of a productive, collaborative environment. We expect the code to be followed in spirit as much as in the letter.
|
||||
|
||||
## Scope
|
||||
|
||||
This code of conduct applies to all repos and communities for kataras-managed open source projects regardless of whether or not the repo explicitly calls out its use of this code. The code also applies in public spaces when an individual is representing a project or its community. Examples include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
||||
|
||||
|
||||
## Reporting Code of Conduct Issues
|
||||
|
||||
We encourage all communities to resolve issues on their own whenever possible. This builds a broader and deeper understanding and ultimately a healthier interaction. In the event that an issue cannot be resolved locally, please feel free to report your concerns by mail to kataras2006@hotmail.com or kataras@tutanota.com (secure way).
|
||||
|
||||
In your report please include:
|
||||
|
||||
* Your contact information.
|
||||
* Names (real, usernames or pseudonyms) of any individuals involved. If there are additional witnesses, please include them as well.
|
||||
* Your account of what occurred, and if you believe the incident is ongoing. If there is a publicly available record (e.g. a mailing list archive or a public chat log), please include a link or attachment.
|
||||
* Any additional information that may be helpful.
|
||||
|
||||
|
||||
All reports will be reviewed by [kataras](https://github.com/kataras) and will result in a response that is deemed necessary and appropriate to the circumstances. Where additional perspectives are needed, I may seek insight from others with relevant expertise or experience. The confidentiality of the person reporting the incident will be kept at all times. Involved parties are never part of the review team.
|
||||
|
||||
Anyone asked to stop unacceptable behavior is expected to comply immediately. If an individual engages in **unacceptable behavior**, the review team may take any action they deem appropriate, **including a permanent ban from the community**.
|
||||
|
||||
This code of conduct is based on the [template](http://todogroup.org/opencodeofconduct) established by the [TODO Group](http://todogroup.org/) and used by numerous other large communities (e.g., [Facebook](https://code.facebook.com/pages/876921332402685/open-source-code-of-conduct), [Yahoo](https://yahoo.github.io/codeofconduct), [Twitter](https://engineering.twitter.com/opensource/code-of-conduct), [GitHub](http://todogroup.org/opencodeofconduct/#opensource@github.com)) and the Scope section from the [Contributor Covenant version 1.4](http://contributor-covenant.org/version/1/4/).
|
5
Dockerfile
Normal file
|
@ -0,0 +1,5 @@
|
|||
FROM irisgo/cloud-native-go:latest
|
||||
|
||||
ENV APPSOURCES /go/src/github.com/iris-contrib/cloud-native-go
|
||||
|
||||
RUN ${APPSOURCES}/cloud-native-go
|
12
Dockerfile.build
Normal file
|
@ -0,0 +1,12 @@
|
|||
FROM golang:1.8.3-alpine
|
||||
|
||||
RUN apk update && apk upgrade && apk add --no-cache bash git
|
||||
RUN go get github.com/iris-contrib/cloud-native-go
|
||||
|
||||
ENV SOURCES /go/src/github.com/iris-contrib/cloud-native-go
|
||||
# COPY . ${SOURCES}
|
||||
|
||||
RUN cd ${SOURCES} $$ CGO_ENABLED=0 go build
|
||||
|
||||
ENTRYPOINT cloud-native-go
|
||||
EXPOSE 8080
|
303
Gopkg.lock
generated
|
@ -1,303 +0,0 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/BurntSushi/toml"
|
||||
packages = ["."]
|
||||
revision = "b26d9c308763d68093482582cea63d69be07a0f0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Joker/jade"
|
||||
packages = ["."]
|
||||
revision = "35b3f5bdbcc920cd31f4870536dbc63be8530541"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Unknwon/i18n"
|
||||
packages = ["."]
|
||||
revision = "8372b908b5876d26cfa46a85fc4851b981dad102"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ajg/form"
|
||||
packages = ["."]
|
||||
revision = "523a5da1a92f01b01f840b61689c0340a0243532"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/aymerick/raymond"
|
||||
packages = [".","ast","lexer","parser"]
|
||||
revision = "72acac2207479d21dd45898c2a4264246c818148"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/eknkc/amber"
|
||||
packages = [".","parser"]
|
||||
revision = "f0d8fdb67f9f4a2c0d02fb6ce4830b8b6754de10"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/esemplastic/unis"
|
||||
packages = [".","logger"]
|
||||
revision = "6e30ed034e8cb31227b24057d030fdd0261bcfc6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/fatih/structs"
|
||||
packages = ["."]
|
||||
revision = "74a29b9fac7397d933f47e33eba94d2d83a464a2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/flosch/pongo2"
|
||||
packages = ["."]
|
||||
revision = "1d0f0d3af150c4a65dfd424d742f7374819e7d29"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/garyburd/redigo"
|
||||
packages = ["internal","redis"]
|
||||
revision = "433969511232c397de61b1442f9fd49ec06ae9ba"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/gavv/monotime"
|
||||
packages = ["."]
|
||||
revision = "47d58efa69556a936a3c15eb2ed42706d968ab01"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/context"
|
||||
packages = ["."]
|
||||
revision = "624d99b1798d7c5375ea1d3ca4c5b04d58f7c775"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/errors"
|
||||
packages = ["."]
|
||||
revision = "99fa440517e8f3d1e4cd8d6dbed6b41f4c1ed3d6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/filepersist"
|
||||
packages = ["."]
|
||||
revision = "c5f0cd24e7991579ba6f5f1bd20a1ad2c9f06cd4"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/golog"
|
||||
packages = ["."]
|
||||
revision = "cca714f7feb5df8e455f409b549d384441ac4578"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/hex"
|
||||
packages = ["."]
|
||||
revision = "083fba3033ad473db3dd31c9bb368473d37581a7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/hidden"
|
||||
packages = ["."]
|
||||
revision = "d52a649ab33af200943bb599898dbdcfdbc94cb7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/ops"
|
||||
packages = ["."]
|
||||
revision = "b70875f5d689a9438bca72aefd7142a2af889b18"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/getlantern/stack"
|
||||
packages = ["."]
|
||||
revision = "02f928aad224fbccd50d66edd776fc9d1e9f2f2b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/google/go-querystring"
|
||||
packages = ["query"]
|
||||
revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gorilla/websocket"
|
||||
packages = ["."]
|
||||
revision = "3ab3a8b8831546bd18fd182c20687ca853b2bb13"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/imdario/mergo"
|
||||
packages = ["."]
|
||||
revision = "3e95a51e0639b4cf372f2ccf74c86749d747fbdc"
|
||||
version = "0.2.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/imkira/go-interpol"
|
||||
packages = ["."]
|
||||
revision = "5accad8134979a6ac504d456a6c7f1c53da237ca"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/iris-contrib/httpexpect"
|
||||
packages = ["."]
|
||||
revision = "ed44d3c477393b96a598a38730f128dffee33068"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/juju/errors"
|
||||
packages = ["."]
|
||||
revision = "8234c829496aaeae67c5c71235a2cbcc289e960a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/klauspost/compress"
|
||||
packages = ["flate","gzip"]
|
||||
revision = "f3dce52e0576655d55fd69e74b63da96ad1108f3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/klauspost/cpuid"
|
||||
packages = ["."]
|
||||
revision = "09cded8978dc9e80714c4d85b0322337b0a1e5e0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/microcosm-cc/bluemonday"
|
||||
packages = ["."]
|
||||
revision = "e79763773ab6222ca1d5a7cbd9d62d83c1f77081"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/monoculum/formam"
|
||||
packages = ["."]
|
||||
revision = "334e05a3c7f95d500715d7c0405937ac933b28cb"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/moul/http2curl"
|
||||
packages = ["."]
|
||||
revision = "4e24498b31dba4683efb9d35c1c8a91e2eda28c8"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pmezard/go-difflib"
|
||||
packages = ["difflib"]
|
||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/russross/blackfriday"
|
||||
packages = ["."]
|
||||
revision = "0ba0f2b6ed7c475a92e4df8641825cb7a11d1fa3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/satori/go.uuid"
|
||||
packages = ["."]
|
||||
revision = "5bf94b69c6b68ee1b541973bb8e1144db23a194b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/sergi/go-diff"
|
||||
packages = ["diffmatchpatch"]
|
||||
revision = "feef008d51ad2b3778f85d387ccf91735543008d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/stretchr/testify"
|
||||
packages = ["assert","require"]
|
||||
revision = "f6abca593680b2315d2075e0f5e2a9751e3f431a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/valyala/bytebufferpool"
|
||||
packages = ["."]
|
||||
revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/xeipuuv/gojsonpointer"
|
||||
packages = ["."]
|
||||
revision = "6fe8760cad3569743d51ddbb243b26f8456742dc"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/xeipuuv/gojsonreference"
|
||||
packages = ["."]
|
||||
revision = "e02fc20de94c78484cd5ffb007f8af96be030a45"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/xeipuuv/gojsonschema"
|
||||
packages = ["."]
|
||||
revision = "0c8571ac0ce161a5feb57375a9cdf148c98c0f70"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yalp/jsonpath"
|
||||
packages = ["."]
|
||||
revision = "31a79c7593bb93eb10b163650d4a3e6ca190e4dc"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/yudai/gojsondiff"
|
||||
packages = [".","formatter"]
|
||||
revision = "7b1b7adf999dab73a6eb02669c3d82dbb27a3dd6"
|
||||
version = "1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yudai/golcs"
|
||||
packages = ["."]
|
||||
revision = "ecda9a501e8220fae3b4b600c3db4b0ba22cfc68"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = ["acme","acme/autocert"]
|
||||
revision = "e1a4589e7d3ea14a3352255d04b6f1a418845e5e"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = ["html","html/atom","idna","publicsuffix"]
|
||||
revision = "e4fa1c5465ad6111f206fc92186b8c83d64adbe1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/text"
|
||||
packages = ["internal/gen","internal/triegen","internal/ucd","secure/bidirule","transform","unicode/bidi","unicode/cldr","unicode/norm","unicode/rangetable"]
|
||||
revision = "ccbd3f7822129ff389f8ca4858a9b9d4d910531c"
|
||||
|
||||
[[projects]]
|
||||
name = "gopkg.in/ini.v1"
|
||||
packages = ["."]
|
||||
revision = "d3de07a94d22b4a0972deb4b96d790c2c0ce8333"
|
||||
version = "v1.28.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/PuerkitoBio/goquery"
|
||||
packages = ["."]
|
||||
revision = "2dc93891ab3bcc1dbc2cbf9bc6376c37f6e6f289"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "415eba3367a3b497ce9c74414ba802d5902d5b7fefc7dfc99cff6af102ec40fe"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
179
Gopkg.toml
|
@ -1,179 +0,0 @@
|
|||
|
||||
## Gopkg.toml example (these lines may be deleted)
|
||||
|
||||
## "metadata" defines metadata about the project that could be used by other independent
|
||||
## systems. The metadata defined here will be ignored by dep.
|
||||
# [metadata]
|
||||
# key1 = "value that convey data to other systems"
|
||||
# system1-data = "value that is used by a system"
|
||||
# system2-data = "value that is used by another system"
|
||||
|
||||
## "required" lists a set of packages (not projects) that must be included in
|
||||
## Gopkg.lock. This list is merged with the set of packages imported by the current
|
||||
## project. Use it when your project needs a package it doesn't explicitly import -
|
||||
## including "main" packages.
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
|
||||
## "ignored" lists a set of packages (not projects) that are ignored when
|
||||
## dep statically analyzes source code. Ignored packages can be in this project,
|
||||
## or in a dependency.
|
||||
# ignored = ["github.com/user/project/badpkg"]
|
||||
|
||||
## Constraints are rules for how directly imported projects
|
||||
## may be incorporated into the depgraph. They are respected by
|
||||
## dep whether coming from the Gopkg.toml of the current project or a dependency.
|
||||
# [[constraint]]
|
||||
## Required: the root import path of the project being constrained.
|
||||
# name = "github.com/user/project"
|
||||
#
|
||||
## Recommended: the version constraint to enforce for the project.
|
||||
## Only one of "branch", "version" or "revision" can be specified.
|
||||
# version = "1.0.0"
|
||||
# branch = "master"
|
||||
# revision = "abc123"
|
||||
#
|
||||
## Optional: an alternate location (URL or import path) for the project's source.
|
||||
# source = "https://github.com/myfork/package.git"
|
||||
#
|
||||
## "metadata" defines metadata about the dependency or override that could be used
|
||||
## by other independent systems. The metadata defined here will be ignored by dep.
|
||||
# [metadata]
|
||||
# key1 = "value that convey data to other systems"
|
||||
# system1-data = "value that is used by a system"
|
||||
# system2-data = "value that is used by another system"
|
||||
|
||||
## Overrides have the same structure as [[constraint]], but supersede all
|
||||
## [[constraint]] declarations from all projects. Only [[override]] from
|
||||
## the current project's are applied.
|
||||
##
|
||||
## Overrides are a sledgehammer. Use them only as a last resort.
|
||||
# [[override]]
|
||||
## Required: the root import path of the project being constrained.
|
||||
# name = "github.com/user/project"
|
||||
#
|
||||
## Optional: specifying a version constraint override will cause all other
|
||||
## constraints on this project to be ignored; only the overridden constraint
|
||||
## need be satisfied.
|
||||
## Again, only one of "branch", "version" or "revision" can be specified.
|
||||
# version = "1.0.0"
|
||||
# branch = "master"
|
||||
# revision = "abc123"
|
||||
#
|
||||
## Optional: specifying an alternate source location as an override will
|
||||
## enforce that the alternate location is used for that project, regardless of
|
||||
## what source location any dependent projects specify.
|
||||
# source = "https://github.com/myfork/package.git"
|
||||
|
||||
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/BurntSushi/toml"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/Joker/jade"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/Unknwon/i18n"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/aymerick/raymond"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
version = "1.1.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/eknkc/amber"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/esemplastic/unis"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/flosch/pongo2"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/garyburd/redigo"
|
||||
version = "1.1.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/gavv/monotime"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/gorilla/websocket"
|
||||
version = "1.1.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/imdario/mergo"
|
||||
version = "0.2.2"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/iris-contrib/httpexpect"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/klauspost/compress"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/microcosm-cc/bluemonday"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/monoculum/formam"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/moul/http2curl"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/pmezard/go-difflib"
|
||||
version = "1.0.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/russross/blackfriday"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/satori/go.uuid"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/valyala/bytebufferpool"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/xeipuuv/gojsonschema"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/yalp/jsonpath"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/yudai/gojsondiff"
|
||||
version = "1.0.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/text"
|
||||
|
||||
[[constraint]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/PuerkitoBio/goquery"
|
153
HISTORY.md
|
@ -7,7 +7,7 @@
|
|||
|
||||
### Looking for previous versions?
|
||||
|
||||
https://github.com/kataras/iris#version
|
||||
https://github.com/kataras/iris#-version
|
||||
|
||||
|
||||
### Should I upgrade my Iris?
|
||||
|
@ -19,6 +19,142 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
|
|||
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
|
||||
|
||||
|
||||
# Mo, 10 July 2017 | v8.0.0
|
||||
|
||||
## 📈 One and a half years with Iris and You...
|
||||
|
||||
Despite the deflamations, the clickbait articles, the removed posts of mine at reddit/r/golang, the unexpected and inadequate ban from the gophers slack room by @dlsniper alone the previous week without any reason or inform, Iris is still here and will be.
|
||||
|
||||
- 7070 github stars
|
||||
- 749 github forks
|
||||
- 1m total views at its documentation
|
||||
- ~800$ at donations (there're a lot for a golang open-source project, thanks to you)
|
||||
- ~550 reported bugs fixed
|
||||
- ~30 community feature requests have been implemented
|
||||
|
||||
## 🔥 Reborn
|
||||
|
||||
As you may have heard I have huge responsibilities on my new position at Dubai nowdays, therefore I don't have the needed time to work on this project anymore.
|
||||
|
||||
After a month of negotiations and searching I succeed to find a decent software engineer to continue my work on the open source community.
|
||||
|
||||
The leadership of this, open-source, repository was transfered to [hiveminded](https://github.com/hiveminded), the author of iris-based [get-ion/ion](https://github.com/get-ion/ion), he actually did an excellent job on the framework, he kept the code as minimal as possible and at the same time added more features, examples and middleware(s).
|
||||
|
||||
These types of projects need heart and sacrifices to continue offer the best developer experience like a paid software, please do support him as you did with me!
|
||||
|
||||
## 📰 Changelog
|
||||
|
||||
> app. = `app := iris.New();` **app.**
|
||||
|
||||
> ctx. = `func(ctx context.Context) {` **ctx.** `}`
|
||||
|
||||
### Docker
|
||||
|
||||
Docker and kubernetes integration showcase, see the [iris-contrib/cloud-native-go](https://github.com/iris-contrib/cloud-native-go) repository as an example.
|
||||
|
||||
### Logger
|
||||
|
||||
* Logger which was an `io.Writer` was replaced with the pluggable `logrus`.
|
||||
* which you still attach an `io.Writer` with `app.Logger().Out = an io.Writer`.
|
||||
* iris as always logs only critical errors, you can disable them with `app.Logger().Level = iris.NoLog`
|
||||
* the request logger outputs the incoming requests as INFO level.
|
||||
|
||||
### Sessions
|
||||
|
||||
Remove `ctx.Session()` and `app.AttachSessionManager`, devs should import and use the `sessions` package as standalone, it's totally optional, devs can use any other session manager too. [Examples here](sessions#table-of-contents).
|
||||
|
||||
### Websockets
|
||||
|
||||
The `github.com/kataras/iris/websocket` package does not handle the endpoint and client side automatically anymore. Example code:
|
||||
|
||||
```go
|
||||
func setupWebsocket(app *iris.Application) {
|
||||
// create our echo websocket server
|
||||
ws := websocket.New(websocket.Config{
|
||||
ReadBufferSize: 1024,
|
||||
WriteBufferSize: 1024,
|
||||
})
|
||||
ws.OnConnection(handleConnection)
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx context.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
||||
// register the server on an endpoint.
|
||||
// see the inline javascript code in the websockets.html, this endpoint is used to connect to the server.
|
||||
app.Get("/echo", ws.Handler())
|
||||
}
|
||||
```
|
||||
|
||||
> More examples [here](websocket#table-of-contents)
|
||||
|
||||
### View
|
||||
|
||||
Rename `app.AttachView(...)` to `app.RegisterView(...)`.
|
||||
|
||||
Users can omit the import of `github.com/kataras/iris/view` and use the `github.com/kataras/iris` package to
|
||||
refer to the view engines, i.e: `app.RegisterView(iris.HTML("./templates", ".html"))` is the same as `import "github.com/kataras/iris/view" [...] app.RegisterView(view.HTML("./templates" ,".html"))`.
|
||||
|
||||
> Examples [here](_examples/#view)
|
||||
|
||||
### Security
|
||||
|
||||
At previous versions, when you called `ctx.Remoteaddr()` Iris could parse and return the client's IP from the "X-Real-IP", "X-Forwarded-For" headers. This was a security leak as you can imagine, because the user can modify them. So we've disabled these headers by-default and add an option to add/remove request headers that are responsible to parse and return the client's real IP.
|
||||
|
||||
```go
|
||||
// WithRemoteAddrHeader enables or adds a new or existing request header name
|
||||
// that can be used to validate the client's real IP.
|
||||
//
|
||||
// Existing values are:
|
||||
// "X-Real-Ip": false,
|
||||
// "X-Forwarded-For": false,
|
||||
// "CF-Connecting-IP": false
|
||||
//
|
||||
// Look `context.RemoteAddr()` for more.
|
||||
WithRemoteAddrHeader(headerName string) Configurator // enables a header.
|
||||
WithoutRemoteAddrHeader(headerName string) Configurator // disables a header.
|
||||
```
|
||||
For example, if you want to enable the "CF-Connecting-IP" header (cloudflare)
|
||||
you have to add the `WithRemoteAddrHeader` option to the `app.Run` function, at the end of your program.
|
||||
|
||||
```go
|
||||
app.Run(iris.Addr(":8080"), iris.WithRemoteAddrHeader("CF-Connecting-IP"))
|
||||
// This header name will be checked when ctx.RemoteAddr() called and if exists
|
||||
// it will return the client's IP, otherwise it will return the default *http.Request's `RemoteAddr` field.
|
||||
```
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
Fix [typescript tools](typescript).
|
||||
|
||||
[_examples](_examples/) folder has been ordered by feature and usage:
|
||||
- contains tests on some examples
|
||||
- new examples added, one of them shows how the `reuseport` feature on UNIX and BSD systems can be used to listen for incoming connections, [see here](_examples/#http-listening)
|
||||
|
||||
|
||||
Replace supervisor's tasks with events, like `RegisterOnShutdown`, `RegisterOnError`, `RegisterOnServe` and fix the (unharmful) race condition when output the banner to the console. Global notifier for interrupt signals which can be disabled via `app.Run([...], iris.WithoutInterruptHandler)`, look [graceful-shutdown](_examples/http-listening/graceful-shutdown/main.go) example for more.
|
||||
|
||||
|
||||
More handlers are ported to Iris (they can be used as they are without `iris.FromStd`), these handlers can be found at [iris-contrib/middleware](https://github.com/iris-contrib/middleware). Feel free to put your own there.
|
||||
|
||||
|
||||
| Middleware | Description | Example |
|
||||
| -----------|--------|-------------|
|
||||
| [jwt](https://github.com/iris-contrib/middleware/tree/master/jwt) | Middleware checks for a JWT on the `Authorization` header on incoming requests and decodes it. | [iris-contrib/middleware/jwt/_example](https://github.com/iris-contrib/middleware/tree/master/jwt/_example) |
|
||||
| [cors](https://github.com/iris-contrib/middleware/tree/master/cors) | HTTP Access Control. | [iris-contrib/middleware/cors/_example](https://github.com/iris-contrib/middleware/tree/master/cors/_example) |
|
||||
| [secure](https://github.com/iris-contrib/middleware/tree/master/secure) | Middleware that implements a few quick security wins. | [iris-contrib/middleware/secure/_example](https://github.com/iris-contrib/middleware/tree/master/secure/_example/main.go) |
|
||||
| [tollbooth](https://github.com/iris-contrib/middleware/tree/master/tollboothic) | Generic middleware to rate-limit HTTP requests. | [iris-contrib/middleware/tollbooth/_examples/limit-handler](https://github.com/iris-contrib/middleware/tree/master/tollbooth/_examples/limit-handler) |
|
||||
| [cloudwatch](https://github.com/iris-contrib/middleware/tree/master/cloudwatch) | AWS cloudwatch metrics middleware. |[iris-contrib/middleware/cloudwatch/_example](https://github.com/iris-contrib/middleware/tree/master/cloudwatch/_example) |
|
||||
| [new relic](https://github.com/iris-contrib/middleware/tree/master/newrelic) | Official [New Relic Go Agent](https://github.com/newrelic/go-agent). | [iris-contrib/middleware/newrelic/_example](https://github.com/iris-contrib/middleware/tree/master/newrelic/_example) |
|
||||
| [prometheus](https://github.com/iris-contrib/middleware/tree/master/prometheus)| Easily create metrics endpoint for the [prometheus](http://prometheus.io) instrumentation tool | [iris-contrib/middleware/prometheus/_example](https://github.com/iris-contrib/middleware/tree/master/prometheus/_example) |
|
||||
|
||||
|
||||
v7.x is deprecated because it sold as it is and it is not part of the public, stable `gopkg.in` iris versions. Developers/users of this library should upgrade their apps to v8.x, the refactor process will cost nothing for most of you, as the most common API remains as it was. The changelog history from that are being presented below.
|
||||
|
||||
|
||||
# Th, 15 June 2017 | v7.2.0
|
||||
|
||||
### About our new home page
|
||||
http://iris-go.com
|
||||
|
||||
|
@ -29,9 +165,6 @@ Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.co
|
|||
|
||||
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!
|
||||
|
||||
|
||||
# Th, 15 June 2017 | v7.2.0
|
||||
|
||||
### Cache
|
||||
|
||||
Declare the `iris.Cache alias` to the new, improved and most-suited for common usage, `cache.Handler function`.
|
||||
|
@ -52,20 +185,20 @@ Declare the `iris.Cache alias` to the new, improved and most-suited for common u
|
|||
- **Fix** `app.StaticEmbedded(requestPath string, vdir string, assetFn func(name string) ([]byte, error), namesFn func() []string)`.
|
||||
|
||||
Examples:
|
||||
- [Embedding Files Into Executable App](_examples/beginner/file-server/embedding-files-into-app)
|
||||
- [Single Page Application](_examples/beginner/file-server/single-page-application)
|
||||
- [Embedding Single Page Application](_examples/beginner/file-server/embedding-single-page-application)
|
||||
- [Embedding Files Into Executable App](_examples/file-server/embedding-files-into-app)
|
||||
- [Single Page Application](_examples/file-server/single-page-application)
|
||||
- [Embedding Single Page Application](_examples/file-server/embedding-single-page-application)
|
||||
|
||||
> [app.StaticWeb](_examples/beginner/file-server/basic/main.go) doesn't works for root request path "/" anymore, use the new `app.SPA` instead.
|
||||
> [app.StaticWeb](_examples/file-server/basic/main.go) doesn't works for root request path "/" anymore, use the new `app.SPA` instead.
|
||||
|
||||
### WWW subdomain entry
|
||||
|
||||
- [Example](_examples/intermediate/subdomains/www/main.go) added to copy all application's routes, including parties, to the `www.mydomain.com`
|
||||
- [Example](_examples/subdomains/www/main.go) added to copy all application's routes, including parties, to the `www.mydomain.com`
|
||||
|
||||
|
||||
### Wrapping the Router
|
||||
|
||||
- [Example](_examples/beginner/routing/custom-wrapper/main.go) added to show you how you can use the `app.WrapRouter`
|
||||
- [Example](_examples/routing/custom-wrapper/main.go) added to show you how you can use the `app.WrapRouter`
|
||||
to implement a similar to `app.SPA` functionality, don't panic, it's easier than it sounds.
|
||||
|
||||
|
||||
|
|
35
LICENSE
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
||||
Copyright (c) 2017 The Iris Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
|
@ -10,38 +10,7 @@ notice, this list of conditions and the following disclaimer.
|
|||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Gerasimos Maropoulos nor the name of his
|
||||
username, kataras, may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
The Go Programming Language is redistributed with the following disclaimer:
|
||||
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
* Neither the name of Iris nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
|
|
571
README.md
|
@ -1,113 +1,73 @@
|
|||
# 02 July 2017
|
||||
|
||||
### DEPRECATED
|
||||
|
||||
Iris has been acquired so development is up to the community, there are two active iris-based communities so far.
|
||||
|
||||
Use one of these projects instead:
|
||||
|
||||
https://github.com/get-ion/ion
|
||||
|
||||
**Ion is a fast, simple and efficient micro web framework for Go. It provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.**
|
||||
|
||||
- a bit faster than Iris version 7, based on `ab`
|
||||
- stable api
|
||||
- more examples
|
||||
- sessions, websockets, typescript and cloud editor(fixed) on different packages
|
||||
- test cov, including examples
|
||||
- slack bot for support automation
|
||||
- has a FAQ page which is part of the gitbook.com beta program
|
||||
- central issue portal
|
||||
- HuHu supported
|
||||
|
||||
https://github.com/go-siris/siris
|
||||
|
||||
**A fast, cross-platform and efficient web framework with robust set of well-designed features, written entirely in Go.**
|
||||
|
||||
- three maintainers
|
||||
- plan to stabilize api, no unneeded changes
|
||||
- plan to increase test-coverage
|
||||
- plan to add more middlewares and examples
|
||||
|
||||
|
||||
> If your team's project is missing from this list, please contact with me.
|
||||
|
||||
# IRIS HAS BEEN ACQUIRED
|
||||
|
||||
Iris project has been acquired by a Dubai-based startup.
|
||||
|
||||
Both sides agree that every related public data should remain open for at least 30 days.
|
||||
|
||||
After the period of 30 days, company has the proprietary rights to delete or transfer this repository and all its related public data forever without any warnings.
|
||||
|
||||
The company may or may not reveal its true identity to the public.
|
||||
|
||||
Transaction of the public domains still in-progress:
|
||||
|
||||
- http://iris-go.com
|
||||
- https://kataras.rocket.chat/channel/iris
|
||||
|
||||
View-accessed users can clone the current state of the project's public repositories and use without any warranties.
|
||||
|
||||
From now on, Original Author owns a high position to the company's table.
|
||||
|
||||
At any circumstances,
|
||||
|
||||
Original Author keeps the creation rights.
|
||||
|
||||
# About the future of Iris
|
||||
|
||||
Clone the repository today because if I can't find a new lead maintainer for the [v7.2](https://github.com/kataras/iris-v7-29d) you, as community, will have to find a way to communicate about its future, the name "iris go" was taken by the company too, so it will be nice if the future main contributor change its name too, if you don't do it I will not beat you but I don't know the full company's law-plan for this, yet.
|
||||
|
||||
All donators, without any exception, will have my support for at least 6 months (for all iris versions), we have a private room at the [chat](https://kataras.rocket.chat/channel/iris).
|
||||
|
||||
Don't worry **I will not let you down**, we're trying to find a decent open-source contributor to continue the Iris' open-source codebase. I'm already in touch with some good gophers but **If you're willing to maintain this project** please [send](#contact) me details about your experience, general bio and your github username.
|
||||
|
||||
**I am really thankful for all of your support to me and the community, all donations, all bug reports, all comments without any exception. I did proceeded with all my physical abilities so far but unfortunately there weren't enough for my survivor. I'm really sorry if the latest news made iris open-source community disappointed but you have to see things from my point view, I was one step before bankruptcy, I had no other choice but accept the offer.**
|
||||
|
||||
# ![Logo created by @santoshanand](logo_white_35_24.png) Iris
|
||||
|
||||
A fast, cross-platform and efficient web framework with robust set of well-designed features, written entirely in Go.
|
||||
Iris is a fast, simple and efficient micro web framework for Go. It provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.
|
||||
|
||||
[![Build status](https://api.travis-ci.org/kataras/iris.svg?branch=master&style=flat-square)](https://travis-ci.org/kataras/iris)
|
||||
[![Report card](https://img.shields.io/badge/report%20card%20-a%2B-F44336.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris)
|
||||
[![Support forum](https://img.shields.io/badge/support-page-ec2eb4.svg?style=flat-square)](http://support.iris-go.com)
|
||||
[![Examples](https://img.shields.io/badge/howto-examples-3362c2.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples#table-of-contents)
|
||||
[![Godocs](https://img.shields.io/badge/7.2.0-%20documentation-5272B4.svg?style=flat-square)](https://godoc.org/github.com/kataras/iris)
|
||||
[![Chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris)
|
||||
[![Buy me a cup of coffee](https://img.shields.io/badge/support-%20open--source-F4A460.svg?logo=data:image%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAwIDEwMDAiPjxwYXRoIGZpbGw9InJnYigyMjAsMjIwLDIyMCkiIGQ9Ik04ODYuNiwzMDUuM2MtNDUuNywyMDMuMS0xODcsMzEwLjMtNDA5LjYsMzEwLjNoLTc0LjFsLTUxLjUsMzI2LjloLTYybC0zLjIsMjEuMWMtMi4xLDE0LDguNiwyNi40LDIyLjYsMjYuNGgxNTguNWMxOC44LDAsMzQuNy0xMy42LDM3LjctMzIuMmwxLjUtOGwyOS45LTE4OS4zbDEuOS0xMC4zYzIuOS0xOC42LDE4LjktMzIuMiwzNy43LTMyLjJoMjMuNWMxNTMuNSwwLDI3My43LTYyLjQsMzA4LjktMjQyLjdDOTIxLjYsNDA2LjgsOTE2LjcsMzQ4LjYsODg2LjYsMzA1LjN6Ii8%2BPHBhdGggZmlsbD0icmdiKDIyMCwyMjAsMjIwKSIgZD0iTTc5MS45LDgzLjlDNzQ2LjUsMzIuMiw2NjQuNCwxMCw1NTkuNSwxMEgyNTVjLTIxLjQsMC0zOS44LDE1LjUtNDMuMSwzNi44TDg1LDg1MWMtMi41LDE1LjksOS44LDMwLjIsMjUuOCwzMC4ySDI5OWw0Ny4zLTI5OS42bC0xLjUsOS40YzMuMi0yMS4zLDIxLjQtMzYuOCw0Mi45LTM2LjhINDc3YzE3NS41LDAsMzEzLTcxLjIsMzUzLjItMjc3LjVjMS4yLTYuMSwyLjMtMTIuMSwzLjEtMTcuOEM4NDUuMSwxODIuOCw4MzMuMiwxMzAuOCw3OTEuOSw4My45TDc5MS45LDgzLjl6Ii8%2BPC9zdmc%2B)](https://github.com/kataras/iris#buy-me-a-cup-of-coffee)
|
||||
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris)
|
||||
[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris)
|
||||
[![godocs](https://img.shields.io/badge/godocs-8.x.x-0366d6.svg?style=flat-square)](https://godoc.org/github.com/kataras/iris)
|
||||
[![get support](https://img.shields.io/badge/get-support-cccc00.svg?style=flat-square)](http://support.iris-go.com)
|
||||
[![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples)
|
||||
[![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris)
|
||||
|
||||
<p>
|
||||
<img src="https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png" alt="This benchmark measures results from 'real-world' instead of 'hello-world' application source code. | Last Update At: July 21, 2016. | Shows: Processing Time Horizontal Graph. | Who did: Third-party source. Transparent achievement." />
|
||||
<img src="https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png" alt="Third-party source for transparency." />
|
||||
</p>
|
||||
|
||||
Build your own web applications and portable APIs with the highest performance and countless potentials.
|
||||
# Mo, 10 July 2017 | v8.0.0
|
||||
|
||||
If you're coming from [Node.js](https://nodejs.org) world, this is the [expressjs](https://github.com/expressjs/express)++ equivalent for the [Go Programming Language](https://golang.org).
|
||||
### 📈 One and a half years with Iris and You...
|
||||
|
||||
- 7070 github stars
|
||||
- 749 github forks
|
||||
- 1m total views at its documentation
|
||||
- ~800$ at donations (there're a lot for a golang open-source project, thanks to you)
|
||||
- ~550 reported bugs fixed
|
||||
- ~30 community feature requests have been implemented
|
||||
|
||||
Table of contents
|
||||
-----------
|
||||
### 🔥 Reborn
|
||||
|
||||
* [Installation](#installation)
|
||||
* [Feature overview](#feature-overview)
|
||||
* [Documentation](#documentation)
|
||||
* [Examples](https://github.com/kataras/iris/tree/master/_examples)
|
||||
* [Reload on source code changes](#reload-on-source-code-changes)
|
||||
* [Support](#support)
|
||||
* [Buy me a cup of coffee?](#buy-me-a-cup-of-coffee)
|
||||
* [Third-party middleware list](#third-party-middleware)
|
||||
* [Testing](#testing)
|
||||
* [Philosophy](#philosophy)
|
||||
* [People](#people)
|
||||
* [Legends](#legends)
|
||||
* [Contact](#contact)
|
||||
* [Versioning](#version)
|
||||
As you may have heard I have huge responsibilities on my new position at Dubai nowdays, therefore I don't have the needed time to work on this project anymore.
|
||||
|
||||
After almost a month of negotiations and searching I succeed to find a decent software engineer to continue my work on the open source community.
|
||||
|
||||
The leadership of this, open-source, repository was transfered to [hiveminded](https://github.com/hiveminded).
|
||||
|
||||
These types of projects need heart and sacrifices to continue offer the best developer experience like a paid software, please do support him as you did with me!
|
||||
|
||||
> Please [contact](https://kataras.rocket.chat/channel/iris) with the project team if you want to help at the development process!
|
||||
|
||||
### 📑 Table of contents
|
||||
|
||||
* [Installation](#-installation)
|
||||
* [Latest changes](https://github.com/kataras/iris/blob/master/HISTORY.md#mo-10-july-2017--v800)
|
||||
* [Learn](#-learn)
|
||||
* [HTTP Listening](_examples/#http-listening)
|
||||
* [Configuration](_examples/#configuration)
|
||||
* [Routing, Grouping, Dynamic Path Parameters, "Macros" and Custom Context](_examples/#routing-grouping-dynamic-path-parameters-macros-and-custom-context)
|
||||
* [Subdomains](_examples/#subdomains)
|
||||
* [Wrap `http.Handler/HandlerFunc`](_examples/#convert-httphandlerhandlerfunc)
|
||||
* [View](_examples/#view)
|
||||
* [Authentication](_examples/#authentication)
|
||||
* [File Server](_examples/#file-server)
|
||||
* [How to Read from `context.Request() *http.Request`](_examples/#how-to-read-from-contextrequest-httprequest)
|
||||
* [How to Write to `context.ResponseWriter() http.ResponseWriter`](_examples/#how-to-write-to-contextresponsewriter-httpresponsewriter)
|
||||
* [Test](_examples/#testing)
|
||||
* [Cache](cache/#table-of-contents)
|
||||
* [Sessions](sessions/#table-of-contents)
|
||||
* [Websockets](websocket/#table-of-contents)
|
||||
* [Miscellaneous](_examples/#miscellaneous)
|
||||
* [Typescript Automation Tools](typescript/#table-of-contents)
|
||||
* [Tutorial: Online Visitors](_examples/tutorial/online-visitors)
|
||||
* [Tutorial: URL Shortener using BoltDB](_examples/tutorial/url-shortener)
|
||||
* [Middleware](middleware/)
|
||||
* [Philosophy](#-philosophy)
|
||||
* [Support](#-support)
|
||||
* [Versioning](#-version)
|
||||
* [When should I upgrade?](#should-i-upgrade-my-iris)
|
||||
* [Where can I find older versions?](#where-can-i-find-older-versions)
|
||||
* [People](#-people)
|
||||
|
||||
Installation
|
||||
-----------
|
||||
### 🚀 Installation
|
||||
|
||||
The only requirement is the [Go Programming Language](https://golang.org/dl/), at least version 1.8
|
||||
|
||||
|
@ -115,393 +75,154 @@ The only requirement is the [Go Programming Language](https://golang.org/dl/), a
|
|||
$ go get -u github.com/kataras/iris
|
||||
```
|
||||
|
||||
> 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.
|
||||
For further installation support, please navigate [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
|
||||
> _iris_ takes advantage of the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature. You get truly reproducible builds, as this method guards against upstream renames and deletes.
|
||||
|
||||
```go
|
||||
// file: main.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/view"
|
||||
)
|
||||
|
||||
// User is just a bindable object structure.
|
||||
type User struct {
|
||||
Username string `json:"username"`
|
||||
Firstname string `json:"firstname"`
|
||||
Lastname string `json:"lastname"`
|
||||
City string `json:"city"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// Load all templates from the "./templates" folder
|
||||
// where extension is ".html" and parse them
|
||||
// using the standard `html/template` package.
|
||||
app.RegisterView(iris.HTML("./templates", ".html"))
|
||||
|
||||
// Define templates using the std html/template engine.
|
||||
// Parse and load all files inside "./views" folder with ".html" file extension.
|
||||
// Reload the templates on each request (development mode).
|
||||
app.AttachView(view.HTML("./views", ".html").Reload(true))
|
||||
|
||||
// Regster custom handler for specific http errors.
|
||||
app.OnErrorCode(iris.StatusInternalServerError, func(ctx context.Context) {
|
||||
// .Values are used to communicate between handlers, middleware.
|
||||
errMessage := ctx.Values().GetString("error")
|
||||
if errMessage != "" {
|
||||
ctx.Writef("Internal server error: %s", errMessage)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Writef("(Unexpected) internal server error")
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
// Bind: {{.message}} with "Hello world!"
|
||||
ctx.ViewData("message", "Hello world!")
|
||||
// Render template file: ./templates/hello.html
|
||||
ctx.View("hello.html")
|
||||
})
|
||||
|
||||
app.Use(func(ctx context.Context) {
|
||||
ctx.Application().Log("Begin request for path: %s", ctx.Path())
|
||||
ctx.Next()
|
||||
})
|
||||
|
||||
// app.Done(func(ctx context.Context) {})
|
||||
|
||||
// Method POST: http://localhost:8080/decode
|
||||
app.Post("/decode", func(ctx context.Context) {
|
||||
var user User
|
||||
ctx.ReadJSON(&user)
|
||||
ctx.Writef("%s %s is %d years old and comes from %s", user.Firstname, user.Lastname, user.Age, user.City)
|
||||
})
|
||||
|
||||
// Method GET: http://localhost:8080/encode
|
||||
app.Get("/encode", func(ctx context.Context) {
|
||||
doe := User{
|
||||
Username: "Johndoe",
|
||||
Firstname: "John",
|
||||
Lastname: "Doe",
|
||||
City: "Neither FBI knows!!!",
|
||||
Age: 25,
|
||||
}
|
||||
|
||||
ctx.JSON(doe)
|
||||
})
|
||||
|
||||
// Method GET: http://localhost:8080/profile/anytypeofstring
|
||||
app.Get("/profile/{username:string}", profileByUsername)
|
||||
|
||||
usersRoutes := app.Party("/users", logThisMiddleware)
|
||||
{
|
||||
// Method GET: http://localhost:8080/users/42
|
||||
usersRoutes.Get("/{id:int min(1)}", getUserByID)
|
||||
// Method POST: http://localhost:8080/users/create
|
||||
usersRoutes.Post("/create", createUser)
|
||||
}
|
||||
|
||||
// Listen for incoming HTTP/1.x & HTTP/2 clients on localhost port 8080.
|
||||
app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8"))
|
||||
}
|
||||
|
||||
func logThisMiddleware(ctx context.Context) {
|
||||
ctx.Application().Log("Path: %s | IP: %s", ctx.Path(), ctx.RemoteAddr())
|
||||
|
||||
// .Next is required to move forward to the chain of handlers,
|
||||
// if missing then it stops the execution at this handler.
|
||||
ctx.Next()
|
||||
}
|
||||
|
||||
func profileByUsername(ctx context.Context) {
|
||||
// .Params are used to get dynamic path parameters.
|
||||
username := ctx.Params().Get("username")
|
||||
ctx.ViewData("Username", username)
|
||||
// renders "./views/users/profile.html"
|
||||
// with {{ .Username }} equals to the username dynamic path parameter.
|
||||
ctx.View("users/profile.html")
|
||||
}
|
||||
|
||||
func getUserByID(ctx context.Context) {
|
||||
userID := ctx.Params().Get("id") // Or convert directly using: .Values().GetInt/GetInt64 etc...
|
||||
// your own db fetch here instead of user :=...
|
||||
user := User{Username: "username" + userID}
|
||||
|
||||
ctx.XML(user)
|
||||
}
|
||||
|
||||
func createUser(ctx context.Context) {
|
||||
var user User
|
||||
err := ctx.ReadForm(&user)
|
||||
if err != nil {
|
||||
ctx.Values().Set("error", "creating user, read and parse form failed. "+err.Error())
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// renders "./views/users/create_verification.html"
|
||||
// with {{ . }} equals to the User object, i.e {{ .Username }} , {{ .Firstname}} etc...
|
||||
ctx.ViewData("", user)
|
||||
ctx.View("users/create_verification.html")
|
||||
// Start the server using a network address and block.
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
```
|
||||
|
||||
### Reload on source code changes
|
||||
```html
|
||||
<!-- file: ./templates/hello.html -->
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{.message}}</h1>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```sh
|
||||
$ go get -u github.com/kataras/rizla
|
||||
$ cd $GOPATH/src/mywebapp
|
||||
$ rizla main.go
|
||||
$ go run main.go
|
||||
> Now listening on: http://localhost:8080
|
||||
> Application started. Press CTRL+C to shut down.
|
||||
```
|
||||
|
||||
> Psst: Wanna go to [_examples](https://github.com/kataras/iris/tree/master/_examples) to see more code-snippets?
|
||||
<details>
|
||||
<summary>Hello World with Go 1.9</summary>
|
||||
|
||||
Feature Overview
|
||||
-----------
|
||||
If you've installed Go 1.9 then you can omit the `github.com/kataras/iris/context` package from the imports statement.
|
||||
|
||||
- Focus on high performance
|
||||
- Build RESTful APIs with our expressionist path syntax, i.e `{userid:int min(1)}`, `{asset:path}`, `{custom regexp([a-z]+)}`
|
||||
- Automatically install and serve certificates from https://letsencrypt.org
|
||||
- Robust routing and middleware ecosystem
|
||||
- Request-Scoped Transactions
|
||||
- Group API's and subdomains with wildcard support
|
||||
- Body binding for JSON, XML, Forms, can be extended to use your own custom binders
|
||||
- More than 50 handy functions to send HTTP responses
|
||||
- View system: supporting more than 6+ template engines, with prerenders. You can still use your favorite
|
||||
- Define virtual hosts and (wildcard) subdomains with path level routing
|
||||
- Graceful shutdown
|
||||
- Limit request body
|
||||
- Localization i18N
|
||||
- Serve static and embedded files
|
||||
- Cache
|
||||
- Log requests
|
||||
- Customizable format and output for the logger
|
||||
- Customizable HTTP errors
|
||||
- Compression (Gzip)
|
||||
- Authentication
|
||||
- OAuth, OAuth2 supporting 27+ popular websites
|
||||
- JWT
|
||||
- Basic Authentication
|
||||
- HTTP Sessions
|
||||
- Add / Remove trailing slash from the URL with option to redirect
|
||||
- Redirect requests
|
||||
- HTTP to HTTPS
|
||||
- HTTP to HTTPS WWW
|
||||
- HTTP to HTTPS non WWW
|
||||
- Non WWW to WWW
|
||||
- WWW to non WWW
|
||||
- Highly scalable rich content render (Markdown, JSON, JSONP, XML...)
|
||||
- Websocket-only API similar to socket.io
|
||||
- Hot Reload on source code changes
|
||||
- Typescript integration + Web IDE
|
||||
- Checks for updates at startup
|
||||
- Highly customizable
|
||||
- Feels like you used iris forever, thanks to its Fluent API
|
||||
- And many others...
|
||||
```go
|
||||
// +build go1.9
|
||||
|
||||
Documentation
|
||||
-----------
|
||||
package main
|
||||
|
||||
<a href="https://github.com/kataras/iris/tree/master/_examples#table-of-contents"><img width="155" src="https://raw.githubusercontent.com/iris-contrib/website/gh-pages/assets/book/cover_4.jpg"></a>
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
Small but practical [examples](https://github.com/kataras/iris/tree/master/_examples#table-of-contents) --they cover each feature.
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.RegisterView(iris.HTML("./templates", ".html"))
|
||||
|
||||
Wanna create your own fast URL Shortener Service Using Iris? --click [here](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7) to learn how.
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.ViewData("message", "Hello world!")
|
||||
ctx.View("hello.html")
|
||||
})
|
||||
|
||||
[Godocs](https://godoc.org/github.com/kataras/iris) --for deep understanding.
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
```
|
||||
|
||||
We expect Go version 1.9 to be released in August, however you can install Go 1.9 beta today.
|
||||
|
||||
Support
|
||||
------------
|
||||
### Installing Go 1.9beta2
|
||||
|
||||
- [Post](http://support.iris-go.com) a feature request or report a bug, will help to make the framework even better.
|
||||
- :star: and watch [the project](https://github.com/kataras/iris/stargazers), will notify you about updates.
|
||||
- :earth_americas: publish [an article](https://medium.com/) or share a [tweet](https://twitter.com/) about Iris.
|
||||
- Donations, will help me to continue.
|
||||
1. Go to https://golang.org/dl/#go1.9beta2
|
||||
2. Download a compatible, with your OS, archieve, i.e `go1.9beta2.windows-amd64.zip`
|
||||
3. Unzip the contents of `go1.9beta2.windows-amd64.zip/go` folder to your $GOROOT, i.e `C:\Go`
|
||||
4. Open a terminal and execute `go version`, it should output the go1.9beta2 version, i.e:
|
||||
```sh
|
||||
C:\Users\hiveminded>go version
|
||||
go version go1.9beta2 windows/amd64
|
||||
```
|
||||
|
||||
I'll be glad to talk with you about **your awesome feature requests**,
|
||||
open a new [discussion](http://support.iris-go.com), you will be heard!
|
||||
</details>
|
||||
|
||||
Thanks in advance!
|
||||
<details>
|
||||
<summary>Why another new web framework?</summary>
|
||||
|
||||
Buy me a cup of coffee?
|
||||
------------
|
||||
_iris_ is easy, it has a familiar API while in the same has far more features than [Gin](https://github.com/gin-gonic/gin) or [Martini](https://github.com/go-martini/martini).
|
||||
|
||||
Iris is free and open source but developing it has taken thousands of hours of my time and a large part of my sanity. If you feel this web framework useful to you, it would go a great way to ensuring that I can afford to take the time to continue to develop it.
|
||||
You own your code —it will never generate (unfamiliar) code for you, like [Beego](https://github.com/astaxie/beego), [Revel](https://github.com/revel/revel) and [Buffalo](https://github.com/gobuffalo/buffalo) do.
|
||||
|
||||
It's not just-another-router but its overall performance is equivalent with something like [httprouter](https://github.com/julienschmidt/httprouter).
|
||||
|
||||
I spend all my time in the construction of Iris, therefore I have no income value.
|
||||
Unlike [fasthttp](https://github.com/valyala/fasthttp), iris provides full HTTP/2 support for free.
|
||||
|
||||
Feel free to send **any** amount through paypal:
|
||||
Compared to the rest open source projects, this one is very active and you get answers almost immediately.
|
||||
|
||||
[![](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kataras2006%40hotmail%2ecom&lc=GR&item_name=Iris%20web%20framework&item_number=iriswebframeworkdonationid2016¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted)
|
||||
</details>
|
||||
|
||||
> Please check your e-mail after your donation.
|
||||
### 👥 Community
|
||||
|
||||
Thanks for your gratitude and finance help ♡
|
||||
<!--
|
||||
Join the welcoming community of fellow _iris_ developers in [rocket.chat](https://kataras.rocket.chat/channel/iris).
|
||||
|
||||
Some of the benefits are listed here:
|
||||
### 📖 Learn
|
||||
|
||||
- Your github username, after your approval, is visible at the top of the README page.
|
||||
- Access to the 'donors' [private chat room](https://kataras.rocket.chat/group/donors) gives you real-time assistance by Iris' Author.
|
||||
The awesome _iris_ community is always adding new examples, [_examples](_examples/) is a great place to get started!
|
||||
|
||||
-->
|
||||
Read the [godocs](https://godoc.org/github.com/kataras/iris) for a better understanding.
|
||||
|
||||
<!--
|
||||
### 🤔 Philosophy
|
||||
|
||||
### Become An Iris Sponsor
|
||||
The _iris_ philosophy is to provide robust tooling for HTTP, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Keep note that, today, iris is faster than apache+nginx itself.
|
||||
|
||||
Want to add your company's logo to our [website](http://iris-go.com)?
|
||||
_iris_ does not force you to use any specific ORM. With support for the most popular template engines, websocket server and a fast sessions manager you can quickly craft your perfect application.
|
||||
|
||||
Please contact me via email: kataras2006@hotmail.com
|
||||
### 💙 Support
|
||||
|
||||
Thank you!
|
||||
- [Post](http://support.iris-go.com) a feature request or report a bug
|
||||
- :star: and watch the public [repository](https://github.com/kataras/iris/stargazers), will keep you up to date
|
||||
- :earth_americas: publish [an article](https://medium.com/search?q=iris) or share a [tweet](https://twitter.com/hashtag/golang) about your personal experience with iris
|
||||
|
||||
-->
|
||||
### 📌 Version
|
||||
|
||||
Third Party Middleware
|
||||
------------
|
||||
|
||||
Iris has its own middleware form of `func(ctx context.Context)` but it's also compatible with all `net/http` middleware forms. See [here](https://github.com/kataras/iris/tree/master/_examples/beginner/convert-handlers).
|
||||
|
||||
I'm sure that each of you have, already, found his own favorite list but here's a small list of third-party handlers:
|
||||
|
||||
| Middleware | Author | Description |
|
||||
| -----------|--------|-------------|
|
||||
| [tollbooth](https://github.com/didip/tollbooth) | [Didip Kerabat](https://github.com/didip) | Generic middleware to rate-limit HTTP requests. [Example](https://github.com/didip/tollbooth/pull/34) |
|
||||
| [goth](https://github.com/markbates/goth) | [Mark Bates](https://github.com/markbates) | OAuth, OAuth2 authentication. [Example](https://github.com/kataras/iris/tree/master/_examples/intermediate/oauth2) |
|
||||
| [binding](https://github.com/mholt/binding) | [Matt Holt](https://github.com/mholt) | Data binding from HTTP requests into structs |
|
||||
| [cloudwatch](https://github.com/cvillecsteele/negroni-cloudwatch) | [Colin Steele](https://github.com/cvillecsteele) | AWS cloudwatch metrics middleware |
|
||||
| [csp](https://github.com/awakenetworks/csp) | [Awake Networks](https://github.com/awakenetworks) | [Content Security Policy](https://www.w3.org/TR/CSP2/) (CSP) support |
|
||||
| [delay](https://github.com/jeffbmartinez/delay) | [Jeff Martinez](https://github.com/jeffbmartinez) | Add delays/latency to endpoints. Useful when testing effects of high latency |
|
||||
| [New Relic Go Agent](https://github.com/yadvendar/negroni-newrelic-go-agent) | [Yadvendar Champawat](https://github.com/yadvendar) | Official [New Relic Go Agent](https://github.com/newrelic/go-agent) (currently in beta) |
|
||||
| [gorelic](https://github.com/jingweno/negroni-gorelic) | [Jingwen Owen Ou](https://github.com/jingweno) | New Relic agent for Go runtime |
|
||||
| [JWT](https://github.com/iris-contrib/middleware/tree/master/jwt) | [Auth0](https://github.com/auth0) | Middleware checks for a JWT on the `Authorization` header on incoming requests and decodes it. [Example](https://github.com/iris-contrib/middleware/tree/master/jwt/_example)|
|
||||
| [logrus](https://github.com/meatballhat/negroni-logrus) | [Dan Buch](https://github.com/meatballhat) | Logrus-based logger |
|
||||
| [onthefly](https://github.com/xyproto/onthefly) | [Alexander Rødseth](https://github.com/xyproto) | Generate TinySVG, HTML and CSS on the fly |
|
||||
| [permissions2](https://github.com/xyproto/permissions2) | [Alexander Rødseth](https://github.com/xyproto) | Cookies, users and permissions |
|
||||
| [prometheus](https://github.com/zbindenren/negroni-prometheus) | [Rene Zbinden](https://github.com/zbindenren) | Easily create metrics endpoint for the [prometheus](http://prometheus.io) instrumentation tool |
|
||||
| [render](https://github.com/unrolled/render) | [Cory Jacobsen](https://github.com/unrolled) | Render JSON, XML and HTML templates |
|
||||
| [RestGate](https://github.com/pjebs/restgate) | [Prasanga Siripala](https://github.com/pjebs) | Secure authentication for REST API endpoints |
|
||||
| [secure](https://github.com/iris-contrib/middleware/tree/master/secure) | [Cory Jacobsen](https://github.com/unrolled) | Middleware that implements a few quick security wins |
|
||||
| [stats](https://github.com/thoas/stats) | [Florent Messa](https://github.com/thoas) | Store information about your web application (response time, etc.) |
|
||||
| [VanGoH](https://github.com/auroratechnologies/vangoh) | [Taylor Wrobel](https://github.com/twrobel3) | Configurable [AWS-Style](http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html) HMAC authentication middleware |
|
||||
| [xrequestid](https://github.com/pilu/xrequestid) | [Andrea Franz](https://github.com/pilu) | Middleware that assigns a random X-Request-Id header to each request |
|
||||
| [digits](https://github.com/bamarni/digits) | [Bilal Amarni](https://github.com/bamarni) | Middleware that handles [Twitter Digits](https://get.digits.com/) authentication |
|
||||
|
||||
Feel free to put up a [PR](https://github.com/iris-contrib/middleware) your middleware!
|
||||
|
||||
Testing
|
||||
------------
|
||||
|
||||
The `httptest` package is your way for end-to-end HTTP testing, it uses the httpexpect library created by our friend, [gavv](https://github.com/gavv).
|
||||
|
||||
A simple test is located to [./_examples/intermediate/httptest/main_test.go](https://github.com/kataras/iris/blob/master/_examples/intermediate/httptest/main_test.go)
|
||||
|
||||
Philosophy
|
||||
------------
|
||||
|
||||
The Iris philosophy is to provide robust tooling for HTTP, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs. Keep note that, today, iris is faster than apache+nginx itself.
|
||||
|
||||
Iris does not force you to use any specific ORM or template engine. With support for the most popular template engines, you can quickly craft your perfect application.
|
||||
|
||||
|
||||
People
|
||||
------------
|
||||
|
||||
The author of Iris is [@kataras](https://github.com/kataras).
|
||||
|
||||
However the real Success of Iris belongs to you with your bug reports and feature requests that made this Framework so Unique.
|
||||
|
||||
|
||||
### Legends
|
||||
|
||||
I really need to thank each one of them because they stood up[♡](https://github.com/kataras/iris#support) to keep this project alive and active.
|
||||
|
||||
[Juan Sebastián Suárez Valencia](https://github.com/Juanses) donated 20 EUR at September 11 of 2016
|
||||
|
||||
[Bob Lee](https://github.com/li3p) donated 20 EUR at September 16 of 2016
|
||||
|
||||
[Celso Luiz](https://github.com/celsosz) donated 50 EUR at September 29 of 2016
|
||||
|
||||
[Ankur Srivastava](https://github.com/ansrivas) donated 20 EUR at October 2 of 2016
|
||||
|
||||
[Damon Zhao](https://github.com/se77en) donated 20 EUR at October 21 of 2016
|
||||
|
||||
[exponity - consulting & digital transformation](https://github.com/exponity) donated 30 EUR at November 4 of 2016
|
||||
|
||||
[Thomas Fritz](https://github.com/thomasfr) donated 25 EUR at Jenuary 8 of 2017
|
||||
|
||||
[Thanos V.](http://mykonosbiennale.com/) donated 20 EUR at Jenuary 16 of 2017
|
||||
|
||||
[George Opritescu](https://github.com/International) donated 20 EUR at February 7 of 2017
|
||||
|
||||
[Lex Tang](https://github.com/lexrus) donated 20 EUR at February 22 of 2017
|
||||
|
||||
[Conrad Steenberg](https://github.com/hengestone) donated 25 EUR at March 23 of 2017
|
||||
|
||||
<p>
|
||||
|
||||
<a href="https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7">
|
||||
<img width="300" src="http://iris-go.com/comment28.png" />
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/gelnior/status/769100480706379776">
|
||||
<img width="300" src="http://iris-go.com/comment27.png" />
|
||||
</a>
|
||||
|
||||
<br/>
|
||||
|
||||
<a href="https://www.youtube.com/watch?v=jGx0LkuUs4A">
|
||||
<img width="300" src="https://github.com/iris-contrib/website/raw/gh-pages/assets/gif_link_to_yt.gif" alt="What people say" />
|
||||
</a>
|
||||
|
||||
<a href="https://www.youtube.com/watch?v=jGx0LkuUs4A">
|
||||
<img width ="300" src="https://github.com/iris-contrib/website/raw/gh-pages/assets/gif_link_to_yt2.gif" alt="What people say" />
|
||||
</a>
|
||||
|
||||
<br/>
|
||||
|
||||
<a href="https://twitter.com/_mgale/status/818591490305761280">
|
||||
<img width="300" width="630" src="http://iris-go.com/comment25.png" />
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/MeAlex07/status/822799954188075008">
|
||||
<img width="300" width="627" src="http://iris-go.com/comment26.png" />
|
||||
</a>
|
||||
|
||||
</p>
|
||||
|
||||
### Contact
|
||||
|
||||
Besides the fact that we have a [community chat][Chat] for questions or reports and ideas, [stackoverflow](http://stackoverflow.com/) section for generic go+iris questions and the [iris support](http://support.iris-go.com) for bug reports and feature requests, you can also contact with me, as a person who is always open to help you:
|
||||
|
||||
- [Twitter](https://twitter.com/MakisMaropoulos)
|
||||
- [Facebook](https://facebook.com/kataras.gopher)
|
||||
- [Linkedin](https://www.linkedin.com/in/gerasimos-maropoulos)
|
||||
|
||||
Version
|
||||
------------
|
||||
|
||||
Current: **7.2.0**
|
||||
Current: **8.0.0**
|
||||
|
||||
Each new release is pushed to the master. It stays there until the next version. When a next version is released then the previous version goes to its own branch with `gopkg.in` as its import path (and its own vendor folder), in order to keep it working "for-ever".
|
||||
|
||||
Community members can request additional features or report a bug fix for a specific iris version.
|
||||
Changelog of the current version can be found at the [HISTORY](HISTORY.md) file.
|
||||
|
||||
#### Should I upgrade my iris?
|
||||
|
||||
### Should I upgrade my Iris?
|
||||
Developers are not forced to use the latest _iris_ version, they can use any version in production, they can update at any time they want.
|
||||
|
||||
Developers are not forced to use the latest Iris version, they can use any version in production, they can update at any time they want.
|
||||
Testers should upgrade immediately, if you're willing to use _iris_ in production you can wait a little more longer, transaction should be as safe as possible.
|
||||
|
||||
Testers should upgrade immediately, if you're willing to use Iris in production you can wait a little more longer, transaction should be as safe as possible.
|
||||
|
||||
### Where can I find older versions?
|
||||
|
||||
Each Iris version is independent. Only bug fixes, Router's API and experience are kept.
|
||||
#### Where can I find older versions?
|
||||
|
||||
Previous versions can be found at [releases page](https://github.com/kataras/iris/releases).
|
||||
|
||||
License
|
||||
------------
|
||||
### 🥇 People
|
||||
|
||||
Unless otherwise noted, the source files are distributed
|
||||
under the BSD-3-Clause License found in the [LICENSE file](LICENSE).
|
||||
The original author of _iris_ is [Gerasimos Maropoulos](https://github.com/kataras)
|
||||
|
||||
Note that some third-party packages that you use with Iris may requires
|
||||
different license agreements.
|
||||
The current lead maintainer is [Bill Qeras, Jr.](https://github.com/hiveminded)
|
||||
|
||||
[Chat]: https://kataras.rocket.chat/channel/iris
|
||||
[List of all contributors](https://github.com/kataras/iris/graphs/contributors)
|
||||
|
||||
[![](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=kataras2006%40hotmail%2ecom&lc=GR&item_name=Iris%20web%20framework&item_number=iriswebframeworkdonationid2016¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted)
|
|
@ -1,110 +1,164 @@
|
|||
# Examples
|
||||
|
||||
This folder provides easy to understand code snippets on how to get started with web development with the Go programming language using the [Iris](https://github.com/kataras/iris) web framework.
|
||||
Please do learn how [net/http](https://golang.org/pkg/net/http/) std package works, first.
|
||||
|
||||
It doesn't contains "best ways" neither explains all its features. It's just a simple, practical cookbook for young Gophers!
|
||||
This folder provides easy to understand code snippets on how to get started with [iris](https://github.com/kataras/iris) micro web framework.
|
||||
|
||||
## Table of contents
|
||||
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!
|
||||
|
||||
* [Level: Beginner](beginner)
|
||||
* [Hello world](beginner/hello-world/main.go)
|
||||
* [Overview](beginner/overview/main.go)
|
||||
* [Listening](beginner/listening)
|
||||
* [Common, with address](beginner/listening/listen-addr/main.go)
|
||||
* [UNIX socket file](beginner/listening/listen-unix/main.go)
|
||||
* [TLS](beginner/listening/listen-tls/main.go)
|
||||
* [Letsencrypt (Automatic Certifications)](beginner/listening/listen-letsencrypt/main.go)
|
||||
* [Custom TCP Listener](beginner/listening/custom-listener/main.go)
|
||||
* [Configuration](beginner/configuration)
|
||||
* [Basic way](beginner/configuration/basic/main.go)
|
||||
* [Functional way](beginner/configuration/functional/main.go)
|
||||
* [Import from YAML file](beginner/configuration/from-yaml-file/main.go)
|
||||
* [Import from TOML file](beginner/configuration/from-toml-file/main.go)
|
||||
* [Routing](beginner/routing)
|
||||
* [Overview](beginner/routing/overview/main.go)
|
||||
* [Basic](beginner/routing/basic/main.go)
|
||||
* [Dynamic Path](beginner/routing/dynamic-path/main.go)
|
||||
* [Reverse routing](beginner/routing/reverse/main.go)
|
||||
* [Custom wrapper](beginner/routing/custom-wrapper/main.go)
|
||||
* [Transform any third-party handler to iris-compatible handler](beginner/convert-handlers)
|
||||
* [From func(http.ResponseWriter, *http.Request, http.HandlerFunc)](beginner/convert-handlers/negroni-like/main.go)
|
||||
* [From http.Handler or http.HandlerFunc](beginner/convert-handlers/nethttp/main.go)
|
||||
* [Internal Application File Logger](beginner/file-logger/main.go)
|
||||
* [Custom HTTP Errors](beginner/http-errors/main.go)
|
||||
* [Write JSON](beginner/write-json/main.go)
|
||||
* [Read JSON](beginner/read-json/main.go)
|
||||
* [Read Form](beginner/read-form/main.go)
|
||||
* [Favicon](beginner/favicon/main.go)
|
||||
* [File Server](beginner/file-server)
|
||||
* [Basic](beginner/file-server/basic/main.go)
|
||||
* [Embedding Files Into App Executable File](beginner/file-server/embedding-files-into-app/main.go)
|
||||
* [Single Page Application](beginner/file-server/single-page-application/main.go)
|
||||
* [Embedding Single Page Application](beginner/file-server/embedding-single-page-application/main.go)
|
||||
* [Send Files](beginner/send-files/main.go)
|
||||
* [Stream Writer](beginner/stream-writer/main.go)
|
||||
* [Send An E-mail](beginner/e-mail/main.go)
|
||||
* [Upload/Read Files](beginner/upload-files/main.go)
|
||||
* [Recovery](beginner/recover/main.go)
|
||||
* [Profiling (pprof)](beginner/pprof/main.go)
|
||||
* [Request Logger](beginner/request-logger/main.go)
|
||||
* [Basic Authentication](beginner/basicauth/main.go)
|
||||
* [Level: Intermediate](intermediate)
|
||||
* [JWT](https://github.com/iris-contrib/middleware/blob/master/jwt/_example/main.go)
|
||||
* [OAUth2](intermediate/oauth2/main.go)
|
||||
* [CORS](https://github.com/iris-contrib/middleware/blob/master/cors/_example/main.go)
|
||||
* [Transactions](intermediate/transactions/main.go)
|
||||
* [HTTP Testing](intermediate/httptest/main_test.go)
|
||||
* [Watch & Compile Typescript source files](intermediate/typescript/main.go)
|
||||
* [Cloud Editor](intermediate/cloud-editor/main.go)
|
||||
* [HTTP Access Control](intermediate/cors/main.go)
|
||||
* [Cache Markdown](intermediate/cache-markdown/main.go)
|
||||
* [Localization and Internationalization](intermediate/i18n/main.go)
|
||||
* [Graceful Shutdown](intermediate/graceful-shutdown)
|
||||
* [Basic and simple](intermediate/graceful-shutdown/basic/main.go)
|
||||
* [Custom Host](intermediate/graceful-shutdown/custom-host/main.go)
|
||||
* [Custom notifier](intermediate/graceful-shutdown/custom-notifier/main.go)
|
||||
* [Custom HTTP Server](intermediate/custom-httpserver)
|
||||
* [Iris way](intermediate/custom-httpserver/iris-way/main.go)
|
||||
* [Standar way](intermediate/custom-httpserver/std-way/main.go)
|
||||
* [More than one server](intermediate/custom-httpserver/multi/main.go)
|
||||
* [Custom Context](intermediate/custom-context)
|
||||
* [Method Overriding](intermediate/custom-context/method-overriding/main.go)
|
||||
* [Route State](intermediate/route-state/main.go)
|
||||
* [View Engine](intermediate/view)
|
||||
* [Overview](intermediate/view/overview/main.go)
|
||||
* [Hi](intermediate/view/template_html_0/main.go)
|
||||
* [Showcase one simple Layout](intermediate/view/template_html_1/main.go)
|
||||
* [Layouts `yield` and `render` tmpl funcs](intermediate/view/template_html_2/main.go)
|
||||
* [Showcase of the `urlpath` tmpl func](intermediate/view/template_html_3/main.go)
|
||||
* [Showcase of the `url` tmpl func](intermediate/view/template_html_4/main.go)
|
||||
* [Inject Data Between Handlers](intermediate/view/context-view-data/main.go)
|
||||
* [Embedding Templates Into App Executable File](intermediate/view/embedding-templates-into-app/main.go)
|
||||
* [Sessions](intermediate/sessions)
|
||||
* [Overview](intermediate/sessions/overview/main.go)
|
||||
* [Encoding & Decoding the Session ID: Secure Cookie](intermediate/sessions/securecookie/main.go)
|
||||
* [Standalone](intermediate/sessions/standalone/main.go)
|
||||
* [Flash Messages](intermediate/sessions/flash-messages/main.go)
|
||||
* [With A Back-End Database](intermediate/sessions/database/main.go)
|
||||
* [Password Hashing](intermediate/sessions/password-hashing/main.go)
|
||||
* [Websockets](intermediate/websockets)
|
||||
* [Ridiculous Simple](intermediate/websockets/ridiculous-simple/main.go)
|
||||
* [Overview](intermediate/websockets/overview/main.go)
|
||||
* [Connection List](intermediate/websockets/connectionlist/main.go)
|
||||
* [Native Messages](intermediate/websockets/native-messages/main.go)
|
||||
* [Secure](intermediate/websockets/secure/main.go)
|
||||
* [Custom Go Client](intermediate/websockets/custom-go-client/main.go)
|
||||
* [Subdomains](intermediate/subdomains)
|
||||
* [Single](intermediate/subdomains/single/main.go)
|
||||
* [Multi](intermediate/subdomains/multi/main.go)
|
||||
* [Wildcard](intermediate/subdomains/wildcard/main.go)
|
||||
* [WWW](intermediate/subdomains/www/main.go)
|
||||
* [Level: Advanced](advanced)
|
||||
* [Online Visitors](advanced/online-visitors/main.go)
|
||||
* [URL Shortener using BoltDB](advanced/url-shortener/main.go)
|
||||
### Overview
|
||||
|
||||
- [Hello world!](hello-world/main.go)
|
||||
- [Glimpse](overview/main.go)
|
||||
- [Tutorial: Online Visitors](tutorial/online-visitors/main.go)
|
||||
- [Tutorial: URL Shortener using BoltDB](tutorial/url-shortener/main.go)
|
||||
|
||||
### HTTP Listening
|
||||
|
||||
- [Common, with address](http-listening/listen-addr/main.go)
|
||||
- [UNIX socket file](http-listening/listen-unix/main.go)
|
||||
- [TLS](http-listening/listen-tls/main.go)
|
||||
- [Letsencrypt (Automatic Certifications)](http-listening/listen-letsencrypt/main.go)
|
||||
- Custom TCP Listener
|
||||
* [common net.Listener](http-listening/custom-listener/main.go)
|
||||
* [SO_REUSEPORT for unix systems](http-listening/custom-listener/unix-reuseport/main.go)
|
||||
- Custom HTTP Server
|
||||
* [iris way](http-listening/custom-httpserver/iris-way/main.go)
|
||||
* [std way](http-listening/custom-httpserver/std-way/main.go)
|
||||
* [multi server instances](http-listening/custom-httpserver/multi/main.go)
|
||||
- Graceful Shutdown
|
||||
* [using the `RegisterOnInterrupt`](http-listening/graceful-shutdown/default-notifier/main.go)
|
||||
* [using a custom notifier](http-listening/graceful-shutdown/custom-notifier/main.go)
|
||||
|
||||
### Configuration
|
||||
|
||||
- [Functional](configuration/functional/main.go)
|
||||
- [From Configuration Struct](configuration/from-configuration-struct/main.go)
|
||||
- [Import from YAML file](configuration/from-yaml-file/main.go)
|
||||
- [Import from TOML file](configuration/from-toml-file/main.go)
|
||||
|
||||
|
||||
You may want to check out examples for jwt, cors and the rest of community-maden middleware by clicking [here](https://github.com/iris-contrib/middleware)
|
||||
### Routing, Grouping, Dynamic Path Parameters, "Macros" and Custom Context
|
||||
|
||||
- [Overview](routing/overview/main.go)
|
||||
- [Basic](routing/basic/main.go)
|
||||
- [Custom HTTP Errors](routing/http-errors/main.go)
|
||||
- [Dynamic Path](routing/dynamic-path/main.go)
|
||||
- [Reverse routing](routing/reverse/main.go)
|
||||
- [Custom wrapper](routing/custom-wrapper/main.go)
|
||||
- Custom Context
|
||||
* [Method Overriding](routing/custom-context/method-overriding/main.go)
|
||||
* [New Implementation](routing/custom-context/new-implementation/main.go)
|
||||
- [Route State](routing/route-state/main.go)
|
||||
|
||||
### Subdomains
|
||||
|
||||
- [Single](subdomains/single/main.go)
|
||||
- [Multi](subdomains/multi/main.go)
|
||||
- [Wildcard](subdomains/wildcard/main.go)
|
||||
- [WWW](subdomains/www/main.go)
|
||||
|
||||
### Convert `http.Handler/HandlerFunc`
|
||||
|
||||
- [From func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)](convert-handlers/negroni-like/main.go)
|
||||
- [From http.Handler or http.HandlerFunc](convert-handlers/nethttp/main.go)
|
||||
|
||||
### View
|
||||
|
||||
| Engine | Declaration |
|
||||
| -----------|-------------|
|
||||
| template/html | `iris.HTML(...)` |
|
||||
| django | `iris.Django(...)` |
|
||||
| handlebars | `iris.Handlebars(...)` |
|
||||
| amber | `iris.Amber(...)` |
|
||||
| pug(jade) | `iris.Pug(...)` |
|
||||
|
||||
- [Overview](view/overview/main.go)
|
||||
- [Hi](view/template_html_0/main.go)
|
||||
- [A simple Layout](view/template_html_1/main.go)
|
||||
- [Layouts: `yield` and `render` tmpl funcs](view/template_html_2/main.go)
|
||||
- [The `urlpath` tmpl func](view/template_html_3/main.go)
|
||||
- [The `url` tmpl func](view/template_html_4/main.go)
|
||||
- [Inject Data Between Handlers](view/context-view-data/main.go)
|
||||
- [Embedding Templates Into App Executable File](view/embedding-templates-into-app/main.go)
|
||||
|
||||
### Authentication
|
||||
|
||||
- [Basic Authentication](authentication/basicauth/main.go)
|
||||
- [OAUth2](authentication/oauth2/main.go)
|
||||
- [JWT](https://github.com/iris-contrib/middleware/blob/master/jwt/_example/main.go)
|
||||
- [Sessions](#sessions)
|
||||
|
||||
### File Server
|
||||
|
||||
- [Favicon](file-server/favicon/main.go)
|
||||
- [Basic](file-server/basic/main.go)
|
||||
- [Embedding Files Into App Executable File](file-server/embedding-files-into-app/main.go)
|
||||
- [Send/Force-Download Files](file-server/send-files/main.go)
|
||||
- Single Page Applications
|
||||
* [Single Page Application](file-server/single-page-application/basic/main.go)
|
||||
* [Embedded Single Page Application](file-server/single-page-application/embedded-single-page-application/main.go)
|
||||
|
||||
### How to Read from `context.Request() *http.Request`
|
||||
|
||||
- [Bind JSON](http_request/read-json/main.go)
|
||||
- [Bind Form](http_request/read-form/main.go)
|
||||
- [Upload/Read Files](http_request/upload-files/main.go)
|
||||
|
||||
> 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.
|
||||
|
||||
### How to Write to `context.ResponseWriter() http.ResponseWriter`
|
||||
|
||||
- [Text, Markdown, HTML, JSON, JSONP, XML, Binary](http_responsewriter/write-rest/main.go)
|
||||
- [Stream Writer](http_responsewriter/stream-writer/main.go)
|
||||
- [Transactions](http_responsewriter/transactions/main.go)
|
||||
|
||||
> The `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.
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
- [Request Logger](http_request/request-logger/main.go)
|
||||
- [Localization and Internationalization](miscellaneous/i18n/main.go)
|
||||
- [Recovery](miscellaneous/recover/main.go)
|
||||
- [Profiling (pprof)](miscellaneous/pprof/main.go)
|
||||
- [Internal Application File Logger](miscellaneous/file-logger/main.go)
|
||||
|
||||
#### More
|
||||
|
||||
https://github.com/kataras/iris/tree/master/middleware#third-party-handlers
|
||||
|
||||
### Testing
|
||||
|
||||
The `httptest` package is your way for end-to-end HTTP testing, it uses the httpexpect library created by our friend, [gavv](https://github.com/gavv).
|
||||
|
||||
[Example](testing/httptest/main_test.go)
|
||||
|
||||
### Caching
|
||||
|
||||
iris cache library lives on its own package: [https://github.com/kataras/iris/tree/master/cache](https://github.com/kataras/iris/tree/master/cache) **it contains examples**
|
||||
|
||||
### Sessions
|
||||
|
||||
iris session manager lives on its own package: [https://github.com/kataras/iris/tree/master/sessions](https://github.com/kataras/iris/tree/master/sessions) **it contains examples**
|
||||
|
||||
> You're free to use your own favourite sessions package if you'd like so.
|
||||
|
||||
### Websockets
|
||||
|
||||
iris websocket library lives on its own package: [https://github.com/kataras/iris/tree/master/websocket](https://github.com/kataras/iris/tree/master/websocket) **it contains examples**
|
||||
|
||||
> You're free to use your own favourite websockets package if you'd like so.
|
||||
|
||||
### Typescript Automation Tools
|
||||
|
||||
typescript automation tools have their own repository: [https://github.com/kataras/iris/tree/master/typescript](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.
|
||||
|
||||
### Hey, You!
|
||||
|
||||
Developers should read the [godocs](https://godoc.org/github.com/kataras/iris) for a better understanding.
|
||||
|
||||
Psst, I almost forgot; do not forget to [star or watch](https://github.com/kataras/iris/stargazers) the project in order to stay updated with the latest tech trends, it never takes more than a second!
|
||||
|
||||
> Do not forget to [star or watch the project](https://github.com/kataras/iris/stargazers) in order to stay updated with the latest tech trends, it takes some seconds for the sake of go!
|
||||
|
||||
> Developers should read the official [documentation](https://godoc.org/github.com/kataras/iris) in depth, for deep understanding.
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package main
|
||||
|
||||
// Version is the current version of the url-shortener package.
|
||||
const Version = "0.0.1"
|
6
_examples/authentication/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
# Authentication
|
||||
|
||||
- [Basic Authentication](basicauth/main.go)
|
||||
- [OAUth2](oauth2/main.go)
|
||||
- [JWT](https://github.com/iris-contrib/middleware/blob/master/jwt/_example/main.go)
|
||||
- [Sessions](https://github.com/kataras/iris/tree/master/_examples/#sessions)
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/kataras/iris/middleware/basicauth"
|
||||
)
|
||||
|
||||
func main() {
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
|
||||
authConfig := basicauth.Config{
|
||||
|
@ -40,6 +40,11 @@ func main() {
|
|||
needAuth.Get("/settings", h)
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := newApp()
|
||||
// open http://localhost:8080/admin
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
29
_examples/authentication/basicauth/main_test.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris/httptest"
|
||||
)
|
||||
|
||||
func TestBasicAuth(t *testing.T) {
|
||||
app := newApp()
|
||||
e := httptest.New(t, app)
|
||||
|
||||
// redirects to /admin without basic auth
|
||||
e.GET("/").Expect().Status(httptest.StatusUnauthorized)
|
||||
// without basic auth
|
||||
e.GET("/admin").Expect().Status(httptest.StatusUnauthorized)
|
||||
|
||||
// with valid basic auth
|
||||
e.GET("/admin").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin myusername:mypassword")
|
||||
e.GET("/admin/profile").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin/profile myusername:mypassword")
|
||||
e.GET("/admin/settings").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin/settings myusername:mypassword")
|
||||
|
||||
// with invalid basic auth
|
||||
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
|
||||
Expect().Status(httptest.StatusUnauthorized)
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
// Any OAuth2 (even the pure golang/x/net/oauth2) package
|
||||
// can be used with Iris but at this example we will see the markbates' goth:
|
||||
// can be used with iris but at this example we will see the markbates' goth:
|
||||
//
|
||||
// $ go get github.com/markbates/goth/...
|
||||
//
|
||||
|
@ -26,8 +26,8 @@ import (
|
|||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
|
||||
"github.com/kataras/iris/sessions"
|
||||
"github.com/kataras/iris/view"
|
||||
|
||||
"github.com/gorilla/securecookie" // optionally, used for session's encoder/decoder
|
||||
|
||||
|
@ -70,6 +70,24 @@ import (
|
|||
"github.com/markbates/goth/providers/yammer"
|
||||
)
|
||||
|
||||
var sessionsManager *sessions.Sessions
|
||||
|
||||
func init() {
|
||||
// attach a session manager
|
||||
cookieName := "mycustomsessionid"
|
||||
// AES only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
hashKey := []byte("the-big-and-secret-fash-key-here")
|
||||
blockKey := []byte("lot-secret-of-characters-big-too")
|
||||
secureCookie := securecookie.New(hashKey, blockKey)
|
||||
|
||||
sessionsManager = sessions.New(sessions.Config{
|
||||
Cookie: cookieName,
|
||||
Encode: secureCookie.Encode,
|
||||
Decode: secureCookie.Decode,
|
||||
})
|
||||
}
|
||||
|
||||
// These are some function helpers that you may use if you want
|
||||
|
||||
// GetProviderName is a function used to get the name of a provider
|
||||
|
@ -97,7 +115,7 @@ var GetProviderName = func(ctx context.Context) (string, error) {
|
|||
}
|
||||
|
||||
/*
|
||||
BeginAuthHandler is a convienence handler for starting the authentication process.
|
||||
BeginAuthHandler is a convenience handler for starting the authentication process.
|
||||
It expects to be able to get the name of the provider from the query parameters
|
||||
as either "provider" or ":provider".
|
||||
|
||||
|
@ -146,8 +164,8 @@ func GetAuthURL(ctx context.Context) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ctx.Session().Set(providerName, sess.Marshal())
|
||||
session := sessionsManager.Start(ctx)
|
||||
session.Set(providerName, sess.Marshal())
|
||||
return url, nil
|
||||
}
|
||||
|
||||
|
@ -191,8 +209,8 @@ var CompleteUserAuth = func(ctx context.Context) (goth.User, error) {
|
|||
if err != nil {
|
||||
return goth.User{}, err
|
||||
}
|
||||
|
||||
value := ctx.Session().GetString(providerName)
|
||||
session := sessionsManager.Start(ctx)
|
||||
value := session.GetString(providerName)
|
||||
if value == "" {
|
||||
return goth.User{}, errors.New("session value for " + providerName + " not found")
|
||||
}
|
||||
|
@ -214,7 +232,7 @@ var CompleteUserAuth = func(ctx context.Context) (goth.User, error) {
|
|||
return goth.User{}, err
|
||||
}
|
||||
|
||||
ctx.Session().Set(providerName, sess.Marshal())
|
||||
session.Set(providerName, sess.Marshal())
|
||||
return provider.FetchUser(sess)
|
||||
}
|
||||
|
||||
|
@ -224,8 +242,8 @@ func Logout(ctx context.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctx.Session().Delete(providerName)
|
||||
session := sessionsManager.Start(ctx)
|
||||
session.Delete(providerName)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -341,21 +359,7 @@ func main() {
|
|||
app := iris.New()
|
||||
|
||||
// attach and build our templates
|
||||
app.AttachView(view.HTML("./templates", ".html"))
|
||||
|
||||
// attach a session manager
|
||||
cookieName := "mycustomsessionid"
|
||||
// AES only supports key sizes of 16, 24 or 32 bytes.
|
||||
// You either need to provide exactly that amount or you derive the key from what you type in.
|
||||
hashKey := []byte("the-big-and-secret-fash-key-here")
|
||||
blockKey := []byte("lot-secret-of-characters-big-too")
|
||||
secureCookie := securecookie.New(hashKey, blockKey)
|
||||
sessManager := sessions.New(sessions.Config{
|
||||
Cookie: cookieName,
|
||||
Encode: secureCookie.Encode,
|
||||
Decode: secureCookie.Decode,
|
||||
})
|
||||
app.AttachSessionManager(sessManager)
|
||||
app.RegisterView(iris.HTML("./templates", ".html"))
|
||||
|
||||
// start of the router
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/kataras/go-mailer"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/view"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
app := iris.New()
|
||||
app.AttachView(view.HTML("./templates", ".html"))
|
||||
|
||||
// change these to your own settings
|
||||
cfg := mailer.Config{
|
||||
Host: "smtp.mailgun.org",
|
||||
Username: "postmaster@sandbox661c307650f04e909150b37c0f3b2f09.mailgun.org",
|
||||
Password: "38304272b8ee5c176d5961dc155b2417",
|
||||
Port: 587,
|
||||
}
|
||||
// change these to your e-mail to check if that works
|
||||
|
||||
// create the service
|
||||
mailService := mailer.New(cfg)
|
||||
|
||||
var to = []string{"kataras2006@hotmail.com"}
|
||||
|
||||
// standalone
|
||||
|
||||
//mailService.Send("iris e-mail test subject", "</h1>outside of context before server's listen!</h1>", to...)
|
||||
|
||||
//inside handler
|
||||
app.Get("/send", func(ctx context.Context) {
|
||||
content := `<h1>Hello From Iris web framework</h1> <br/><br/> <span style="color:blue"> This is the rich message body </span>`
|
||||
|
||||
err := mailService.Send("iris e-mail just t3st subject", content, to...)
|
||||
|
||||
if err != nil {
|
||||
ctx.HTML("<b> Problem while sending the e-mail: " + err.Error())
|
||||
} else {
|
||||
ctx.HTML("<h1> SUCCESS </h1>")
|
||||
}
|
||||
})
|
||||
|
||||
// send a body by template
|
||||
app.Get("/send/template", func(ctx context.Context) {
|
||||
// we will not use ctx.View
|
||||
// because we don't want to render to the client
|
||||
// we need the templates' parsed result as raw bytes
|
||||
// so we make use of the bytes.Buffer which is an io.Writer
|
||||
// which being expected on app.View parameter first.
|
||||
//
|
||||
// the rest of the parameters are the same and the behavior is the same as ctx.View,
|
||||
// except the 'where to render'
|
||||
buff := &bytes.Buffer{}
|
||||
|
||||
// View executes and writes the result of a template file to the writer.
|
||||
//
|
||||
// First parameter is the writer to write the parsed template.
|
||||
// Second parameter is the relative, to templates directory, template filename, including extension.
|
||||
// Third parameter is the layout, can be empty string.
|
||||
// Forth parameter is the bindable data to the template, can be nil.
|
||||
//
|
||||
// Use context.View to render templates to the client instead.
|
||||
// Returns an error on failure, otherwise nil.
|
||||
app.View(buff, "body.html", "", context.Map{
|
||||
"Message": " his is the rich message body sent by a template!!",
|
||||
"Footer": "The footer of this e-mail!",
|
||||
})
|
||||
content := buff.String()
|
||||
|
||||
err := mailService.Send("iris e-mail just t3st subject", content, to...)
|
||||
|
||||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusBadRequest)
|
||||
ctx.HTML("<b> Sent failed with error: " + err.Error())
|
||||
} else {
|
||||
ctx.HTML("<h1> SUCCESS </h1>")
|
||||
}
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<h1>Hello From Iris web framework</h1>
|
||||
<br />
|
||||
<br />
|
||||
<span style="color: red"> {{.Message}}</span>
|
||||
<hr />
|
||||
|
||||
<b> {{.Footer}} </b>
|
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 15 KiB |
|
@ -1,14 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Handle("GET", "/", func(ctx context.Context) {
|
||||
ctx.HTML("<b> Hello world! </b>")
|
||||
})
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/core/nettools"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
l, err := nettools.UNIX("/tmpl/srv.sock", 0666) // see its code to see how you can manually create a new file listener, it's easy.
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app.Run(iris.Listener(l))
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
// User bind struct
|
||||
type User struct {
|
||||
Firstname string `json:"firstname"`
|
||||
Lastname string `json:"lastname"`
|
||||
City string `json:"city"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Post("/decode", func(ctx context.Context) {
|
||||
var user User
|
||||
ctx.ReadJSON(&user)
|
||||
|
||||
ctx.Writef("%s %s is %d years old and comes from %s!", user.Firstname, user.Lastname, user.Age, user.City)
|
||||
})
|
||||
|
||||
app.Get("/encode", func(ctx context.Context) {
|
||||
peter := User{
|
||||
Firstname: "John",
|
||||
Lastname: "Doe",
|
||||
City: "Neither FBI knows!!!",
|
||||
Age: 25,
|
||||
}
|
||||
|
||||
ctx.StatusCode(iris.StatusOK)
|
||||
ctx.JSON(peter)
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -2,16 +2,19 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML("<b>Hello!</b>")
|
||||
})
|
||||
// [...]
|
||||
|
||||
// Good when you want to modify the whole configuration.
|
||||
app.Run(iris.Addr(":8080"), iris.WithConfiguration(iris.Configuration{ // default configuration:
|
||||
DisableBanner: false,
|
||||
DisableStartupLog: false,
|
||||
DisableInterruptHandler: false,
|
||||
DisablePathCorrection: false,
|
||||
EnablePathEscape: false,
|
||||
|
@ -22,7 +25,6 @@ func main() {
|
|||
Charset: "UTF-8",
|
||||
}))
|
||||
|
||||
// or before run:
|
||||
// app.Configure(iris.WithConfiguration(...))
|
||||
// app.Run(iris.Addr(":8080"))
|
||||
// or before Run:
|
||||
// app.Configure(iris.WithConfiguration(iris.Configuration{...}))
|
||||
}
|
|
@ -6,4 +6,4 @@ TimeFormat = "Mon, 01 Jan 2006 15:04:05 GMT"
|
|||
Charset = "UTF-8"
|
||||
|
||||
[Other]
|
||||
MyServerName = "Iris"
|
||||
MyServerName = "iris"
|
|
@ -2,11 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML("<b>Hello!</b>")
|
||||
})
|
||||
// [...]
|
||||
|
||||
// Good when you have two configurations, one for development and a different one for production use.
|
|
@ -2,11 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML("<b>Hello!</b>")
|
||||
})
|
||||
// [...]
|
||||
|
||||
// Good when you have two configurations, one for development and a different one for production use.
|
|
@ -2,15 +2,20 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML("<b>Hello!</b>")
|
||||
})
|
||||
// [...]
|
||||
|
||||
// Good when you want to change some of the configuration's field.
|
||||
// I use that method :)
|
||||
// Prefix: "With", code editors will help you navigate through all
|
||||
// configuration options without even a glitch to the documentation.
|
||||
|
||||
app.Run(iris.Addr(":8080"), iris.WithoutBanner, iris.WithCharset("UTF-8"))
|
||||
|
||||
// or before run:
|
|
@ -5,13 +5,12 @@ import (
|
|||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/handlerconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
irisMiddleware := handlerconv.FromStdWithNext(negronilikeTestMiddleware)
|
||||
app.Use(irisMiddleware)
|
||||
ionMiddleware := iris.FromStd(negronilikeTestMiddleware)
|
||||
app.Use(ionMiddleware)
|
||||
|
||||
// Method GET: http://localhost:8080/
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
|
@ -41,3 +40,6 @@ func negronilikeTestMiddleware(w http.ResponseWriter, r *http.Request, next http
|
|||
w.WriteHeader(iris.StatusBadRequest)
|
||||
w.Write([]byte("Bad request"))
|
||||
}
|
||||
|
||||
// Look "routing/custom-context" if you want to convert a custom handler with a custom Context
|
||||
// to a context.Handler.
|
|
@ -5,13 +5,12 @@ import (
|
|||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/handlerconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
irisMiddleware := handlerconv.FromStd(nativeTestMiddleware)
|
||||
app.Use(irisMiddleware)
|
||||
ionMiddleware := iris.FromStd(nativeTestMiddleware)
|
||||
app.Use(ionMiddleware)
|
||||
|
||||
// Method GET: http://localhost:8080/
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
|
@ -31,3 +30,6 @@ func main() {
|
|||
func nativeTestMiddleware(w http.ResponseWriter, r *http.Request) {
|
||||
println("Request path: " + r.URL.Path)
|
||||
}
|
||||
|
||||
// Look "routing/custom-context" if you want to convert a custom handler with a custom Context
|
||||
// to a context.Handler.
|
BIN
_examples/file-server/basic/assets/favicon.ico
Normal file
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
|
@ -3,10 +3,10 @@ package main
|
|||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/httptest"
|
||||
)
|
||||
|
||||
|
@ -33,7 +33,11 @@ func (r resource) loadFromBase(dir string) string {
|
|||
panic(fullpath + " failed with error: " + err.Error())
|
||||
}
|
||||
|
||||
return string(b)
|
||||
result := string(b)
|
||||
if runtime.GOOS != "windows" {
|
||||
result = strings.Replace(result, "\n", "\r\n", -1)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
var urls = []resource{
|
||||
|
@ -49,12 +53,18 @@ func TestEmbeddingFilesIntoApp(t *testing.T) {
|
|||
app := newApp()
|
||||
e := httptest.New(t, app)
|
||||
|
||||
if runtime.GOOS != "windows" {
|
||||
// remove the embedded static favicon for !windows,
|
||||
// it should be built for unix-specific in order to be work
|
||||
urls = urls[0 : len(urls)-1]
|
||||
}
|
||||
|
||||
for _, u := range urls {
|
||||
url := u.String()
|
||||
contents := u.loadFromBase("./assets")
|
||||
|
||||
e.GET(url).Expect().
|
||||
Status(iris.StatusOK).
|
||||
Status(httptest.StatusOK).
|
||||
Body().Equal(contents)
|
||||
}
|
||||
}
|
|
@ -8,17 +8,17 @@ import (
|
|||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
// This will serve the ./static/favicons/iris_favicon_48_48.ico to: localhost:8080/favicon.ico
|
||||
app.Favicon("./static/favicons/iris_favicon_48_48.ico")
|
||||
// This will serve the ./static/favicons/favicon.ico to: localhost:8080/favicon.ico
|
||||
app.Favicon("./static/favicons/favicon.ico.ico")
|
||||
|
||||
// app.Favicon("./static/favicons/iris_favicon_48_48.ico", "/favicon_48_48.ico")
|
||||
// This will serve the ./static/favicons/iris_favicon_48_48.ico to: localhost:8080/favicon_48_48.ico
|
||||
// app.Favicon("./static/favicons/favicon.ico.ico", "/favicon_16_16.ico")
|
||||
// This will serve the ./static/favicons/favicon.ico.ico to: localhost:8080/favicon_16_16.ico
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML(`<a href="/favicon.ico"> press here to see the favicon.ico</a>.
|
||||
At some browsers like chrome, it should be visible at the top-left side of the browser's window,
|
||||
because some browsers make requests to the /favicon.ico automatically,
|
||||
so Iris serves your favicon in that path too (you can change it).`)
|
||||
so iris serves your favicon in that path too (you can change it).`)
|
||||
}) // if favicon doesn't show to you, try to clear your browser's cache.
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
BIN
_examples/file-server/favicon/static/favicons/favicon.ico
Normal file
After Width: | Height: | Size: 1.1 KiB |
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/kataras/iris/view"
|
||||
)
|
||||
|
||||
// same as embedding-single-page-application but without go-bindata, the files are "physical" stored in the
|
||||
// same as embedded-single-page-application but without go-bindata, the files are "physical" stored in the
|
||||
// current system directory.
|
||||
|
||||
var page = struct {
|
||||
|
@ -15,7 +15,7 @@ var page = struct {
|
|||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.AttachView(view.HTML("./public", ".html"))
|
||||
app.RegisterView(view.HTML("./public", ".html"))
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.ViewData("Page", page)
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/httptest"
|
||||
)
|
||||
|
||||
|
@ -35,7 +34,8 @@ func (r resource) loadFromBase(dir string) string {
|
|||
panic(fullpath + " failed with error: " + err.Error())
|
||||
}
|
||||
|
||||
return string(b)
|
||||
result := string(b)
|
||||
return result
|
||||
}
|
||||
|
||||
var urls = []resource{
|
||||
|
@ -47,7 +47,7 @@ var urls = []resource{
|
|||
|
||||
func TestSPA(t *testing.T) {
|
||||
app := newApp()
|
||||
e := httptest.New(t, app)
|
||||
e := httptest.New(t, app, httptest.Debug(true))
|
||||
|
||||
for _, u := range urls {
|
||||
url := u.String()
|
||||
|
@ -55,7 +55,7 @@ func TestSPA(t *testing.T) {
|
|||
contents = strings.Replace(contents, "{{ .Page.Title }}", page.Title, 1)
|
||||
|
||||
e.GET(url).Expect().
|
||||
Status(iris.StatusOK).
|
||||
Status(httptest.StatusOK).
|
||||
Body().Equal(contents)
|
||||
}
|
||||
}
|
|
@ -182,9 +182,9 @@ func AssetNames() []string {
|
|||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"public/app.js": publicAppJs,
|
||||
"public/app.js": publicAppJs,
|
||||
"public/css/main.css": publicCssMainCss,
|
||||
"public/index.html": publicIndexHtml,
|
||||
"public/index.html": publicIndexHtml,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
|
@ -226,13 +226,14 @@ type bintree struct {
|
|||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"public": &bintree{nil, map[string]*bintree{
|
||||
"app.js": &bintree{publicAppJs, map[string]*bintree{}},
|
||||
"css": &bintree{nil, map[string]*bintree{
|
||||
"main.css": &bintree{publicCssMainCss, map[string]*bintree{}},
|
||||
"public": {nil, map[string]*bintree{
|
||||
"app.js": {publicAppJs, map[string]*bintree{}},
|
||||
"css": {nil, map[string]*bintree{
|
||||
"main.css": {publicCssMainCss, map[string]*bintree{}},
|
||||
}},
|
||||
"index.html": &bintree{publicIndexHtml, map[string]*bintree{}},
|
||||
"index.html": {publicIndexHtml, map[string]*bintree{}},
|
||||
}},
|
||||
}}
|
||||
|
||||
|
@ -282,4 +283,3 @@ func _filePath(dir, name string) string {
|
|||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import (
|
|||
// $ go get -u github.com/jteeuwen/go-bindata/...
|
||||
// $ go-bindata ./public/...
|
||||
// $ go build
|
||||
// $ ./embedding-single-page-application
|
||||
// $ ./embedded-single-page-application
|
||||
|
||||
var page = struct {
|
||||
Title string
|
||||
|
@ -17,7 +17,7 @@ var page = struct {
|
|||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.AttachView(view.HTML("./public", ".html").Binary(Asset, AssetNames))
|
||||
app.RegisterView(view.HTML("./public", ".html").Binary(Asset, AssetNames))
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.ViewData("Page", page)
|
|
@ -3,10 +3,10 @@ package main
|
|||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/httptest"
|
||||
)
|
||||
|
||||
|
@ -34,8 +34,11 @@ func (r resource) loadFromBase(dir string) string {
|
|||
if err != nil {
|
||||
panic(fullpath + " failed with error: " + err.Error())
|
||||
}
|
||||
|
||||
return string(b)
|
||||
result := string(b)
|
||||
if runtime.GOOS != "windows" {
|
||||
result = strings.Replace(result, "\n", "\r\n", -1)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
var urls = []resource{
|
||||
|
@ -55,7 +58,7 @@ func TestSPAEmbedded(t *testing.T) {
|
|||
contents = strings.Replace(contents, "{{ .Page.Title }}", page.Title, 1)
|
||||
|
||||
e.GET(url).Expect().
|
||||
Status(iris.StatusOK).
|
||||
Status(httptest.StatusOK).
|
||||
Body().Equal(contents)
|
||||
}
|
||||
}
|
36
_examples/hello-world/main.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
// +build go.1.8
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.Default()
|
||||
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/
|
||||
app.Handle("GET", "/", func(ctx context.Context) {
|
||||
ctx.HTML("<b>Hello world!</b>")
|
||||
})
|
||||
|
||||
// same as app.Handle("GET", "/ping", [...])
|
||||
// Method: GET
|
||||
// Resource: http://context:8080/ping
|
||||
app.Get("/ping", func(ctx iris.Context) {
|
||||
ctx.WriteString("pong")
|
||||
})
|
||||
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/hello
|
||||
app.Get("/hello", func(ctx context.Context) {
|
||||
ctx.JSON(iris.Map{"message": "Hello iris web framework."})
|
||||
})
|
||||
|
||||
// http://localhost:8080
|
||||
// http://localhost:8080/ping
|
||||
// http://localhost:8080/hello
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
35
_examples/hello-world/main_go19.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
// +build go1.9
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.Default()
|
||||
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/
|
||||
app.Handle("GET", "/", func(ctx iris.Context) {
|
||||
ctx.HTML("<b>Hello world!</b>")
|
||||
})
|
||||
|
||||
// same as app.Handle("GET", "/ping", [...])
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/ping
|
||||
app.Get("/ping", func(ctx iris.Context) {
|
||||
ctx.WriteString("pong")
|
||||
})
|
||||
|
||||
// Method: GET
|
||||
// Resource: http://localhost:8080/hello
|
||||
app.Get("/hello", func(ctx iris.Context) {
|
||||
ctx.JSON(iris.Map{"message": "Hello iris web framework."})
|
||||
})
|
||||
|
||||
// http://localhost:8080
|
||||
// http://localhost:8080/ping
|
||||
// http://localhost:8080/hello
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -18,7 +18,9 @@ func main() {
|
|||
ctx.Writef("Hello from %s", ctx.Path())
|
||||
})
|
||||
|
||||
srv := &http.Server{Addr: ":8080" /* Any custom fields here: Handler and ErrorLog are setted to the server automatically */}
|
||||
// Any custom fields here. Handler and ErrorLog are setted to the server automatically
|
||||
srv := &http.Server{Addr: ":8080"}
|
||||
|
||||
// http://localhost:8080/
|
||||
// http://localhost:8080/mypath
|
||||
app.Run(iris.Server(srv)) // same as app.Run(iris.Addr(":8080"))
|
|
@ -18,10 +18,8 @@ func main() {
|
|||
ctx.Writef("Hello from %s", ctx.Path())
|
||||
})
|
||||
|
||||
// call .Build before use the 'app' as an http.Handler on a custom http.Server
|
||||
if err := app.Build(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// call .Build before use the 'app' as a http.Handler on a custom http.Server
|
||||
app.Build()
|
||||
|
||||
// create our custom server and assign the Handler/Router
|
||||
srv := &http.Server{Handler: app, Addr: ":8080"} // you have to set Handler:app and Addr, see "iris-way" which does this automatically.
|
|
@ -0,0 +1,45 @@
|
|||
// +build linux darwin dragonfly freebsd netbsd openbsd rumprun
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
// Package tcplisten provides customizable TCP net.Listener with various
|
||||
// performance-related options:
|
||||
//
|
||||
// - SO_REUSEPORT. This option allows linear scaling server performance
|
||||
// on multi-CPU servers.
|
||||
// See https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/ for details.
|
||||
//
|
||||
// - TCP_DEFER_ACCEPT. This option expects the server reads from the accepted
|
||||
// connection before writing to them.
|
||||
//
|
||||
// - TCP_FASTOPEN. See https://lwn.net/Articles/508865/ for details.
|
||||
"github.com/valyala/tcplisten"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
// $ go get github.com/valyala/tcplisten
|
||||
// $ go run main.go
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML("<b>Hello World!</b>")
|
||||
})
|
||||
|
||||
listenerCfg := tcplisten.Config{
|
||||
ReusePort: true,
|
||||
DeferAccept: true,
|
||||
FastOpen: true,
|
||||
}
|
||||
|
||||
l, err := listenerCfg.NewListener("tcp", ":8080")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app.Run(iris.Listener(l))
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
panic("windows operating system does not support this feature")
|
||||
}
|
|
@ -13,10 +13,9 @@ import (
|
|||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// output startup banner and error logs on os.Stdout
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
|
||||
ctx.HTML("<h1>hi, I just exist in order to see if the server is closed</h1>")
|
||||
})
|
||||
|
||||
go func() {
|
||||
|
@ -33,16 +32,16 @@ func main() {
|
|||
)
|
||||
select {
|
||||
case <-ch:
|
||||
println("Shutdown the server gracefully...")
|
||||
println("shutdown...")
|
||||
|
||||
timeout := 5 * time.Second // give the server 5 seconds to wait for idle connections.
|
||||
timeout := 5 * time.Second
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
app.Shutdown(ctx)
|
||||
}
|
||||
}()
|
||||
|
||||
// Start the server and disable the default interrupt handler in order to handle it clear and simple by our own, without
|
||||
// any issues.
|
||||
// Start the server and disable the default interrupt handler in order to
|
||||
// handle it clear and simple by our own, without any issues.
|
||||
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler)
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
// Before continue:
|
||||
//
|
||||
// Gracefully Shutdown on control+C/command+C or when kill command sent is ENABLED BY-DEFAULT.
|
||||
//
|
||||
// In order to manually manage what to do when app is interrupted,
|
||||
// We have to disable the default behavior with the option `WithoutInterruptHandler`
|
||||
// and register a new interrupt handler (globally, across all possible hosts).
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
iris.RegisterOnInterrupt(func() {
|
||||
timeout := 5 * time.Second
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
// close all hosts
|
||||
app.Shutdown(ctx)
|
||||
})
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
|
||||
})
|
||||
|
||||
// http://localhost:8080
|
||||
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler)
|
||||
}
|
|
@ -9,7 +9,7 @@ func main() {
|
|||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML("<h1>Index /</h1>")
|
||||
ctx.HTML("<h1>Hello World!/</h1>")
|
||||
})
|
||||
|
||||
if err := app.Run(iris.Addr(":8080")); err != nil {
|
|
@ -22,7 +22,7 @@ func main() {
|
|||
})
|
||||
|
||||
// If http to https auto-redirect is one of your needs
|
||||
// please look the code inside iris_deprecateed.go.ListenLETSENCRYPT to do it manually.
|
||||
// please look the code inside ion_deprecateed.go.ListenLETSENCRYPT to do it manually.
|
||||
|
||||
// NOTE: This may not work on local addresses like this,
|
||||
// use it on a real domain, because
|
19
_examples/http-listening/listen-unix/main.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/core/netutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
l, err := netutil.UNIX("/tmpl/srv.sock", 0666) // see its code to see how you can manually create a new file listener, it's easy.
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app.Run(iris.Listener(l))
|
||||
}
|
||||
|
||||
// Look "custom-listener/unix-reuseport" too.
|
1
_examples/http_request/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
The `context.Request()` returns the same *http.Request you already know, the examples show some places where the Context uses this object. Besides that you can use it as you did before iris.
|
|
@ -17,7 +17,7 @@ func main() {
|
|||
app := iris.New()
|
||||
|
||||
// set the view html template engine
|
||||
app.AttachView(view.HTML("./templates", ".html").Reload(true))
|
||||
app.RegisterView(view.HTML("./templates", ".html").Reload(true))
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
if err := ctx.View("form.html"); err != nil {
|
|
@ -31,7 +31,7 @@ func main() {
|
|||
// to the http://localhost:8080 with RAW BODY:
|
||||
/*
|
||||
{
|
||||
"Name": "Iris-Go",
|
||||
"Name": "iris-Go",
|
||||
"City": "New York",
|
||||
"Other": "Something here"
|
||||
}
|
||||
|
@ -39,6 +39,6 @@ func main() {
|
|||
// and Content-Type to application/json
|
||||
//
|
||||
// The response should be:
|
||||
// Received: &main.Company{Name:"Iris-Go", City:"New York", Other:"Something here"}
|
||||
// Received: &main.Company{Name:"iris-Go", City:"New York", Other:"Something here"}
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -16,7 +16,7 @@ import (
|
|||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.AttachView(view.HTML("./templates", ".html"))
|
||||
app.RegisterView(view.HTML("./templates", ".html"))
|
||||
|
||||
// Serve the form.html to the user
|
||||
app.Get("/upload", func(ctx context.Context) {
|
1
_examples/http_responsewriter/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
The `context.ResponseWriter()` returns an enchament version of a http.ResponseWriter, the examples show some places where the Context uses this object. Besides that you can use it as you did before iris.
|
|
@ -32,7 +32,7 @@ func main() {
|
|||
|
||||
// OPTIONAl STEP:
|
||||
// but useful if we want to post back an error message to the client if the transaction failed.
|
||||
// if the reason is empty then the transaction completed succesfuly,
|
||||
// if the reason is empty then the transaction completed successfully,
|
||||
// otherwise we rollback the whole response writer's body,
|
||||
// headers and cookies, status code and everything lives inside this transaction
|
||||
t.Complete(err)
|
|
@ -5,9 +5,16 @@ import (
|
|||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/view"
|
||||
)
|
||||
|
||||
// User bind struct
|
||||
type User struct {
|
||||
Firstname string `json:"firstname"`
|
||||
Lastname string `json:"lastname"`
|
||||
City string `json:"city"`
|
||||
Age int `json:"age"`
|
||||
}
|
||||
|
||||
// ExampleXML just a test struct to view represents xml content-type
|
||||
type ExampleXML struct {
|
||||
XMLName xml.Name `xml:"example"`
|
||||
|
@ -18,8 +25,32 @@ type ExampleXML struct {
|
|||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
// Just some general restful render types, none of these has to do anything with templates.
|
||||
app.Get("/binary", func(ctx context.Context) { // useful when you want force-download of contents of raw bytes form.
|
||||
// Read
|
||||
app.Post("/decode", func(ctx context.Context) {
|
||||
var user User
|
||||
ctx.ReadJSON(&user)
|
||||
|
||||
ctx.Writef("%s %s is %d years old and comes from %s!", user.Firstname, user.Lastname, user.Age, user.City)
|
||||
})
|
||||
|
||||
// Write
|
||||
app.Get("/encode", func(ctx context.Context) {
|
||||
peter := User{
|
||||
Firstname: "John",
|
||||
Lastname: "Doe",
|
||||
City: "Neither FBI knows!!!",
|
||||
Age: 25,
|
||||
}
|
||||
|
||||
ctx.StatusCode(iris.StatusOK)
|
||||
// Manually setting a content type: ctx.ContentType("application/javascript")
|
||||
ctx.JSON(peter)
|
||||
})
|
||||
|
||||
// Other content types,
|
||||
|
||||
app.Get("/binary", func(ctx context.Context) {
|
||||
// useful when you want force-download of contents of raw bytes form.
|
||||
ctx.Binary([]byte("Some binary data here."))
|
||||
})
|
||||
|
||||
|
@ -40,38 +71,17 @@ func main() {
|
|||
})
|
||||
|
||||
app.Get("/markdown", func(ctx context.Context) {
|
||||
ctx.Markdown([]byte("# Hello Dynamic Markdown -- Iris"))
|
||||
ctx.Markdown([]byte("# Hello Dynamic Markdown -- iris"))
|
||||
})
|
||||
|
||||
// http://localhost:8080/decode
|
||||
// http://localhost:8080/encode
|
||||
//
|
||||
|
||||
// - standard html | view.HTML(...)
|
||||
// - django | view.Django(...)
|
||||
// - pug(jade) | view.Pug(...)
|
||||
// - handlebars | view.Handlebars(...)
|
||||
// - amber | view.Amber(...)
|
||||
// with default template funcs:
|
||||
//
|
||||
// - {{ urlpath "mynamedroute" "pathParameter_ifneeded" }}
|
||||
// - {{ render "header.html" }}
|
||||
// - {{ render_r "header.html" }} // partial relative path to current page
|
||||
// - {{ yield }}
|
||||
// - {{ current }}
|
||||
app.AttachView(view.HTML("./templates", ".html"))
|
||||
app.Get("/template", func(ctx context.Context) {
|
||||
|
||||
ctx.ViewData("Name", "Iris") // the .Name inside the ./templates/hi.html
|
||||
ctx.Gzip(true) // enable gzip for big files
|
||||
ctx.View("hi.html") // render the template with the file name relative to the './templates'
|
||||
|
||||
})
|
||||
|
||||
// http://localhost:8080/binary
|
||||
// http://localhost:8080/text
|
||||
// http://localhost:8080/json
|
||||
// http://localhost:8080/jsonp
|
||||
// http://localhost:8080/xml
|
||||
// http://localhost:8080/markdown
|
||||
// http://localhost:8080/template
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
|
||||
"github.com/kataras/iris/typescript" // optionally
|
||||
"github.com/kataras/iris/typescript/editor"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// adapt a router, order doesn't matters
|
||||
|
||||
// optionally but good to have, I didn't put inside editor or the editor in the typescript compiler adaptors
|
||||
// because you may use tools like gulp and you may use the editor without the typescript compiler adaptor.
|
||||
// but if you need auto-compilation on .ts, we have a solution:
|
||||
ts := typescript.New()
|
||||
ts.Config.Dir = "./www/scripts/"
|
||||
ts.Attach(app) // attach the typescript compiler adaptor
|
||||
|
||||
editorConfig := editor.Config{
|
||||
Hostname: "localhost",
|
||||
Port: 4444,
|
||||
WorkingDir: "./www/scripts/", // "/path/to/the/client/side/directory/",
|
||||
Username: "myusername",
|
||||
Password: "mypassword",
|
||||
}
|
||||
e := editor.New(editorConfig)
|
||||
e.Attach(app) // attach the editor
|
||||
|
||||
app.StaticWeb("/", "./www") // serve the index.html
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/host"
|
||||
)
|
||||
|
||||
// Before continue, please read the below notes:
|
||||
//
|
||||
// Current version of Iris is auto-graceful on control+C/command+C
|
||||
// or kill command sent or whenever app.Shutdown called.
|
||||
//
|
||||
// In order to add a custom interrupt handler(ctrl+c/cmd+c) or
|
||||
// shutdown manually you have to "schedule a host supervisor's task" or
|
||||
// use the core/host package manually or use a pure http.Server as we already seen at "custom-server" example.
|
||||
//
|
||||
// At this example, we will disable the interrupt handler and set our own interrupt handler.
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// output startup banner and error logs on os.Stdout
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
|
||||
})
|
||||
|
||||
// tasks are always running in their go-routine by-default.
|
||||
//
|
||||
// register custom interrupt handler, fires when ctrl+C/cmd+C pressed or kill command sent.
|
||||
app.Scheduler.Schedule(host.OnInterrupt(func(proc host.TaskProcess) {
|
||||
println("Shutdown the server gracefully...")
|
||||
|
||||
timeout := 5 * time.Second // give the server 5 seconds to wait for idle connections.
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
proc.Host().Shutdown(ctx) // Shutdown the underline supervisor's server
|
||||
}))
|
||||
|
||||
// Start the server and disable the default interrupt handler in order to use our scheduled interrupt task.
|
||||
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler)
|
||||
}
|
||||
|
||||
// Note:
|
||||
// You can just use an http.Handler with your own signal notify channel and do that as you did with the net/http
|
||||
// package. I will not show this way, but you can find many examples on the internet.
|
|
@ -1,72 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
stdContext "context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/host"
|
||||
)
|
||||
|
||||
// The difference from its parent main.go is that
|
||||
// with a custom host we're able to call the host's shutdown
|
||||
// and be notified about its .Shutdown call.
|
||||
// Almost the same as before.
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// output startup banner and error logs on os.Stdout
|
||||
|
||||
app.Get("/", func(ctx context.Context) {
|
||||
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
|
||||
})
|
||||
|
||||
// build the framework when all routing-relative actions are declared.
|
||||
if err := app.Build(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// create our custom host supervisor by adapting
|
||||
// a custom http server
|
||||
srv := host.New(&http.Server{Addr: ":8080", Handler: app})
|
||||
|
||||
// tasks are always running in their go-routine by-default.
|
||||
//
|
||||
// register custom interrupt handler, fires when ctrl+C/cmd+C pressed or kill command sent, as we did before.
|
||||
srv.Schedule(host.OnInterrupt(func(proc host.TaskProcess) {
|
||||
println("Shutdown the server gracefully...")
|
||||
|
||||
timeout := 5 * time.Second // give the server 5 seconds to wait for idle connections.
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
proc.Host().DeferFlow() // defer the exit, in order to catch the event
|
||||
srv.Shutdown(ctx) // Shutdown the supervisor, only this way the proc.Host().Done will be notified
|
||||
// the proc.Host().Shutdown, closes the underline server but no the supervisor.
|
||||
// This behavior was choosen because is inneed for custom maintanance services
|
||||
// (i.e restart server every week without loosing connections) which you can easly adapt with Iris.
|
||||
}))
|
||||
|
||||
// schedule a task to be notify when the server was closed by our interrutp handler,
|
||||
// optionally ofcourse.
|
||||
srv.ScheduleFunc(func(proc host.TaskProcess) {
|
||||
select {
|
||||
case <-proc.Host().Done(): // when .Host.Shutdown(ctx) called.
|
||||
println("Server was closed.")
|
||||
proc.Host().RestoreFlow() // Restore the flow in order to exit(continue after the srv.ListenAndServe)
|
||||
}
|
||||
})
|
||||
|
||||
// Start our custom host
|
||||
println("Server is running at :8080")
|
||||
srv.ListenAndServe()
|
||||
// Go to the console and press ctrl+c(for windows and linux) or cmd+c for osx.
|
||||
// The output should be:
|
||||
// Server is running at:8080
|
||||
// Shutdown the server gracefully...
|
||||
// Server was closed.
|
||||
}
|
||||
|
||||
// Note:
|
||||
// You can just use an http.Handler with your own signal notify channel and do that as you did with the net/http
|
||||
// package. I will not show this way, but you can find many examples on the internet.
|
|
@ -1 +0,0 @@
|
|||
hi = Γεια, %s
|
|
@ -1,28 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func HashPassword(password string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
func CheckPasswordHash(password, hash string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
password := "secret"
|
||||
hash, _ := HashPassword(password) // ignore error for the sake of simplicity
|
||||
|
||||
fmt.Println("Password:", password)
|
||||
fmt.Println("Hash: ", hash)
|
||||
|
||||
match := CheckPasswordHash(password, hash)
|
||||
fmt.Println("Match: ", match)
|
||||
}
|
Before Width: | Height: | Size: 7.2 KiB |
Before Width: | Height: | Size: 7.2 KiB |