## Basic Auth (基本認證) 中間件
Basic Auth 中間件提供了 HTTP 的基本認證方式。
- 對于有效的請求,則繼續調用下一個處理程序 (handler) 。
- 對于丟失或無效的請求,則返回 "401 - Unauthorized" 響應。
*用法*
```go
e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
if username == "joe" && password == "secret" {
return true, nil
}
return false, nil
}))
```
### 自定義配置
*用法*
```go
e.Use(middleware.BasicAuthWithConfig(middleware.BasicAuthConfig{}))
```
### 配置
```go
BasicAuthConfig struct {
// Skipper 定義了一個跳過中間件的函數
Skipper Skipper
// Validator 是一個用來驗證 BasicAuth 是否合法的函數
// Validator 是必須的.
Validator BasicAuthValidator
// Realm 是一個用來定義 BasicAuth 的 Realm 屬性的字符串
// 默認值是 "Restricted"
Realm string
}
```
*默認配置*
```go
DefaultBasicAuthConfig = BasicAuthConfig{
Skipper: defaultSkipper,
}
```