snap/auth/auth.go

35 lines
672 B
Go
Raw Normal View History

2018-01-24 02:26:26 +00:00
package auth
2018-02-07 22:25:00 +00:00
import (
"net/http"
)
2018-01-24 02:26:26 +00:00
type AuthData struct {
User string
Group string
}
2018-01-24 02:26:26 +00:00
type AuthManager interface {
AddUser(user string, group string, password string) error
DeleteUser(user string) error
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
2018-01-24 02:26:26 +00:00
}
2021-01-19 03:02:59 +00:00
type Authenticator interface {
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
}
//----------------------------------------------------------------------------------------------------------------------
func NewAuth(kind string) AuthManager {
switch kind {
case "basic":
return NewBasicAuth()
case "token":
return NewTokenAuth()
default:
return NewNoAuth()
}
2021-01-19 03:23:52 +00:00
}