Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

vicanso/elton-basic-auth

Repository files navigation

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")
}