basicauth

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2019 License: MIT Imports: 4 Imported by: 0

README

elton-basic-auth

Build Status

Basic auth middleware for elton.

package main

import (
	"bytes"
	"fmt"

	"github.com/vicanso/elton"
	basicauth "github.com/vicanso/elton-basic-auth"
	"github.com/vicanso/hes"
)

func main() {
	d := elton.New()

	d.Use(basicauth.New(basicauth.Config{
		Validate: func(account, pwd string, c *elton.Context) (bool, error) {
			if account == "tree.xie" && pwd == "password" {
				return true, nil
			}
			if account == "n" {
				return false, hes.New("account is invalid")
			}
			return false, nil
		},
	}))

	d.GET("/", func(c *elton.Context) (err error) {
		c.BodyBuffer = bytes.NewBufferString("hello world")
		return
	})

	d.ListenAndServe(":7001")
}

Documentation

Index

Constants

View Source
const (

	// ErrCategory basic auth error category
	ErrCategory = "elton-basic-auth"
)

Variables

This section is empty.

Functions

func New

func New(config Config) elton.Handler

New new basic auth

Types

type Config

type Config struct {
	Realm    string
	Validate Validate
	Skipper  elton.Skipper
}

Config basic auth config

type Validate

type Validate func(username string, password string, c *elton.Context) (bool, error)

Validate validate function

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL