mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
one for today, one for tomorrow and ready :)
Former-commit-id: 2e0a335c84c1d9c57a61b7f3203e54f7cccd7dcc
This commit is contained in:
parent
75d710ce90
commit
64da28af8b
1832
HISTORY.md
1832
HISTORY.md
File diff suppressed because it is too large
Load Diff
142
README.md
142
README.md
|
@ -1,32 +1,22 @@
|
|||
# Iris Web Framework
|
||||
# Iris web framework
|
||||
|
||||
[![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)[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)[![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)[![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)[![CLA assistant](https://cla-assistant.io/readme/badge/kataras/iris?style=flat-square)](https://cla-assistant.io/kataras/iris)
|
||||
<img align="right" width="105px" src="logo.svg" alt="Iris Logo: 2018" title="logo created by @merry.dii" />
|
||||
|
||||
Iris is a fast, simple and efficient web framework for Go.
|
||||
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris) <!-- [![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)--> [![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris) [![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed) [![chat](https://img.shields.io/badge/community-%20chat-00BCD4.svg?style=flat-square)](https://kataras.rocket.chat/channel/iris) [![view examples](https://img.shields.io/badge/learn%20by-examples-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/tree/master/_examples) [![release](https://img.shields.io/badge/release%20-v10.0-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
|
||||
Iris provides a beautifully expressive and easy to use foundation for your next website, API, or distributed app.
|
||||
Iris is a fast, simple yet fully featured and very efficient web framework for Go.
|
||||
|
||||
Learn what [others say about Iris](https://www.youtube.com/watch?v=jGx0LkuUs4A) and [star](https://github.com/kataras/iris/stargazers) this github repository to stay [up to date](https://facebook.com/iris.framework).
|
||||
Iris provides a beautifully expressive and easy to use foundation for your next website or API.
|
||||
|
||||
Finally, a real expressjs equivalent for the Go Programming Language.
|
||||
|
||||
## Sponsors
|
||||
Learn what [others say about Iris](#support) and [star](https://github.com/kataras/iris/stargazers) this github repository to stay [up to date](https://facebook.com/iris.framework).
|
||||
|
||||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor](https://opencollective.com/iris#sponsor)
|
||||
## Backers
|
||||
|
||||
<a href="https://opencollective.com/iris/sponsor/0/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/1/website" target="_blank">
|
||||
Thank you to all our backers! [Become a backer](https://opencollective.com/iris#backer)
|
||||
|
||||
## [Benchmarks](_benchmarks)
|
||||
|
||||
[![Iris vs .NET Core(C#) vs Node.js (Express)](https://iris-go.com/images/benchmark-new-gray.png)](_benchmarks/README_UNIX.md)
|
||||
|
||||
<details>
|
||||
<summary>Benchmarks from third-party source over the rest web frameworks</summary>
|
||||
|
||||
![Comparison with other frameworks](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
|
||||
|
||||
_Updated at: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_
|
||||
</details>
|
||||
<a href="https://opencollective.com/iris#backers" target="_blank"><img src="https://opencollective.com/iris/backers.svg?width=890"></a>
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -38,12 +28,103 @@ $ go get -u github.com/kataras/iris
|
|||
|
||||
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.
|
||||
|
||||
### Learn
|
||||
[![Iris vs .NET Core(C#) vs Node.js (Express)](https://iris-go.com/images/benchmark-new-gray.png)](_benchmarks/README_UNIX.md)
|
||||
|
||||
[![](cheatsheet.png)](https://iris-go.com/v10)
|
||||
_Updated at: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_
|
||||
|
||||
## Articles
|
||||
<details>
|
||||
<summary>Benchmarks from third-party source over the rest web frameworks</summary>
|
||||
|
||||
![Comparison with other frameworks](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
|
||||
|
||||
</details>
|
||||
|
||||
## Support
|
||||
|
||||
- [HISTORY](HISTORY.md) file is your best friend, it contains information about all the new features for the current release, you can even search for [older versions](https://github.com/kataras/iris/releases)
|
||||
- Did you happen to find a bug? Post it at [github issues](https://github.com/kataras/iris/issues)
|
||||
- Do you have any questions or need to speak with someone experienced to solve a problem at real-time? Join us to the [community chat](https://chat.iris-go.com)
|
||||
- Do you like the framework? Tweet something about it! The People have spoken:
|
||||
|
||||
<a href="https://twitter.com/gelnior/status/769100480706379776">
|
||||
<img src="https://comments.iris-go.com/comment27_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/MeAlex07/status/822799954188075008">
|
||||
<img src="https://comments.iris-go.com/comment28_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/_mgale/status/818591490305761280">
|
||||
<img src="https://comments.iris-go.com/comment29_mini.png" width="350px">
|
||||
</a>
|
||||
<a href="https://twitter.com/VeayoX/status/813273328550973440">
|
||||
<img src="https://comments.iris-go.com/comment30_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/pvsukale/status/745328224876408832">
|
||||
<img src="https://comments.iris-go.com/comment31_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/blainsmith/status/745338092211560453">
|
||||
<img src="https://comments.iris-go.com/comment32_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/tjbyte/status/758287014210867200">
|
||||
<img src="https://comments.iris-go.com/comment33_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/tangzero/status/751050577220698112">
|
||||
<img src="https://comments.iris-go.com/comment34_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/tjbyte/status/758287244947972096">
|
||||
<img src="https://comments.iris-go.com/comment33_2_mini.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/sgryphon/status/912073318928232448">
|
||||
<img src="https://comments.iris-go.com/comment40.png" width="350px">
|
||||
</a>
|
||||
|
||||
<a href="https://twitter.com/ferarias/status/902468752364773376">
|
||||
<img src="https://comments.iris-go.com/comment41.png" width="350px">
|
||||
</a>
|
||||
|
||||
For more information about contributing to the Iris project please check the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
||||
|
||||
[List of all Contributors](https://github.com/kataras/iris/graphs/contributors)
|
||||
|
||||
## Learn
|
||||
|
||||
First of all, the most correct way to begin with a web framework is to learn the basics of the programming language and the standard `http` capabilities, if your web application is a very simple personal project without performance and maintainability requirements you may want to proceed just with the standard packages. After that follow the guidelines:
|
||||
|
||||
- Navigate through **100+1** **[examples](_examples)** and some [iris starter kits](#iris-starter-kits) we crafted for you
|
||||
- Read the [godocs](https://godoc.org/github.com/kataras/iris) for any details
|
||||
- Prepare a cup of coffee or tea, whatever pleasures you the most, and read some [articles](#articles) we found for you
|
||||
|
||||
### Iris starter kits
|
||||
|
||||
| Description | Link |
|
||||
| -----------|-------------|
|
||||
| Hasura hub starter project with a ready to deploy golang helloworld webapp with IRIS! | https://hasura.io/hub/project/hasura/hello-golang-iris |
|
||||
| A basic web app built in Iris for Go |https://github.com/gauravtiwari/go_iris_app |
|
||||
| A mini social-network created with the awesome Iris💖💖 | https://github.com/iris-contrib/Iris-Mini-Social-Network |
|
||||
| Iris isomorphic react/hot reloadable/redux/css-modules starter kit | https://github.com/iris-contrib/iris-starter-kit |
|
||||
| Demo project with react using typescript and Iris | https://github.com/ionutvilie/react-ts |
|
||||
| Self-hosted Localization Management Platform built with Iris and Angular | https://github.com/iris-contrib/parrot |
|
||||
| Iris + Docker and Kubernetes | https://github.com/iris-contrib/cloud-native-go |
|
||||
| Quickstart for Iris with Nanobox | https://guides.nanobox.io/golang/iris/from-scratch |
|
||||
|
||||
> Did you build something similar? Let us [know](https://github.com/kataras/iris/pulls)!
|
||||
|
||||
### Middleware
|
||||
|
||||
Iris has a great collection of handlers[[1]](middleware/)[[2]](https://github.com/iris-contrib/middleware) that you can use side by side with your web apps. However you are not limited to them - you are free to use any third-party middleware that is compatible with the [net/http](https://golang.org/pkg/net/http/) package, [_examples/convert-handlers](_examples/convert-handlers) will show you the way.
|
||||
|
||||
Iris, unlike others, is 100% compatible with the standards and that's why the majority of the big companies that adapt Go to their workflow, like a very famous US Television Network, trust Iris; it's always up-to-date and it will be aligned with the std `net/http` package which is modernized by the Go Author on each new release of the Go Programming Language forever.
|
||||
|
||||
### Articles
|
||||
|
||||
* [A Hasura starter project with a ready to deploy Golang hello-world web app with IRIS](bit.ly/2lmKaAZ)
|
||||
* [Top 6 web frameworks for Go as of 2017](https://blog.usejournal.com/top-6-web-frameworks-for-go-as-of-2017-23270e059c4b)
|
||||
* [Iris Go Framework + MongoDB](https://medium.com/go-language/iris-go-framework-mongodb-552e349eab9c)
|
||||
* [How to build a file upload form using DropzoneJS and Go](https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991)
|
||||
|
@ -55,14 +136,19 @@ Iris takes advantage of the [vendor directory](https://docs.google.com/document/
|
|||
* [Deploying a Iris Golang app in hasura](https://medium.com/@HasuraHQ/deploy-an-iris-golang-app-with-backend-apis-in-minutes-25a559bf530b)
|
||||
* [A URL Shortener Service using Go, Iris and Bolt](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
|
||||
|
||||
[List of all Contributors](https://github.com/kataras/iris/graphs/contributors)
|
||||
### Get hired
|
||||
|
||||
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras) or [BTC](https://iris-go.com/v8/donate).
|
||||
There are many companies and start-ups looking for Go web developers with Iris experience as requirement, we are searching for you every day and we post those information via our [facebook page](https://www.facebook.com/iris.framework), like the page to get notified, we have already posted some of them.
|
||||
|
||||
For more information about contributing to the Iris project please check the [CONTRIBUTING.md file](CONTRIBUTING.md).
|
||||
### Sponsors
|
||||
|
||||
Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/iris#sponsor))
|
||||
|
||||
<a href="https://opencollective.com/iris/sponsor/0/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/1/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/1/avatar.svg"></a>
|
||||
|
||||
## License
|
||||
|
||||
Iris is licensed under the 3-Clause BSD [License](LICENSE). Iris is 100% open-source software.
|
||||
Iris is licensed under the [3-Clause BSD License](LICENSE). Iris is 100% free and open-source software.
|
||||
|
||||
For any questions regarding the license please [contact us](mailto:kataras2006@hotmail.com?subject=Iris%20License).
|
||||
For any questions regarding the license please send [e-mail](mailto:kataras2006@hotmail.com?subject=Iris%20License).
|
||||
|
|
229
README_ZH.md
229
README_ZH.md
|
@ -1,229 +0,0 @@
|
|||
# [![Logo created by @santoshanand](logo_white_35_24.png)](https://iris-go.com) Iris
|
||||
|
||||
[![build status](https://img.shields.io/travis/kataras/iris/master.svg?style=flat-square)](https://travis-ci.org/kataras/iris)[![Backers on Open Collective](https://opencollective.com/iris/backers/badge.svg?style=flat-square)](#backers)[![Sponsors on Open Collective](https://opencollective.com/iris/sponsors/badge.svg?style=flat-square)](#sponsors)[![report card](https://img.shields.io/badge/report%20card-a%2B-ff3333.svg?style=flat-square)](http://goreportcard.com/report/kataras/iris)[![github closed issues](https://img.shields.io/github/issues-closed-raw/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/issues?q=is%3Aissue+is%3Aclosed)[![release](https://img.shields.io/github/release/kataras/iris.svg?style=flat-square)](https://github.com/kataras/iris/releases)[![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)[![CLA assistant](https://cla-assistant.io/readme/badge/kataras/iris?style=flat-square)](https://cla-assistant.io/kataras/iris)
|
||||
|
||||
<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/Qw6E1MTHvUJW6BtwUUf9qwsy/kataras/iris'>
|
||||
<img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/Qw6E1MTHvUJW6BtwUUf9qwsy/kataras/iris.svg' />
|
||||
</a>
|
||||
|
||||
|
||||
Iris是一个超快、简单并且高效的Go语言Web开发框架。
|
||||
|
||||
Iris功能很强大,使用又很简单,它将会是你下一个网站、API服务或者分布式应用基础框架的不二之选。
|
||||
|
||||
看看[别人是如何评价Iris](https://www.youtube.com/watch?v=jGx0LkuUs4A),同时欢迎各位[成为Iris星探](https://github.com/kataras/iris/stargazers),或者关注[Iris facebook主页](https://facebook.com/iris.framework)。
|
||||
|
||||
[![Iris vs .NET Core(C#) vs Node.js (Express)](https://iris-go.com/images/benchmark-new-gray.png)](_benchmarks)
|
||||
|
||||
<details>
|
||||
<summary>上图是第三发机构发布的REST Web框架的基准测试</summary>
|
||||
|
||||
![Comparison with other frameworks](https://raw.githubusercontent.com/smallnest/go-web-framework-benchmark/4db507a22c964c9bc9774c5b31afdc199a0fe8b7/benchmark.png)
|
||||
|
||||
更新于: [2017年9月29,星期五](_benchmarks)_
|
||||
</details>
|
||||
|
||||
## 前言 ♥️
|
||||
|
||||
在发现Iris之前,我想你一定也看过其它Go Web开发框架。也许你已经摩拳擦掌并马上要使用了,但我会很遗憾的告诉你,将来你还是会使用Iris的。不仅仅因为Iris性能卓越和使用简单,更重要的是Iris独树一帜,他可以让你成为真正的极客界摇滚明星。
|
||||
|
||||
不管你是想开发微服务或者大型Web应用,Iris都能满足你的需求。Iris可能是你在网上能找到最好的Web后台开发软件之一了。
|
||||
|
||||
Iris现在已经到第8版了,但是我们从未停止开发。有很多非常棒的功能已经提上开发日程了,而且我们非常乐意加入很多有创意的想法。
|
||||
|
||||
如果你想用CDN加速,我推荐用[KeyCDN](https://www.keycdn.com/),因为KeyCDN简单、速度快而且稳定。
|
||||
|
||||
我们用[微软](https://www.microsoft.com)开发的[Visual Studio Code](https://code.visualstudio.com/)来开发Golang应用。
|
||||
|
||||
如果你之前使用[nodejs](https://nodejs.org)做开发,恭喜你,Iris使用基本和[expressjs](https://github.com/expressjs/express)一样。
|
||||
|
||||
## 内容列表
|
||||
|
||||
* [安装](#installation)
|
||||
* [最近更新](https://github.com/kataras/iris/blob/master/HISTORY.md#tu-07-november-2017--v857)
|
||||
* [快速入门](#getting-started)
|
||||
* [进阶](_examples/)
|
||||
* [MVC (模型 视图 控制器)](_examples/#mvc) **NEW**
|
||||
* [结构](_examples/#structuring) **NEW**
|
||||
* [HTTP 监听](_examples/#http-listening)
|
||||
* [配置](_examples/#configuration)
|
||||
* [路由,分组,动态参数,“宏定义”已经自定义Context](_examples/#routing-grouping-dynamic-path-parameters-macros-and-custom-context)
|
||||
* [子域名处理](_examples/#subdomains)
|
||||
* [`http.Handler/HandlerFunc` 使用](_examples/#convert-httphandlerhandlerfunc)
|
||||
* [视图处理](_examples/#view)
|
||||
* [认证](_examples/#authentication)
|
||||
* [文件服务器](_examples/#file-server)
|
||||
* [如何从`context.Request() *http.Request` 读数据](_examples/#how-to-read-from-contextrequest-httprequest)
|
||||
* [如何给`context.ResponseWriter() http.ResponseWriter`写数据](_examples/#how-to-write-to-contextresponsewriter-httpresponsewriter)
|
||||
* [测试](_examples/#testing)
|
||||
* [缓存](_examples/#caching)
|
||||
* [会话](_examples/#sessions)
|
||||
* [Websockets](_examples/#websockets)
|
||||
* [其它杂项](_examples/#miscellaneous)
|
||||
* [将"Parrot"项目转换为Iris实现](https://github.com/iris-contrib/parrot)
|
||||
* [Iris和react/hot reloadable/redux/css-modules配合使用](https://github.com/kataras/iris-starter-kit)
|
||||
* [Typescript自动化操作工具](typescript/#table-of-contents)
|
||||
* [指南: 用Iris和Bolt实现短连接服务](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
|
||||
* [指南: 如何统计在线访问人数](_examples/tutorial/online-visitors)
|
||||
* [指南: Caddy](_examples/tutorial/caddy)
|
||||
* [指南: 如何用DropzoneJS上传文件](https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991)
|
||||
* [指南: Iris+MongoDB](https://medium.com/go-language/iris-go-framework-mongodb-552e349eab9c)
|
||||
* [中间件](middleware/)
|
||||
* [Docker例子](https://github.com/iris-contrib/cloud-native-go)
|
||||
* [贡献](CONTRIBUTING.md)
|
||||
* [常见问题](FAQ.md)
|
||||
* [更新计划?](#now-you-are-ready-to-move-to-the-next-step-and-get-closer-to-becoming-a-pro-gopher)
|
||||
* [开发者](#people)
|
||||
|
||||
## 安装
|
||||
|
||||
仅仅依赖[Go语言](https://golang.org/dl/)
|
||||
|
||||
```sh
|
||||
$ go get -u github.com/kataras/iris
|
||||
```
|
||||
Iris使用[vendor](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) 包依赖管理方式。vendor包管理的方式可以有效处理包依赖更新问题
|
||||
|
||||
## 入门
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// 从"./views"目录加载HTML模板
|
||||
// 模板解析html后缀文件
|
||||
// 此方式是用`html/template`标准包(Iris的模板引擎)
|
||||
app.RegisterView(iris.HTML("./views", ".html"))
|
||||
|
||||
// HTTP方法: GET
|
||||
// 路径: http://localhost:8080
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
// {{.message}} 和 "Hello world!" 字串绑定
|
||||
ctx.ViewData("message", "Hello world!")
|
||||
// 映射HTML模板文件路径 ./views/hello.html
|
||||
ctx.View("hello.html")
|
||||
})
|
||||
|
||||
// HTTP方法: GET
|
||||
// 路径: http://localhost:8080/user/42
|
||||
//
|
||||
// 想在路径中用正则吗?So easy!
|
||||
// 如下所示
|
||||
// app.Get("/user/{id:string regexp(^[0-9]+$)}")
|
||||
app.Get("/user/{id:long}", func(ctx iris.Context) {
|
||||
userID, _ := ctx.Params().GetInt64("id")
|
||||
ctx.Writef("User ID: %d", userID)
|
||||
})
|
||||
|
||||
// 绑定端口并启动服务.
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
```
|
||||
|
||||
> 想要了解更多关于路径参数配置,戳[这里](https://github.com/kataras/iris/blob/master/_examples/routing/dynamic-path/main.go#L31).
|
||||
|
||||
```html
|
||||
<!-- file: ./views/hello.html -->
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{.message}}</h1>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```sh
|
||||
$ go run main.go
|
||||
> 在这里监听服务: http://localhost:8080
|
||||
> 应用已经启动按键 CTRL+C 停止服务
|
||||
```
|
||||
|
||||
> 想要实现当代码改变后自动重启应用吗?那就装个[rizla](https://github.com/kataras/rizla)工具,启动go文件用 `rizla main.go` 来代替 `go run main.go`。
|
||||
|
||||
Iris的一些开发约定可以看看这里[_examples/structuring](_examples/#structuring)。
|
||||
|
||||
|
||||
## 现在你已经准备好进入下一阶段,又向专家级gopher迈进一步了
|
||||
|
||||
恭喜你看到这里了,我们为你准备了更高水平的内容,向真正的专家级gopher进军吧😃
|
||||
|
||||
> 准备好咖啡,尽情享受吧!
|
||||
|
||||
* [Iris框架+MongoDB](https://medium.com/go-language/iris-go-framework-mongodb-552e349eab9c)
|
||||
* [用DropzoneJS 和 Go来构建表单文件上传](https://hackernoon.com/how-to-build-a-file-upload-form-using-dropzonejs-and-go-8fb9f258a991)
|
||||
* [用DropzoneJS 和 Go来呈现服务器上的问题](https://hackernoon.com/how-to-display-existing-files-on-server-using-dropzonejs-and-go-53e24b57ba19)
|
||||
* [Iris模块化Web开发框架](https://medium.com/@corebreaker/iris-web-cd684b4685c7)
|
||||
* [按照 HTTP 性能来比较Go 和 .NET Core](https://medium.com/@kataras/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8)
|
||||
* [按照 HTTP 性能来比较Go 和 .NET Core Kestrel](https://hackernoon.com/iris-go-vs-net-core-kestrel-in-terms-of-http-performance-806195dc93d5)
|
||||
* [在Android设备上搭建Web服务器](https://twitter.com/ThePracticalDev/status/892022594031017988)
|
||||
* [在hasura上部署Iris应用](https://medium.com/@HasuraHQ/deploy-an-iris-golang-app-with-backend-apis-in-minutes-25a559bf530b)
|
||||
* [用Iris 和 Bolt实现短连接服务](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
|
||||
|
||||
## 作者
|
||||
|
||||
Iris的作者是[@kataras](https://github.com/kataras), 你可以通过以下方式来了解作者:
|
||||
|
||||
* [Medium](https://medium.com/@kataras)
|
||||
* [Twitter](https://twitter.com/makismaropoulos)
|
||||
* [Dev.to](https://dev.to/@kataras)
|
||||
* [Facebook](https://facebook.com/iris.framework)
|
||||
* [Mail](mailto:kataras2006@hotmail.com?subject=Iris%20I%20need%20some%20help%20please)
|
||||
|
||||
[作者](AUTHORS)
|
||||
|
||||
[贡献者列表](https://github.com/kataras/iris/graphs/contributors)
|
||||
|
||||
你可以通过[PayPal](https://www.paypal.me/kataras) 或 [BTC](https://iris-go.com/v8/donate)来捐赠这个项目,这样可以促进开发者们创造更棒、更优秀的Iris。
|
||||
|
||||
[如何贡献代码](CONTRIBUTING.md)
|
||||
|
||||
### 我们期待你能帮助我们翻译Iris文档
|
||||
|
||||
Iris需要你的帮助,帮助我们翻译[README](README.md)和https://iris-go.com ,同时你也会得到奖励的。
|
||||
|
||||
你可以在这里https://github.com/kataras/iris/issues/796 看到详细的有关翻译的信息
|
||||
|
||||
|
||||
### Iris 用户体验反馈 | 2017年10月3号
|
||||
|
||||
**请放心** Iris用户体验反馈就是一些简单的表单提交,**2分钟**就能搞定。
|
||||
|
||||
这些表单里有些问题是为了更好的了解你,了解你可以让我们更好的为你服务。
|
||||
|
||||
https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link
|
||||
|
||||
## 贡献者列表
|
||||
|
||||
非常感谢所有对Iris的贡献者,没有你们就没有Iris [贡献者](CONTRIBUTING.md)
|
||||
<a href="graphs/contributors"><img src="https://opencollective.com/iris/contributors.svg?width=890" /></a>
|
||||
|
||||
## 资助者
|
||||
|
||||
万分感谢所有的资助者🙏 [成为资助者](https://opencollective.com/iris#backer)
|
||||
|
||||
<a href="https://opencollective.com/iris#backers" target="_blank"><img src="https://opencollective.com/iris/backers.svg?width=890"></a>
|
||||
|
||||
## 赞助商
|
||||
|
||||
资助Iris,你将是Iris的赞助商,你的logo将会出现在下面的列表中,[成为赞助商](https://opencollective.com/iris#sponsor)
|
||||
|
||||
<a href="https://opencollective.com/iris/sponsor/0/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/1/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/2/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/3/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/4/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/5/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/6/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/7/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/8/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/iris/sponsor/9/website" target="_blank"><img src="https://opencollective.com/iris/sponsor/9/avatar.svg"></a>
|
||||
|
||||
## 开源许可证
|
||||
|
||||
Iris使用3-Clause BSD [许可证](LICENSE)开源许可 。Iris绝对是100%开源的。
|
||||
对这个许可有任何疑问请[联系我们](mailto:kataras2006@hotmail.com?subject=Iris%20License)
|
|
@ -11,6 +11,7 @@ It doesn't always contain the "best ways" but it does cover each important featu
|
|||
- [Hello world!](hello-world/main.go)
|
||||
- [Glimpse](overview/main.go)
|
||||
- [Tutorial: Online Visitors](tutorial/online-visitors/main.go)
|
||||
- [Tutorial: Vue.js Todo MVC](tutorial/vuejs-todo-mvc)
|
||||
- [Tutorial: URL Shortener using BoltDB](https://medium.com/@kataras/a-url-shortener-service-using-go-iris-and-bolt-4182f0b00ae7)
|
||||
- [Tutorial: How to turn your Android Device into a fully featured Web Server (**MUST**)](https://twitter.com/ThePracticalDev/status/892022594031017988)
|
||||
- [POC: Convert the medium-sized project "Parrot" from native to Iris](https://github.com/iris-contrib/parrot)
|
||||
|
@ -18,7 +19,6 @@ It doesn't always contain the "best ways" but it does cover each important featu
|
|||
- [Tutorial: DropzoneJS Uploader](tutorial/dropzonejs)
|
||||
- [Tutorial: Caddy](tutorial/caddy)
|
||||
- [Tutorial:Iris Go Framework + MongoDB](https://medium.com/go-language/iris-go-framework-mongodb-552e349eab9c)
|
||||
|
||||
### Structuring
|
||||
|
||||
Nothing stops you from using your favorite folder structure. Iris is a low level web framework, it has got MVC first-class support but it doesn't limit your folder structure, this is your choice.
|
||||
|
@ -253,17 +253,7 @@ Follow the examples below,
|
|||
- [Login showcase - Plus Repository and Service layers](mvc/login) **UPDATED**
|
||||
- [Singleton](mvc/singleton) **NEW**
|
||||
- [Websocket Controller](mvc/websocket) **NEW**
|
||||
|
||||
<!--
|
||||
Why updated?
|
||||
Old method works, as promised no breaking changes.
|
||||
But mvc.C as controller marker and mvc.Result on method functions return value
|
||||
is more lightweight and faster than `mvc.Controller` because `mvc.Controller` initializes
|
||||
some fields like `Data, Path`... and Data is a map even if not used, at the opossite hand
|
||||
`mvc.C` just initializes the context `Ctx` field, the dev has all the `mvc.Controller`'s features
|
||||
by the `mvc.Result` built'n types like `mvc.Response` and `mvc.View` PLUS she/he can
|
||||
convert any custom type into a response dispatcher by implementing the `mvc.Result` interface.
|
||||
-->
|
||||
- [Vue.js Todo MVC](tutorial/vuejs-todo-mvc) **NEW**
|
||||
|
||||
### Subdomains
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
// Optionally, add two built'n handlers
|
||||
// that can recover from any http-relative panics
|
||||
// and log the requests to the terminal.
|
||||
|
|
|
@ -31,38 +31,41 @@ func main() {
|
|||
})
|
||||
|
||||
// Handle the post request from the upload_form.html to the server
|
||||
app.Post("/upload", iris.LimitRequestBodySize(10<<20),
|
||||
func(ctx iris.Context) {
|
||||
// or use ctx.SetMaxRequestBodySize(10 << 20)
|
||||
// to limit the uploaded file(s) size.
|
||||
app.Post("/upload", func(ctx iris.Context) {
|
||||
// iris.LimitRequestBodySize(32 <<20) as middleware to a route
|
||||
// or use ctx.SetMaxRequestBodySize(32 << 20)
|
||||
// to limit the whole request body size,
|
||||
//
|
||||
// or let the configuration option at app.Run for global setting
|
||||
// for POST/PUT methods, including uploads of course.
|
||||
|
||||
// Get the file from the request
|
||||
file, info, err := ctx.FormFile("uploadfile")
|
||||
// Get the file from the request.
|
||||
file, info, err := ctx.FormFile("uploadfile")
|
||||
|
||||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.HTML("Error while uploading: <b>" + err.Error() + "</b>")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.HTML("Error while uploading: <b>" + err.Error() + "</b>")
|
||||
return
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
fname := info.Filename
|
||||
defer file.Close()
|
||||
fname := info.Filename
|
||||
|
||||
// Create a file with the same name
|
||||
// assuming that you have a folder named 'uploads'
|
||||
out, err := os.OpenFile("./uploads/"+fname,
|
||||
os.O_WRONLY|os.O_CREATE, 0666)
|
||||
// Create a file with the same name
|
||||
// assuming that you have a folder named 'uploads'
|
||||
out, err := os.OpenFile("./uploads/"+fname,
|
||||
os.O_WRONLY|os.O_CREATE, 0666)
|
||||
|
||||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.HTML("Error while uploading: <b>" + err.Error() + "</b>")
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
if err != nil {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.HTML("Error while uploading: <b>" + err.Error() + "</b>")
|
||||
return
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
io.Copy(out, file)
|
||||
})
|
||||
io.Copy(out, file)
|
||||
})
|
||||
|
||||
// start the server at http://localhost:8080
|
||||
app.Run(iris.Addr(":8080"))
|
||||
// start the server at http://localhost:8080 with post limit at 32 MB.
|
||||
app.Run(iris.Addr(":8080"), iris.WithPostMaxMemory(32<<20))
|
||||
}
|
||||
|
|
|
@ -32,17 +32,25 @@ func TodoApp(app *mvc.Application) {
|
|||
&prefixedLogger{prefix: "DEV"},
|
||||
)
|
||||
|
||||
// GET: http://localhost:8080/todo
|
||||
// GET: http://localhost:8080/todo/custom
|
||||
app.Handle(new(TodoController))
|
||||
|
||||
// All dependencies of the parent *mvc.Application
|
||||
// are cloned to that new child, thefore it has access to the same session as well.
|
||||
// are cloned to this new child,
|
||||
// thefore it has access to the same session as well.
|
||||
// GET: http://localhost:8080/todo/sub
|
||||
app.Party("/sub").
|
||||
Handle(new(TodoSubController))
|
||||
}
|
||||
|
||||
// If controller's fields (or even its functions) expecting an interface
|
||||
// but a struct value is binded then it will check if that struct value implements
|
||||
// the interface and if true then it will bind it as expected.
|
||||
// but a struct value is binded then it will check
|
||||
// if that struct value implements
|
||||
// the interface and if true then it will add this to the
|
||||
// available bindings, as expected, before the server ran of course,
|
||||
// remember? Iris always uses the best possible way to reduce load
|
||||
// on serving web resources.
|
||||
|
||||
type LoggerService interface {
|
||||
Log(string)
|
||||
|
|
|
@ -65,7 +65,7 @@ func (c *websocketController) update() {
|
|||
// visits++
|
||||
newCount := increment()
|
||||
|
||||
// This will call the "visit" event on all clients, incuding the current
|
||||
// This will call the "visit" event on all clients, including the current
|
||||
// with the 'newCount' variable.
|
||||
//
|
||||
// There are many ways that u can do it and faster, for example u can just send a new visitor
|
||||
|
|
|
@ -82,7 +82,7 @@ func (c *Controller) PostRegister(form formValue) mvc.Result {
|
|||
// you can use variables-- that are initialized before server start
|
||||
// so you can win some time on serving.
|
||||
// You can do it else where as well but I let them as pracise for you,
|
||||
// essentialy you can understand by just looking below.
|
||||
// essentially you can understand by just looking below.
|
||||
var userLoginView = mvc.View{
|
||||
Name: PathLogin.Path + ".html",
|
||||
Data: page{"User Login"},
|
||||
|
|
|
@ -1 +1,43 @@
|
|||
# Unfinished - wait until today :)
|
||||
# A Todo MVC Application using Iris and Vue.js
|
||||
|
||||
## The Tools
|
||||
|
||||
Programming Languages are just tools for us, but we need a safe, fast and “cross-platform” programming language to power our service.
|
||||
|
||||
[Go](https://golang.org) is a [rapidly growing](https://www.tiobe.com/tiobe-index/) open source programming language designed for building simple, fast, and reliable software. Take a look [here](https://github.com/golang/go/wiki/GoUsers) which great companies use Go to power their services.
|
||||
|
||||
### Install the Go Programming Language
|
||||
|
||||
Extensive information about downloading & installing Go can be found [here](https://golang.org/dl/).
|
||||
|
||||
[![](https://i3.ytimg.com/vi/9x-pG3lvLi0/hqdefault.jpg)](https://youtu.be/9x-pG3lvLi0)
|
||||
|
||||
> Maybe [Windows](https://www.youtube.com/watch?v=WT5mTznJBS0) or [Mac OS X](https://www.youtube.com/watch?v=5qI8z_lB5Lw) user?
|
||||
|
||||
> The article does not contain an introduction to the language itself, if you’re a newcomer I recommend you to bookmark this article, [learn](https://github.com/golang/go/wiki/Learn) the language’s fundamentals and come back later on.
|
||||
|
||||
## The Dependencies
|
||||
|
||||
Many articles have been written, in the past, that lead developers not to use a web framework because they are useless and "bad". I have to tell you that there is no such thing, it always depends on the (web) framework that you’re going to use. At production environment, we don’t have the time or the experience to code everything that we wanna use in the applications, and if we could are we sure that we can do better and safely than others? In short term: **Good frameworks are helpful tools for any developer, company or startup and "bad" frameworks are waste of time, crystal clear.**
|
||||
|
||||
You’ll need only two dependencies:
|
||||
|
||||
1. The Iris Web Framework, for our server-side requirements. Can be found [here](https://github.com/kataras/iris)
|
||||
2. Vue.js, for our client-side requirements. Download it from [here](https://vuejs.org/)
|
||||
|
||||
> If you have Go already installed then just execute `go get -u github.com/kataras/iris` to install the Iris Web Framework.
|
||||
|
||||
## Start
|
||||
|
||||
If we are all in the same page, it’s time to learn how we can create a live todo application that will be easy to deploy and extend even more!
|
||||
|
||||
We're going to use a vue.js todo application which uses browser'
|
||||
s local storage and doesn't have any user-specified features like live sync between browser's tabs, you can find the original version inside the vue's [docs](https://vuejs.org/v2/examples/todomvc.html).
|
||||
|
||||
### The client-side (vue.js)
|
||||
|
||||
### The server-side (iris)
|
||||
|
||||
## References
|
||||
|
||||
https://vuejs.org/v2/examples/todomvc.html (using browser's local storage)
|
|
@ -85,7 +85,7 @@ func SendMessage(serverID, to, method, message string) error {
|
|||
|
||||
// SendtBytes broadcast a message to server
|
||||
func SendtBytes(serverID, to, method string, message []byte) error {
|
||||
// look https://github.com/kataras/iris/tree/master/adaptors/websocket/message.go , client.go and client.js
|
||||
// look https://github.com/kataras/iris/blob/master/websocket/message.go , client.go and client.js
|
||||
// to understand the buffer line:
|
||||
buffer := []byte(fmt.Sprintf("iris-websocket-message:%v;0;%v;%v;", method, serverID, to))
|
||||
buffer = append(buffer, message...)
|
||||
|
|
BIN
cheatsheet.png
BIN
cheatsheet.png
Binary file not shown.
Before Width: | Height: | Size: 249 KiB |
|
@ -523,8 +523,8 @@ type Configuration struct {
|
|||
RemoteAddrHeaders map[string]bool `json:"remoteAddrHeaders,omitempty" yaml:"RemoteAddrHeaders" toml:"RemoteAddrHeaders"`
|
||||
|
||||
// Other are the custom, dynamic options, can be empty.
|
||||
// This field used only by you to set any app's options you want
|
||||
// or by custom adaptors, it's a way to simple communicate between your adaptors (if any)
|
||||
// This field used only by you to set any app's options you want.
|
||||
//
|
||||
// Defaults to a non-nil empty map.
|
||||
Other map[string]interface{} `json:"other,omitempty" yaml:"Other" toml:"Other"`
|
||||
}
|
||||
|
|
|
@ -549,7 +549,22 @@ type Context interface {
|
|||
// The default form's memory maximum size is 32MB, it can be changed by the
|
||||
// `iris#WithPostMaxMemory` configurator at main configuration passed on `app.Run`'s second argument.
|
||||
FormFile(key string) (multipart.File, *multipart.FileHeader, error)
|
||||
|
||||
// UploadFormFiles uploads any received file(s) from the client
|
||||
// to the system physical location "destDirectory".
|
||||
// The root directory must already exists.
|
||||
// Note that it doesn't check if request body streamed.
|
||||
//
|
||||
// Returns the copied length as int64 and
|
||||
// a not nil error if at least one new file
|
||||
// can't be created due to the operating system's permissions or
|
||||
// http.ErrMissingFile if no file received.
|
||||
//
|
||||
// If you want to receive & accept files and manage them manually you can use the `context#FormFile`
|
||||
// instead and create a copy function that suits your needs, the below is for generic usage.
|
||||
//
|
||||
// The default form's memory maximum size is 32MB, it can be changed by the
|
||||
// `iris#WithPostMaxMemory` configurator at main configuration passed on `app.Run`'s second argument.
|
||||
UploadFormFiles(destDirectory string) (int64, error)
|
||||
// +------------------------------------------------------------+
|
||||
// | Custom HTTP Errors |
|
||||
// +------------------------------------------------------------+
|
||||
|
@ -1750,29 +1765,98 @@ func (ctx *context) PostValues(name string) []string {
|
|||
|
||||
// FormFile returns the first uploaded file that received from the client.
|
||||
//
|
||||
//
|
||||
// The default form's memory maximum size is 32MB, it can be changed by the
|
||||
// `iris#WithPostMaxMemory` configurator at main configuration passed on `app.Run`'s second argument.
|
||||
func (ctx *context) FormFile(key string) (multipart.File, *multipart.FileHeader, error) {
|
||||
// we don't have access to see if the request is body stream
|
||||
// and then the ParseMultipartForm can be useless
|
||||
// here but do it in order to apply the post limit,
|
||||
// the internal request.FormFile will not do it if that's filled
|
||||
// and it's not a stream body.
|
||||
ctx.request.ParseMultipartForm(ctx.Application().ConfigurationReadOnly().GetPostMaxMemory())
|
||||
return ctx.request.FormFile(key)
|
||||
}
|
||||
|
||||
// UploadFormFiles uploads any received file(s) from the client
|
||||
// to the system physical location "destDirectory".
|
||||
// The root directory must already exists.
|
||||
//
|
||||
// Note that it doesn't check if request body streamed.
|
||||
//
|
||||
// Returns the copied length as int64 and
|
||||
// a not nil error if at least one new file
|
||||
// can't be created due to the operating system's permissions or
|
||||
// http.ErrMissingFile if no file received.
|
||||
//
|
||||
// If you want to receive & accept files and manage them manually you can use the `context#FormFile`
|
||||
// instead and create a copy function that suits your needs, the below is for generic usage.
|
||||
//
|
||||
// The default form's memory maximum size is 32MB, it can be changed by the
|
||||
// `iris#WithPostMaxMemory` configurator at main configuration passed on `app.Run`'s second argument.
|
||||
func (ctx *context) UploadFormFiles(destDirectory string) (n int64, err error) {
|
||||
err = ctx.request.ParseMultipartForm(ctx.Application().ConfigurationReadOnly().GetPostMaxMemory())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if ctx.request.MultipartForm != nil {
|
||||
if fhs := ctx.request.MultipartForm.File; fhs != nil {
|
||||
for _, files := range fhs {
|
||||
for _, file := range files {
|
||||
n0, err0 := uploadTo(file, destDirectory)
|
||||
if err0 != nil {
|
||||
return 0, err0
|
||||
}
|
||||
n += n0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0, http.ErrMissingFile
|
||||
}
|
||||
|
||||
func uploadTo(fh *multipart.FileHeader, destDirectory string) (int64, error) {
|
||||
src, err := fh.Open()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer src.Close()
|
||||
|
||||
out, err := os.Create(filepath.Join(destDirectory, fh.Filename))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
return io.Copy(out, src)
|
||||
}
|
||||
|
||||
/* Good idea of mine but it doesn't work of course...
|
||||
// Go can't use `io.ReadCloser` function return value the same
|
||||
// as with other function that returns a `multipart.File`, even if
|
||||
// multipart.File is an `io.ReadCloser`.
|
||||
// So comment all those and implement a function inside the context itself.
|
||||
//
|
||||
// Copiable is the interface which should be completed
|
||||
// by files or not that intend to be used inside the `context#CopyFile`.
|
||||
// This interface allows testing file uploads to your http test as well.
|
||||
//
|
||||
// See `CopyFile` for more.
|
||||
type Copiable interface {
|
||||
Open() (io.ReadCloser, error)
|
||||
}
|
||||
// type Copiable interface {
|
||||
// Open() (io.ReadCloser, error)
|
||||
// }
|
||||
//
|
||||
|
||||
// CopyFile copies a `context#Copiable` "file", that can be acquired by a `context.FormFile`
|
||||
// as well, to the "dest".
|
||||
|
||||
// CopyFile copies a `context#Copiable` "file", that can be acquired by the second argument of
|
||||
// a `context.FormFile` (*multipart.FileHeader) as well, to the "dest".
|
||||
//
|
||||
// Returns the copied length as int64 and
|
||||
// an error if file is not exist, or new file can't be created or closed at the end.
|
||||
func CopyFile(file Copiable, dest string) (int64, error) {
|
||||
src, err := file.Open()
|
||||
src, err := fileOpen()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
@ -1787,6 +1871,8 @@ func CopyFile(file Copiable, dest string) (int64, error) {
|
|||
return io.Copy(out, src)
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// Redirect sends a redirect response to the client
|
||||
// to a specific url or relative path.
|
||||
// accepts 2 parameters string and an optional int
|
||||
|
|
6
iris.go
6
iris.go
|
@ -311,12 +311,6 @@ var (
|
|||
//
|
||||
// Examples: https://github.com/kataras/iris/tree/master/_examples/file-server
|
||||
StaticEmbeddedHandler = router.StaticEmbeddedHandler
|
||||
// CopyFile copies a `context#Copiable` "file", that can be acquired by a `context.FormFile`
|
||||
// as well, to the "dest".
|
||||
//
|
||||
// Returns the copied length as int64 and
|
||||
// an error if file is not exist, or new file can't be created or closed at the end.
|
||||
CopyFile = context.CopyFile
|
||||
// Gzip is a middleware which enables writing
|
||||
// using gzip compression, if client supports.
|
||||
//
|
||||
|
|
1
logo.svg
Normal file
1
logo.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB |
|
@ -132,6 +132,14 @@ func (s *Session) GetStringDefault(key string, defaultValue string) string {
|
|||
if v, ok := value.(string); ok {
|
||||
return v
|
||||
}
|
||||
|
||||
if v, ok := value.(int); ok {
|
||||
return strconv.Itoa(v)
|
||||
}
|
||||
|
||||
if v, ok := value.(int64); ok {
|
||||
return strconv.FormatInt(v, 10)
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
|
|
Loading…
Reference in New Issue
Block a user