vicanso / elton-basic-auth

Basic auth middleware for elton.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

elton-basic-auth

The middleware has been archived, please use the middleware of elton.

Build Status

Basic auth middleware for elton.

package main

import (
	"bytes"

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

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

	e.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
		},
	}))

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

	e.ListenAndServe(":3000")
}

About

Basic auth middleware for elton.

License:Apache License 2.0


Languages

Language:Go 96.7%Language:Makefile 3.3%