auth.go 591 B

12345678910111213141516171819202122232425262728293031323334
  1. package auth
  2. import (
  3. "net/http"
  4. )
  5. type AuthData struct {
  6. User string
  7. Group string
  8. Properties map[string]string
  9. }
  10. type AuthManager interface {
  11. AddUser(user string, group string, password string) error
  12. DeleteUser(user string) error
  13. DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
  14. }
  15. type Authenticator interface {
  16. DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, bool)
  17. }
  18. func NewAuth(kind string) AuthManager {
  19. switch kind {
  20. case "basic":
  21. return NewBasicAuth()
  22. case "token":
  23. return NewTokenAuth()
  24. default:
  25. return NewNoAuth()
  26. }
  27. }