mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
Update to version 10.5.0 | Read HISTORY.md for more
Former-commit-id: 41b1947aafa258d342bbf9d22baeecc946d198a4
This commit is contained in:
parent
2955edd81c
commit
66d367b255
21
HISTORY.md
21
HISTORY.md
|
@ -17,6 +17,27 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
|
|||
|
||||
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris` or let the automatic updater do that for you.
|
||||
|
||||
# Sa, 24 March 2018 | v10.5.0
|
||||
|
||||
### New
|
||||
|
||||
Add new client cache (helpers) middlewares for even faster static file servers. Read more [there](https://github.com/kataras/iris/pull/935).
|
||||
|
||||
### Breaking Change
|
||||
|
||||
Change the `Value<T>Default(<T>, error)` to `Value<T>Default(key, defaultValue) <T>` like `ctx.PostValueIntDefault` or `ctx.Values().GetIntDefault` or `sessions/session#GetIntDefault` or `context#URLParamIntDefault`.
|
||||
The proposal was made by @jefurry at https://github.com/kataras/iris/issues/937.
|
||||
|
||||
#### How to align your existing codebase
|
||||
|
||||
Just remove the second return value from these calls.
|
||||
|
||||
Nothing too special or hard to change here, think that in our 100+ [_examples](_examples) we had only two of them.
|
||||
|
||||
For example: at [_examples/mvc/basic/main.go line 100](_examples/mvc/basic/main.go#L100) the `count,_ := c.Session.GetIntDefault("count", 1)` **becomes now:** `count := c.Session.GetIntDefault("count", 1)`.
|
||||
|
||||
> Remember that if you can't upgrade then just don't, we dont have any security fixes in this release, but at some point you will have to upgrade for your own good, we always add new features that you will love to embrace!
|
||||
|
||||
# We, 14 March 2018 | v10.4.0
|
||||
|
||||
- fix `APIBuilder, Party#StaticWeb` and `APIBuilder, Party#StaticEmbedded` wrong strip prefix inside children parties
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
**Πώς να αναβαθμίσετε**: Ανοίξτε την γραμμή εντολών σας και εκτελέστε αυτήν την εντολή: `go get -u github.com/kataras/iris` ή αφήστε το αυτόματο updater να το κάνει αυτό για σας.
|
||||
|
||||
# Sa, 24 March 2018 | v10.5.0
|
||||
|
||||
This history entry is not translated yet to the Greek language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#sa-24-march-2018--v1050) instead.
|
||||
|
||||
# We, 14 March 2018 | v10.4.0
|
||||
|
||||
This history entry is not translated yet to the Greek language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#we-14-march-2018--v1040) instead.
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
|
||||
**如何升级**: 打开命令行执行以下命令: `go get -u github.com/kataras/iris` 或者等待自动更新。
|
||||
|
||||
# Sa, 24 March 2018 | v10.5.0
|
||||
|
||||
This history entry is not translated yet to the Chinese language yet, please refer to the english version of the [HISTORY entry](https://github.com/kataras/iris/blob/master/HISTORY.md#sa-24-march-2018--v1050) instead.
|
||||
|
||||
# 2018 3月14日 | v10.4.0 版本更新
|
||||
|
||||
- 修正 `APIBuilder, Party#StaticWeb` 和 `APIBuilder, Party#StaticEmbedded` 子分组内的前缀错误
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<a href="https://iris-go.com"> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> </a>
|
||||
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.4-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.5-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
|
||||
Iris is a fast, simple yet fully featured and very efficient web framework for Go.
|
||||
|
||||
|
@ -106,7 +106,7 @@ _Updated at: [Tuesday, 21 November 2017](_benchmarks/README_UNIX.md)_
|
|||
|
||||
## Support
|
||||
|
||||
- [HISTORY](HISTORY.md#we-14-march-2018--v1040) file is your best friend, it contains information about the latest features and changes
|
||||
- [HISTORY](HISTORY.md#sa-24-march-2018--v1050) file is your best friend, it contains information about the latest features and changes
|
||||
- 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)
|
||||
- Complete our form-based user experience report by clicking [here](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<a href="https://iris-go.com"> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> </a>
|
||||
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.4-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.5-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
|
||||
Το Iris είναι ένα γρήγορο, απλό αλλά και πλήρως λειτουργικό και πολύ αποδοτικό web framework για τη Go.
|
||||
|
||||
|
@ -108,7 +108,7 @@ _Η τελευταία ενημέρωση έγινε την [Τρίτη, 21 Νο
|
|||
|
||||
## Υποστήριξη
|
||||
|
||||
- To [HISTORY](HISTORY_GR.md#we-14-march-2018--v1040) αρχείο είναι ο καλύτερος σας φίλος, περιέχει πληροφορίες σχετικά με τις τελευταίες λειτουργίες(features) και αλλαγές
|
||||
- To [HISTORY](HISTORY_GR.md#sa-24-march-2018--v1050) αρχείο είναι ο καλύτερος σας φίλος, περιέχει πληροφορίες σχετικά με τις τελευταίες λειτουργίες(features) και αλλαγές
|
||||
- Μήπως τυχαίνει να βρήκατε κάποιο bug; Δημοσιεύστε το στα [github issues](https://github.com/kataras/iris/issues)
|
||||
- Έχετε οποιεσδήποτε ερωτήσεις ή πρέπει να μιλήσετε με κάποιον έμπειρο για την επίλυση ενός προβλήματος σε πραγματικό χρόνο; Ελάτε μαζί μας στην [συνομιλία κοινότητας](https://chat.iris-go.com)
|
||||
- Συμπληρώστε την αναφορά εμπειρίας χρήστη κάνοντας κλικ [εδώ](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<a href="https://iris-go.com"> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> </a>
|
||||
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.4-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.5-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
|
||||
Iris - это быстрая, простая, но полнофункциональная и очень эффективная веб-платформа для Go.
|
||||
|
||||
|
@ -106,7 +106,7 @@ _Обновлено: [Вторник, 21 ноября 2017 г.](_benchmarks/READ
|
|||
|
||||
## Поддержка
|
||||
|
||||
- Файл [HISTORY](HISTORY.md#we-14-march-2018--v1040) - ваш лучший друг, он содержит информацию о последних особенностях и всех изменениях
|
||||
- Файл [HISTORY](HISTORY.md#sa-24-march-2018--v1050) - ваш лучший друг, он содержит информацию о последних особенностях и всех изменениях
|
||||
- Вы случайно обнаружили ошибку? Опубликуйте ее на [Github вопросы](https://github.com/kataras/iris/issues)
|
||||
- У Вас есть какие-либо вопросы или Вам нужно поговорить с кем-то, кто бы смог решить Вашу проблему в режиме реального времени? Присоединяйтесь к нам в [чате сообщества](https://chat.iris-go.com)
|
||||
- Заполните наш отчет о пользовательском опыте на основе формы, нажав [здесь](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<a href="https://iris-go.com"> <img align="right" width="169px" src="https://iris-go.com/images/icon.svg?v=a" title="logo created by @merry.dii" /> </a>
|
||||
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.4-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
[![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) [![vscode-iris](https://img.shields.io/badge/ext%20-vscode-0c77e3.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=kataras2006.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://iris-go.com/v10/recipe) [![release](https://img.shields.io/badge/release%20-v10.5-0077b3.svg?style=flat-square)](https://github.com/kataras/iris/releases)
|
||||
|
||||
Iris 是一款超快、简洁高效的 Go 语言 Web开发框架。
|
||||
|
||||
|
@ -102,7 +102,7 @@ _更新于: [2017年11月21日星期二](_benchmarks/README_UNIX.md)_
|
|||
|
||||
## 支持
|
||||
|
||||
- [更新记录](HISTORY_ZH.md#we-14-march-2018--v1040) 是您最好的朋友,它包含有关最新功能和更改的信息
|
||||
- [更新记录](HISTORY_ZH.md#sa-24-march-2018--v1050) 是您最好的朋友,它包含有关最新功能和更改的信息
|
||||
- 你碰巧找到了一个错误? 请提交 [github issues](https://github.com/kataras/iris/issues)
|
||||
- 您是否有任何疑问或需要与有经验的人士交谈以实时解决问题? [加入我们的聊天](https://chat.iris-go.com)
|
||||
- [点击这里完成我们基于表单的用户体验报告](https://docs.google.com/forms/d/e/1FAIpQLSdCxZXPANg_xHWil4kVAdhmh7EBBHQZ_4_xSZVDL-oCC_z5pA/viewform?usp=sf_link)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
10.4.0:https://github.com/kataras/iris/blob/master/HISTORY.md#we-14-march-2018--v1040
|
||||
10.5.0:https://github.com/kataras/iris/blob/master/HISTORY.md#sa-24-march-2018--v1050
|
|
@ -97,6 +97,6 @@ type basicSubController struct {
|
|||
}
|
||||
|
||||
func (c *basicSubController) Get() string {
|
||||
count, _ := c.Session.GetIntDefault("count", 1)
|
||||
count := c.Session.GetIntDefault("count", 1)
|
||||
return fmt.Sprintf("Hello from basicSubController.\nRead-only visits count: %d", count)
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ type UserController struct {
|
|||
const userIDKey = "UserID"
|
||||
|
||||
func (c *UserController) getCurrentUserID() int64 {
|
||||
userID, _ := c.Session.GetInt64Default(userIDKey, 0)
|
||||
userID := c.Session.GetInt64Default(userIDKey, 0)
|
||||
return userID
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ func (r RequestParams) GetIntUnslashed(key string) (int, error) {
|
|||
|
||||
}
|
||||
|
||||
return -1, memstore.ErrIntParse.Format(v)
|
||||
return -1, fmt.Errorf("unable to find int for '%s'", key)
|
||||
}
|
||||
|
||||
// Len returns the full length of the parameters.
|
||||
|
@ -456,39 +456,35 @@ type Context interface {
|
|||
|
||||
// URLParam returns true if the url parameter exists, otherwise false.
|
||||
URLParamExists(name string) bool
|
||||
// URLParamDefault returns the get parameter from a request, if not found then "def" is returned.
|
||||
// URLParamDefault returns the get parameter from a request,
|
||||
// if not found then "def" is returned.
|
||||
URLParamDefault(name string, def string) string
|
||||
// URLParam returns the get parameter from a request , if any.
|
||||
// URLParam returns the get parameter from a request, if any.
|
||||
URLParam(name string) string
|
||||
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request,
|
||||
// returns an error if parse failed.
|
||||
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request.
|
||||
URLParamTrim(name string) string
|
||||
// URLParamTrim returns the escaped url query parameter from a request,
|
||||
// returns an error if parse failed.
|
||||
// URLParamTrim returns the escaped url query parameter from a request.
|
||||
URLParamEscape(name string) string
|
||||
// URLParamIntDefault returns the url query parameter as int value from a request,
|
||||
// if not found then "def" is returned.
|
||||
// Returns an error if parse failed.
|
||||
URLParamIntDefault(name string, def int) (int, error)
|
||||
// URLParamInt returns the url query parameter as int value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns -1 and an error if parse failed.
|
||||
URLParamInt(name string) (int, error)
|
||||
// URLParamInt64Default returns the url query parameter as int64 value from a request,
|
||||
// if not found then "def" is returned.
|
||||
// Returns an error if parse failed.
|
||||
URLParamInt64Default(name string, def int64) (int64, error)
|
||||
// URLParamIntDefault returns the url query parameter as int value from a request,
|
||||
// if not found or parse failed then "def" is returned.
|
||||
URLParamIntDefault(name string, def int) int
|
||||
// URLParamInt64 returns the url query parameter as int64 value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns -1 and an error if parse failed.
|
||||
URLParamInt64(name string) (int64, error)
|
||||
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
|
||||
// if not found then "def" is returned.
|
||||
// Returns an error if parse failed.
|
||||
URLParamFloat64Default(name string, def float64) (float64, error)
|
||||
// URLParamInt64Default returns the url query parameter as int64 value from a request,
|
||||
// if not found or parse failed then "def" is returned.
|
||||
URLParamInt64Default(name string, def int64) int64
|
||||
// URLParamFloat64 returns the url query parameter as float64 value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns -1 and an error if parse failed.
|
||||
URLParamFloat64(name string) (float64, error)
|
||||
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
|
||||
// if not found or parse failed then "def" is returned.
|
||||
URLParamFloat64Default(name string, def float64) float64
|
||||
// URLParamBool returns the url query parameter as boolean value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns an error if parse failed or not found.
|
||||
URLParamBool(name string) (bool, error)
|
||||
// URLParams returns a map of GET query parameters separated by comma if more than one
|
||||
// it returns an empty map if nothing found.
|
||||
|
@ -522,36 +518,36 @@ type Context interface {
|
|||
// PostValueTrim returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", without trailing spaces.
|
||||
PostValueTrim(name string) string
|
||||
// PostValueIntDefault returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int.
|
||||
//
|
||||
// If not found returns the "def".
|
||||
PostValueIntDefault(name string, def int) (int, error)
|
||||
// PostValueInt returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int.
|
||||
//
|
||||
// If not found returns 0.
|
||||
// If not found returns -1 and a non-nil error.
|
||||
PostValueInt(name string) (int, error)
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int64.
|
||||
// PostValueIntDefault returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int.
|
||||
//
|
||||
// If not found returns the "def".
|
||||
PostValueInt64Default(name string, def int64) (int64, error)
|
||||
// If not found returns or parse errors the "def".
|
||||
PostValueIntDefault(name string, def int) int
|
||||
// PostValueInt64 returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as float64.
|
||||
//
|
||||
// If not found returns 0.0.
|
||||
// If not found returns -1 and a no-nil error.
|
||||
PostValueInt64(name string) (int64, error)
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int64.
|
||||
//
|
||||
// If not found or parse errors returns the "def".
|
||||
PostValueInt64Default(name string, def int64) int64
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as float64.
|
||||
//
|
||||
// If not found returns the "def".
|
||||
PostValueFloat64Default(name string, def float64) (float64, error)
|
||||
/// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// If not found returns -1 and a non-nil error.
|
||||
PostValueFloat64(name string) (float64, error)
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as float64.
|
||||
//
|
||||
// If not found returns 0.0.
|
||||
PostValueFloat64(name string) (float64, error)
|
||||
// If not found or parse errors returns the "def".
|
||||
PostValueFloat64Default(name string, def float64) float64
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as bool.
|
||||
//
|
||||
|
@ -1641,79 +1637,103 @@ func (ctx *context) URLParamExists(name string) bool {
|
|||
|
||||
// URLParamDefault returns the get parameter from a request, if not found then "def" is returned.
|
||||
func (ctx *context) URLParamDefault(name string, def string) string {
|
||||
v := ctx.request.URL.Query().Get(name)
|
||||
if v == "" {
|
||||
return def
|
||||
if v := ctx.request.URL.Query().Get(name); v != "" {
|
||||
return v
|
||||
}
|
||||
return v
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// URLParam returns the get parameter from a request , if any.
|
||||
// URLParam returns the get parameter from a request, if any.
|
||||
func (ctx *context) URLParam(name string) string {
|
||||
return ctx.URLParamDefault(name, "")
|
||||
}
|
||||
|
||||
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request,
|
||||
// returns an error if parse failed.
|
||||
// URLParamTrim returns the url query parameter with trailing white spaces removed from a request.
|
||||
func (ctx *context) URLParamTrim(name string) string {
|
||||
return strings.TrimSpace(ctx.URLParam(name))
|
||||
}
|
||||
|
||||
// URLParamTrim returns the escaped url query parameter from a request,
|
||||
// returns an error if parse failed.
|
||||
// URLParamTrim returns the escaped url query parameter from a request.
|
||||
func (ctx *context) URLParamEscape(name string) string {
|
||||
return DecodeQuery(ctx.URLParam(name))
|
||||
}
|
||||
|
||||
// URLParamIntDefault returns the url query parameter as int value from a request,
|
||||
// if not found then "def" is returned.
|
||||
// Returns an error if parse failed.
|
||||
func (ctx *context) URLParamIntDefault(name string, def int) (int, error) {
|
||||
v := ctx.URLParam(name)
|
||||
if v == "" {
|
||||
return def, nil
|
||||
}
|
||||
return strconv.Atoi(v)
|
||||
}
|
||||
var errURLParamNotFound = errors.New("url param '%s' does not exist")
|
||||
|
||||
// URLParamInt returns the url query parameter as int value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns -1 and an error if parse failed or not found.
|
||||
func (ctx *context) URLParamInt(name string) (int, error) {
|
||||
return ctx.URLParamIntDefault(name, 0)
|
||||
if v := ctx.URLParam(name); v != "" {
|
||||
n, err := strconv.Atoi(v)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
return -1, errURLParamNotFound.Format(name)
|
||||
}
|
||||
|
||||
// URLParamInt64Default returns the url query parameter as int64 value from a request,
|
||||
// if not found then "def" is returned.
|
||||
// Returns an error if parse failed.
|
||||
func (ctx *context) URLParamInt64Default(name string, def int64) (int64, error) {
|
||||
v := ctx.URLParam(name)
|
||||
if v == "" {
|
||||
return def, nil
|
||||
// URLParamIntDefault returns the url query parameter as int value from a request,
|
||||
// if not found or parse failed then "def" is returned.
|
||||
func (ctx *context) URLParamIntDefault(name string, def int) int {
|
||||
v, err := ctx.URLParamInt(name)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return strconv.ParseInt(v, 10, 64)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// URLParamInt64 returns the url query parameter as int64 value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns -1 and an error if parse failed or not found.
|
||||
func (ctx *context) URLParamInt64(name string) (int64, error) {
|
||||
return ctx.URLParamInt64Default(name, 0.0)
|
||||
if v := ctx.URLParam(name); v != "" {
|
||||
n, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
return -1, errURLParamNotFound.Format(name)
|
||||
}
|
||||
|
||||
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
|
||||
// if not found then "def" is returned.
|
||||
// Returns an error if parse failed.
|
||||
func (ctx *context) URLParamFloat64Default(name string, def float64) (float64, error) {
|
||||
v := ctx.URLParam(name)
|
||||
if v == "" {
|
||||
return def, nil
|
||||
// URLParamInt64Default returns the url query parameter as int64 value from a request,
|
||||
// if not found or parse failed then "def" is returned.
|
||||
func (ctx *context) URLParamInt64Default(name string, def int64) int64 {
|
||||
v, err := ctx.URLParamInt64(name)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
return strconv.ParseFloat(v, 64)
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// URLParamFloat64 returns the url query parameter as float64 value from a request,
|
||||
// returns an error if parse failed.
|
||||
// returns an error and -1 if parse failed.
|
||||
func (ctx *context) URLParamFloat64(name string) (float64, error) {
|
||||
return ctx.URLParamFloat64Default(name, 0.0)
|
||||
if v := ctx.URLParam(name); v != "" {
|
||||
n, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
return -1, errURLParamNotFound.Format(name)
|
||||
}
|
||||
|
||||
// URLParamFloat64Default returns the url query parameter as float64 value from a request,
|
||||
// if not found or parse failed then "def" is returned.
|
||||
func (ctx *context) URLParamFloat64Default(name string, def float64) float64 {
|
||||
v, err := ctx.URLParamFloat64(name)
|
||||
if err != nil {
|
||||
return def
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// URLParamBool returns the url query parameter as boolean value from a request,
|
||||
|
@ -1836,54 +1856,64 @@ func (ctx *context) PostValueTrim(name string) string {
|
|||
return strings.TrimSpace(ctx.PostValue(name))
|
||||
}
|
||||
|
||||
// PostValueIntDefault returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int.
|
||||
//
|
||||
// If not found returns the "def".
|
||||
func (ctx *context) PostValueIntDefault(name string, def int) (int, error) {
|
||||
v := ctx.PostValue(name)
|
||||
if v == "" {
|
||||
return def, nil
|
||||
}
|
||||
return strconv.Atoi(v)
|
||||
}
|
||||
var errUnableToFindPostValue = errors.New("unable to find post value '%s'")
|
||||
|
||||
// PostValueInt returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int.
|
||||
//
|
||||
// If not found returns 0.
|
||||
// If not found returns -1 and a non-nil error.
|
||||
func (ctx *context) PostValueInt(name string) (int, error) {
|
||||
return ctx.PostValueIntDefault(name, 0)
|
||||
}
|
||||
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int64.
|
||||
//
|
||||
// If not found returns the "def".
|
||||
func (ctx *context) PostValueInt64Default(name string, def int64) (int64, error) {
|
||||
v := ctx.PostValue(name)
|
||||
if v == "" {
|
||||
return def, nil
|
||||
return -1, errUnableToFindPostValue.Format(name)
|
||||
}
|
||||
return strconv.ParseInt(v, 10, 64)
|
||||
return strconv.Atoi(v)
|
||||
}
|
||||
|
||||
// PostValueIntDefault returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int.
|
||||
//
|
||||
// If not found or parse errors returns the "def".
|
||||
func (ctx *context) PostValueIntDefault(name string, def int) int {
|
||||
if v, err := ctx.PostValueInt(name); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// PostValueInt64 returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as float64.
|
||||
//
|
||||
// If not found returns 0.0.
|
||||
// If not found returns -1 and a non-nil error.
|
||||
func (ctx *context) PostValueInt64(name string) (int64, error) {
|
||||
return ctx.PostValueInt64Default(name, 0.0)
|
||||
v := ctx.PostValue(name)
|
||||
if v == "" {
|
||||
return -1, errUnableToFindPostValue.Format(name)
|
||||
}
|
||||
return strconv.ParseInt(v, 10, 64)
|
||||
}
|
||||
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as int64.
|
||||
//
|
||||
// If not found or parse errors returns the "def".
|
||||
func (ctx *context) PostValueInt64Default(name string, def int64) int64 {
|
||||
if v, err := ctx.PostValueInt64(name); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as float64.
|
||||
//
|
||||
// If not found returns the "def".
|
||||
func (ctx *context) PostValueFloat64Default(name string, def float64) (float64, error) {
|
||||
// If not found returns -1 and a non-nil error.
|
||||
func (ctx *context) PostValueFloat64(name string) (float64, error) {
|
||||
v := ctx.PostValue(name)
|
||||
if v == "" {
|
||||
return def, nil
|
||||
return -1, errUnableToFindPostValue.Format(name)
|
||||
}
|
||||
return strconv.ParseFloat(v, 64)
|
||||
}
|
||||
|
@ -1891,9 +1921,13 @@ func (ctx *context) PostValueFloat64Default(name string, def float64) (float64,
|
|||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
// or PUT body parameters based on a "name", as float64.
|
||||
//
|
||||
// If not found returns 0.0.
|
||||
func (ctx *context) PostValueFloat64(name string) (float64, error) {
|
||||
return ctx.PostValueFloat64Default(name, 0.0)
|
||||
// If not found or parse errors returns the "def".
|
||||
func (ctx *context) PostValueFloat64Default(name string, def float64) float64 {
|
||||
if v, err := ctx.PostValueFloat64(name); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// PostValueInt64Default returns the parsed form data from POST, PATCH,
|
||||
|
@ -1901,7 +1935,12 @@ func (ctx *context) PostValueFloat64(name string) (float64, error) {
|
|||
//
|
||||
// If not found or value is false, then it returns false, otherwise true.
|
||||
func (ctx *context) PostValueBool(name string) (bool, error) {
|
||||
return strconv.ParseBool(ctx.PostValue(name))
|
||||
v := ctx.PostValue(name)
|
||||
if v == "" {
|
||||
return false, errUnableToFindPostValue.Format(name)
|
||||
}
|
||||
|
||||
return strconv.ParseBool(v)
|
||||
}
|
||||
|
||||
// PostValues returns all the parsed form data from POST, PATCH,
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
const (
|
||||
// Version is the string representation of the current local Iris Web Framework version.
|
||||
Version = "10.4.0"
|
||||
Version = "10.5.0"
|
||||
)
|
||||
|
||||
// CheckForUpdates checks for any available updates
|
||||
|
|
|
@ -85,65 +85,116 @@ func (e Entry) StringTrim() string {
|
|||
return strings.TrimSpace(e.String())
|
||||
}
|
||||
|
||||
// ErrIntParse returns an error message when int parse failed
|
||||
// it's not statical error, it depends on the failed value.
|
||||
var ErrIntParse = errors.New("unable to find or parse the integer, found: %#v")
|
||||
var errFindParse = errors.New("unable to find the %s with key: %s")
|
||||
|
||||
// IntDefault returns the entry's value as int.
|
||||
// If not found returns "def".
|
||||
// If not found returns "def" and a non-nil error.
|
||||
func (e Entry) IntDefault(def int) (int, error) {
|
||||
v := e.ValueRaw
|
||||
if v == nil {
|
||||
return def, nil
|
||||
return def, errFindParse.Format("int", e.Key)
|
||||
}
|
||||
if vint, ok := v.(int); ok {
|
||||
return vint, nil
|
||||
} else if vstring, sok := v.(string); sok {
|
||||
if vstring == "" {
|
||||
return def, nil
|
||||
} else if vstring, sok := v.(string); sok && vstring != "" {
|
||||
vint, err := strconv.Atoi(vstring)
|
||||
if err != nil {
|
||||
return def, err
|
||||
}
|
||||
return strconv.Atoi(vstring)
|
||||
|
||||
return vint, nil
|
||||
}
|
||||
|
||||
return def, nil
|
||||
return def, errFindParse.Format("int", e.Key)
|
||||
}
|
||||
|
||||
// Int64Default returns the entry's value as int64.
|
||||
// If not found returns "def".
|
||||
// If not found returns "def" and a non-nil error.
|
||||
func (e Entry) Int64Default(def int64) (int64, error) {
|
||||
v := e.ValueRaw
|
||||
if v == nil {
|
||||
return def, nil
|
||||
return def, errFindParse.Format("int64", e.Key)
|
||||
}
|
||||
|
||||
if vint64, ok := v.(int64); ok {
|
||||
return vint64, nil
|
||||
} else if vstring, sok := v.(string); sok {
|
||||
if vstring == "" {
|
||||
return def, nil
|
||||
}
|
||||
}
|
||||
|
||||
if vint, ok := v.(int); ok {
|
||||
return int64(vint), nil
|
||||
}
|
||||
|
||||
if vstring, sok := v.(string); sok {
|
||||
return strconv.ParseInt(vstring, 10, 64)
|
||||
}
|
||||
|
||||
return def, nil
|
||||
return def, errFindParse.Format("int64", e.Key)
|
||||
}
|
||||
|
||||
// Float64Default returns the entry's value as float64.
|
||||
// If not found returns "def".
|
||||
// If not found returns "def" and a non-nil error.
|
||||
func (e Entry) Float64Default(def float64) (float64, error) {
|
||||
v := e.ValueRaw
|
||||
|
||||
if v == nil {
|
||||
return def, nil
|
||||
}
|
||||
if vfloat64, ok := v.(float64); ok {
|
||||
return vfloat64, nil
|
||||
} else if vstring, sok := v.(string); sok {
|
||||
if vstring == "" {
|
||||
return def, nil
|
||||
}
|
||||
return strconv.ParseFloat(vstring, 64)
|
||||
return def, errFindParse.Format("float64", e.Key)
|
||||
}
|
||||
|
||||
return def, nil
|
||||
if vfloat32, ok := v.(float32); ok {
|
||||
return float64(vfloat32), nil
|
||||
}
|
||||
|
||||
if vfloat64, ok := v.(float64); ok {
|
||||
return vfloat64, nil
|
||||
}
|
||||
|
||||
if vint, ok := v.(int); ok {
|
||||
return float64(vint), nil
|
||||
}
|
||||
|
||||
if vstring, sok := v.(string); sok {
|
||||
vfloat64, err := strconv.ParseFloat(vstring, 64)
|
||||
if err != nil {
|
||||
return def, err
|
||||
}
|
||||
|
||||
return vfloat64, nil
|
||||
}
|
||||
|
||||
return def, errFindParse.Format("float64", e.Key)
|
||||
}
|
||||
|
||||
// Float32Default returns the entry's value as float32.
|
||||
// If not found returns "def" and a non-nil error.
|
||||
func (e Entry) Float32Default(key string, def float32) (float32, error) {
|
||||
v := e.ValueRaw
|
||||
|
||||
if v == nil {
|
||||
return def, errFindParse.Format("float32", e.Key)
|
||||
}
|
||||
|
||||
if vfloat32, ok := v.(float32); ok {
|
||||
return vfloat32, nil
|
||||
}
|
||||
|
||||
if vfloat64, ok := v.(float64); ok {
|
||||
return float32(vfloat64), nil
|
||||
}
|
||||
|
||||
if vint, ok := v.(int); ok {
|
||||
return float32(vint), nil
|
||||
}
|
||||
|
||||
if vstring, sok := v.(string); sok {
|
||||
vfloat32, err := strconv.ParseFloat(vstring, 32)
|
||||
if err != nil {
|
||||
return def, err
|
||||
}
|
||||
|
||||
return float32(vfloat32), nil
|
||||
}
|
||||
|
||||
return def, errFindParse.Format("float32", e.Key)
|
||||
}
|
||||
|
||||
// BoolDefault returns the user's value as bool.
|
||||
|
@ -151,11 +202,11 @@ func (e Entry) Float64Default(def float64) (float64, error) {
|
|||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
// Any other value returns an error.
|
||||
//
|
||||
// If not found returns "def".
|
||||
// If not found returns "def" and a non-nil error.
|
||||
func (e Entry) BoolDefault(def bool) (bool, error) {
|
||||
v := e.ValueRaw
|
||||
if v == nil {
|
||||
return def, nil
|
||||
return def, errFindParse.Format("bool", e.Key)
|
||||
}
|
||||
|
||||
if vBoolean, ok := v.(bool); ok {
|
||||
|
@ -163,7 +214,11 @@ func (e Entry) BoolDefault(def bool) (bool, error) {
|
|||
}
|
||||
|
||||
if vString, ok := v.(string); ok {
|
||||
return strconv.ParseBool(vString)
|
||||
b, err := strconv.ParseBool(vString)
|
||||
if err != nil {
|
||||
return def, err
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
if vInt, ok := v.(int); ok {
|
||||
|
@ -173,7 +228,7 @@ func (e Entry) BoolDefault(def bool) (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
return def, nil
|
||||
return def, errFindParse.Format("bool", e.Key)
|
||||
}
|
||||
|
||||
// Value returns the value of the entry,
|
||||
|
@ -347,66 +402,64 @@ func (r *Store) GetStringTrim(name string) string {
|
|||
return strings.TrimSpace(r.GetString(name))
|
||||
}
|
||||
|
||||
// GetIntDefault returns the entry's value as int, based on its key.
|
||||
// If not found returns "def".
|
||||
func (r *Store) GetIntDefault(key string, def int) (int, error) {
|
||||
// GetInt returns the entry's value as int, based on its key.
|
||||
// If not found returns -1 and a non-nil error.
|
||||
func (r *Store) GetInt(key string) (int, error) {
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return def, nil
|
||||
return 0, errFindParse.Format("int", key)
|
||||
}
|
||||
return v.IntDefault(def)
|
||||
return v.IntDefault(-1)
|
||||
}
|
||||
|
||||
// GetInt returns the entry's value as int, based on its key.
|
||||
// If not found returns 0.
|
||||
func (r *Store) GetInt(key string) (int, error) {
|
||||
return r.GetIntDefault(key, 0)
|
||||
// GetIntDefault returns the entry's value as int, based on its key.
|
||||
// If not found returns "def".
|
||||
func (r *Store) GetIntDefault(key string, def int) int {
|
||||
if v, err := r.GetInt(key); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// GetInt64 returns the entry's value as int64, based on its key.
|
||||
// If not found returns -1 and a non-nil error.
|
||||
func (r *Store) GetInt64(key string) (int64, error) {
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return -1, errFindParse.Format("int64", key)
|
||||
}
|
||||
return v.Int64Default(-1)
|
||||
}
|
||||
|
||||
// GetInt64Default returns the entry's value as int64, based on its key.
|
||||
// If not found returns "def".
|
||||
func (r *Store) GetInt64Default(key string, def int64) (int64, error) {
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return def, nil
|
||||
func (r *Store) GetInt64Default(key string, def int64) int64 {
|
||||
if v, err := r.GetInt64(key); err == nil {
|
||||
return v
|
||||
}
|
||||
return v.Int64Default(def)
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// GetInt64 returns the entry's value as int64, based on its key.
|
||||
// If not found returns 0.0.
|
||||
func (r *Store) GetInt64(key string) (int64, error) {
|
||||
return r.GetInt64Default(key, 0.0)
|
||||
// GetFloat64 returns the entry's value as float64, based on its key.
|
||||
// If not found returns -1 and a non nil error.
|
||||
func (r *Store) GetFloat64(key string) (float64, error) {
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return -1, errFindParse.Format("float64", key)
|
||||
}
|
||||
return v.Float64Default(-1)
|
||||
}
|
||||
|
||||
// GetFloat64Default returns the entry's value as float64, based on its key.
|
||||
// If not found returns "def".
|
||||
func (r *Store) GetFloat64Default(key string, def float64) (float64, error) {
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return def, nil
|
||||
func (r *Store) GetFloat64Default(key string, def float64) float64 {
|
||||
if v, err := r.GetFloat64(key); err == nil {
|
||||
return v
|
||||
}
|
||||
return v.Float64Default(def)
|
||||
}
|
||||
|
||||
// GetFloat64 returns the entry's value as float64, based on its key.
|
||||
// If not found returns 0.0.
|
||||
func (r *Store) GetFloat64(key string) (float64, error) {
|
||||
return r.GetFloat64Default(key, 0.0)
|
||||
}
|
||||
|
||||
// GetBoolDefault returns the user's value as bool, based on its key.
|
||||
// a string which is "1" or "t" or "T" or "TRUE" or "true" or "True"
|
||||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
// Any other value returns an error.
|
||||
//
|
||||
// If not found returns "def".
|
||||
func (r *Store) GetBoolDefault(key string, def bool) (bool, error) {
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return def, nil
|
||||
}
|
||||
return v.BoolDefault(def)
|
||||
return def
|
||||
}
|
||||
|
||||
// GetBool returns the user's value as bool, based on its key.
|
||||
|
@ -414,9 +467,27 @@ func (r *Store) GetBoolDefault(key string, def bool) (bool, error) {
|
|||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
// Any other value returns an error.
|
||||
//
|
||||
// If not found returns false.
|
||||
// If not found returns false and a non-nil error.
|
||||
func (r *Store) GetBool(key string) (bool, error) {
|
||||
return r.GetBoolDefault(key, false)
|
||||
v := r.GetEntry(key)
|
||||
if v == nil {
|
||||
return false, errFindParse.Format("bool", key)
|
||||
}
|
||||
|
||||
return v.BoolDefault(false)
|
||||
}
|
||||
|
||||
// GetBoolDefault returns the user's value as bool, based on its key.
|
||||
// a string which is "1" or "t" or "T" or "TRUE" or "true" or "True"
|
||||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
//
|
||||
// If not found returns "def".
|
||||
func (r *Store) GetBoolDefault(key string, def bool) bool {
|
||||
if v, err := r.GetBool(key); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
// Remove deletes an entry linked to that "key",
|
||||
|
|
2
doc.go
2
doc.go
|
@ -35,7 +35,7 @@ Source code and other details for the project are available at GitHub:
|
|||
|
||||
Current Version
|
||||
|
||||
10.4.0
|
||||
10.5.0
|
||||
|
||||
Installation
|
||||
|
||||
|
|
|
@ -122,12 +122,6 @@ func (s *Session) peekFlashMessage(key string) (*flashMessage, bool) {
|
|||
// GetString same as Get but returns its string representation,
|
||||
// if key doesn't exist then it returns an empty string.
|
||||
func (s *Session) GetString(key string) string {
|
||||
return s.GetStringDefault(key, "")
|
||||
}
|
||||
|
||||
// GetStringDefault same as Get but returns its string representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetStringDefault(key string, defaultValue string) string {
|
||||
if value := s.Get(key); value != nil {
|
||||
if v, ok := value.(string); ok {
|
||||
return v
|
||||
|
@ -142,6 +136,16 @@ func (s *Session) GetStringDefault(key string, defaultValue string) string {
|
|||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetStringDefault same as Get but returns its string representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetStringDefault(key string, defaultValue string) string {
|
||||
if v := s.GetString(key); v != "" {
|
||||
return v
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
|
@ -166,14 +170,8 @@ func (s *Session) GetFlashStringDefault(key string, defaultValue string) string
|
|||
var errFindParse = errors.New("Unable to find the %s with key: %s. Found? %#v")
|
||||
|
||||
// GetInt same as `Get` but returns its int representation,
|
||||
// if key doesn't exist then it returns -1.
|
||||
// if key doesn't exist then it returns -1 and a non-nil error.
|
||||
func (s *Session) GetInt(key string) (int, error) {
|
||||
return s.GetIntDefault(key, -1)
|
||||
}
|
||||
|
||||
// GetIntDefault same as `Get` but returns its int representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetIntDefault(key string, defaultValue int) (int, error) {
|
||||
v := s.Get(key)
|
||||
|
||||
if vint, ok := v.(int); ok {
|
||||
|
@ -184,14 +182,23 @@ func (s *Session) GetIntDefault(key string, defaultValue int) (int, error) {
|
|||
return strconv.Atoi(vstring)
|
||||
}
|
||||
|
||||
return defaultValue, errFindParse.Format("int", key, v)
|
||||
return -1, errFindParse.Format("int", key, v)
|
||||
}
|
||||
|
||||
// GetIntDefault same as `Get` but returns its int representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetIntDefault(key string, defaultValue int) int {
|
||||
if v, err := s.GetInt(key); err == nil {
|
||||
return v
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// Increment increments the stored int value saved as "key" by +"n".
|
||||
// If value doesn't exist on that "key" then it creates one with the "n" as its value.
|
||||
// It returns the new, incremented, value.
|
||||
func (s *Session) Increment(key string, n int) (newValue int) {
|
||||
newValue, _ = s.GetIntDefault(key, 0)
|
||||
newValue = s.GetIntDefault(key, 0)
|
||||
newValue += n
|
||||
s.Set(key, newValue)
|
||||
return
|
||||
|
@ -201,21 +208,15 @@ func (s *Session) Increment(key string, n int) (newValue int) {
|
|||
// If value doesn't exist on that "key" then it creates one with the "n" as its value.
|
||||
// It returns the new, decremented, value even if it's less than zero.
|
||||
func (s *Session) Decrement(key string, n int) (newValue int) {
|
||||
newValue, _ = s.GetIntDefault(key, 0)
|
||||
newValue = s.GetIntDefault(key, 0)
|
||||
newValue -= n
|
||||
s.Set(key, newValue)
|
||||
return
|
||||
}
|
||||
|
||||
// GetInt64 same as `Get` but returns its int64 representation,
|
||||
// if key doesn't exist then it returns -1.
|
||||
// if key doesn't exist then it returns -1 and a non-nil error.
|
||||
func (s *Session) GetInt64(key string) (int64, error) {
|
||||
return s.GetInt64Default(key, -1)
|
||||
}
|
||||
|
||||
// GetInt64Default same as `Get` but returns its int64 representation,
|
||||
// if key doesn't exist it returns the "defaultValue".
|
||||
func (s *Session) GetInt64Default(key string, defaultValue int64) (int64, error) {
|
||||
v := s.Get(key)
|
||||
|
||||
if vint64, ok := v.(int64); ok {
|
||||
|
@ -230,18 +231,22 @@ func (s *Session) GetInt64Default(key string, defaultValue int64) (int64, error)
|
|||
return strconv.ParseInt(vstring, 10, 64)
|
||||
}
|
||||
|
||||
return defaultValue, errFindParse.Format("int64", key, v)
|
||||
return -1, errFindParse.Format("int64", key, v)
|
||||
}
|
||||
|
||||
// GetInt64Default same as `Get` but returns its int64 representation,
|
||||
// if key doesn't exist it returns the "defaultValue".
|
||||
func (s *Session) GetInt64Default(key string, defaultValue int64) int64 {
|
||||
if v, err := s.GetInt64(key); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// GetFloat32 same as `Get` but returns its float32 representation,
|
||||
// if key doesn't exist then it returns -1.
|
||||
// if key doesn't exist then it returns -1 and a non-nil error.
|
||||
func (s *Session) GetFloat32(key string) (float32, error) {
|
||||
return s.GetFloat32Default(key, -1)
|
||||
}
|
||||
|
||||
// GetFloat32Default same as `Get` but returns its float32 representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetFloat32Default(key string, defaultValue float32) (float32, error) {
|
||||
v := s.Get(key)
|
||||
|
||||
if vfloat32, ok := v.(float32); ok {
|
||||
|
@ -264,18 +269,22 @@ func (s *Session) GetFloat32Default(key string, defaultValue float32) (float32,
|
|||
return float32(vfloat64), nil
|
||||
}
|
||||
|
||||
return defaultValue, errFindParse.Format("float32", key, v)
|
||||
return -1, errFindParse.Format("float32", key, v)
|
||||
}
|
||||
|
||||
// GetFloat32Default same as `Get` but returns its float32 representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetFloat32Default(key string, defaultValue float32) float32 {
|
||||
if v, err := s.GetFloat32(key); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// GetFloat64 same as `Get` but returns its float64 representation,
|
||||
// if key doesn't exist then it returns -1.
|
||||
// if key doesn't exist then it returns -1 and a non-nil error.
|
||||
func (s *Session) GetFloat64(key string) (float64, error) {
|
||||
return s.GetFloat64Default(key, -1)
|
||||
}
|
||||
|
||||
// GetFloat64Default same as `Get` but returns its float64 representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetFloat64Default(key string, defaultValue float64) (float64, error) {
|
||||
v := s.Get(key)
|
||||
|
||||
if vfloat32, ok := v.(float32); ok {
|
||||
|
@ -294,27 +303,65 @@ func (s *Session) GetFloat64Default(key string, defaultValue float64) (float64,
|
|||
return strconv.ParseFloat(vstring, 32)
|
||||
}
|
||||
|
||||
return defaultValue, errFindParse.Format("float64", key, v)
|
||||
return -1, errFindParse.Format("float64", key, v)
|
||||
}
|
||||
|
||||
// GetFloat64Default same as `Get` but returns its float64 representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetFloat64Default(key string, defaultValue float64) float64 {
|
||||
if v, err := s.GetFloat64(key); err == nil {
|
||||
return v
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// GetBoolean same as `Get` but returns its boolean representation,
|
||||
// if key doesn't exist then it returns false.
|
||||
// if key doesn't exist then it returns false and a non-nil error.
|
||||
func (s *Session) GetBoolean(key string) (bool, error) {
|
||||
return s.GetBooleanDefault(key, false)
|
||||
}
|
||||
|
||||
// GetBooleanDefault same as `Get` but returns its boolean representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetBooleanDefault(key string, defaultValue bool) (bool, error) {
|
||||
v := s.Get(key)
|
||||
if v == nil {
|
||||
return false, errFindParse.Format("bool", key, "nil")
|
||||
}
|
||||
|
||||
// here we could check for "true", "false" and 0 for false and 1 for true
|
||||
// but this may cause unexpected behavior from the developer if they expecting an error
|
||||
// so we just check if bool, if yes then return that bool, otherwise return false and an error.
|
||||
if vb, ok := v.(bool); ok {
|
||||
return vb, nil
|
||||
}
|
||||
if vstring, ok := v.(string); ok {
|
||||
return strconv.ParseBool(vstring)
|
||||
}
|
||||
|
||||
return defaultValue, errFindParse.Format("bool", key, v)
|
||||
return false, errFindParse.Format("bool", key, v)
|
||||
}
|
||||
|
||||
// GetBooleanDefault same as `Get` but returns its boolean representation,
|
||||
// if key doesn't exist then it returns the "defaultValue".
|
||||
func (s *Session) GetBooleanDefault(key string, defaultValue bool) bool {
|
||||
/*
|
||||
Note that here we can't do more than duplicate the GetBoolean's code, because of the "false".
|
||||
*/
|
||||
v := s.Get(key)
|
||||
if v == nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// here we could check for "true", "false" and 0 for false and 1 for true
|
||||
// but this may cause unexpected behavior from the developer if they expecting an error
|
||||
// so we just check if bool, if yes then return that bool, otherwise return false and an error.
|
||||
if vb, ok := v.(bool); ok {
|
||||
return vb
|
||||
}
|
||||
|
||||
if vstring, ok := v.(string); ok {
|
||||
if b, err := strconv.ParseBool(vstring); err == nil {
|
||||
return b
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// GetAll returns a copy of all session's values.
|
||||
|
|
Loading…
Reference in New Issue
Block a user