1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-06 03:27:27 +00:00

Publish the new version ✈️ | Look description please!

# FAQ

### Looking for free support?

	http://support.iris-go.com
    https://kataras.rocket.chat/channel/iris

### Looking for previous versions?

    https://github.com/kataras/iris#version

### Should I upgrade my Iris?

Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.

**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).

### About our new home page
    http://iris-go.com

Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!

[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.

The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!

Read more at https://github.com/kataras/iris/blob/master/HISTORY.md


Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
This commit is contained in:
kataras
2017-06-03 23:22:52 +03:00
parent 03bcadadec
commit 5e4b63acb2
330 changed files with 35786 additions and 17316 deletions

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2016-2017 Gerasimos Maropoulos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,3 +1,8 @@
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package basicauth provides http basic authentication via middleware. See _examples/beginner/basicauth
package basicauth
import (
@@ -5,22 +10,10 @@ import (
"strconv"
"time"
"gopkg.in/kataras/iris.v6"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
// +------------------------------------------------------------+
// | Middleware usage |
// +------------------------------------------------------------+
//
// import "gopkg.in/kataras/iris.v6/middleware/basicauth"
//
// app := iris.New()
// authentication := basicauth.Default(map[string]string{"myusername": "mypassword", "mySecondusername": "mySecondpassword"})
// app.Get("/dashboard", authentication, func(ctx *iris.Context){})
//
// for more configuration basicauth.New(basicauth.Config{...})
// see _example
type (
encodedUser struct {
HeaderValue string
@@ -41,29 +34,31 @@ type (
//
// New takes one parameter, the Config returns a HandlerFunc
// use: iris.UseFunc(New(...)), iris.Get(...,New(...),...)
func New(c Config) iris.HandlerFunc {
b := &basicAuthMiddleware{config: DefaultConfig().MergeSingle(c)}
// New takes one parameter, the Config returns a Handler
// use: iris.Use(New(...)), iris.Get(...,New(...),...)
func New(c Config) context.Handler {
config := DefaultConfig()
if c.ContextKey != "" {
config.ContextKey = c.ContextKey
}
if c.Realm != "" {
config.Realm = c.Realm
}
config.Users = c.Users
b := &basicAuthMiddleware{config: config}
b.init()
return b.Serve
}
// Default takes one parameter, the users returns a HandlerFunc
// use: iris.UseFunc(Default(...)), iris.Get(...,Default(...),...)
func Default(users map[string]string) iris.HandlerFunc {
// Default takes one parameter, the users returns a Handler
// use: iris.Use(Default(...)), iris.Get(...,Default(...),...)
func Default(users map[string]string) context.Handler {
c := DefaultConfig()
c.Users = users
return New(c)
}
//
// User returns the user from context key same as 'ctx.GetString("user")' but cannot be used by the developer, use the basicauth.Config.User func instead.
func (b *basicAuthMiddleware) User(ctx *iris.Context) string {
return b.config.User(ctx)
}
func (b *basicAuthMiddleware) init() {
// pass the encoded users from the user's config's Users value
b.auth = make(encodedUsers, 0, len(b.config.Users))
@@ -98,20 +93,20 @@ func (b *basicAuthMiddleware) findAuth(headerValue string) (auth *encodedUser, f
return
}
func (b *basicAuthMiddleware) askForCredentials(ctx *iris.Context) {
ctx.SetHeader("WWW-Authenticate", b.realmHeaderValue)
ctx.SetStatusCode(iris.StatusUnauthorized)
func (b *basicAuthMiddleware) askForCredentials(ctx context.Context) {
ctx.Header("WWW-Authenticate", b.realmHeaderValue)
ctx.StatusCode(iris.StatusUnauthorized)
}
// Serve the actual middleware
func (b *basicAuthMiddleware) Serve(ctx *iris.Context) {
func (b *basicAuthMiddleware) Serve(ctx context.Context) {
if auth, found := b.findAuth(ctx.RequestHeader("Authorization")); !found {
if auth, found := b.findAuth(ctx.GetHeader("Authorization")); !found {
b.askForCredentials(ctx)
// don't continue to the next handler
} else {
// all ok set the context's value in order to be getable from the next handler
ctx.Set(b.config.ContextKey, auth.Username)
ctx.Values().Set(b.config.ContextKey, auth.Username)
if b.expireEnabled {
if auth.logged == false {

View File

@@ -1,10 +1,13 @@
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package basicauth
import (
"time"
"github.com/imdario/mergo"
"gopkg.in/kataras/iris.v6"
"github.com/kataras/iris/context"
)
const (
@@ -35,14 +38,7 @@ func DefaultConfig() Config {
return Config{make(map[string]string), DefaultBasicAuthRealm, DefaultBasicAuthContextKey, 0}
}
// MergeSingle merges the default with the given config and returns the result
func (c Config) MergeSingle(cfg Config) (config Config) {
config = cfg
mergo.Merge(&config, c)
return
}
// User returns the user from context key same as 'ctx.GetString("user")' but cannot be used by the developer, this is only here in order to understand how you can get the authenticated username
func (c Config) User(ctx *iris.Context) string {
return ctx.GetString(c.ContextKey)
func (c Config) User(ctx context.Context) string {
return ctx.Values().GetString(c.ContextKey)
}