-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
86 lines (70 loc) · 1.79 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package goadmin
import (
"context"
"database/sql"
"github.com/golang-migrate/migrate/database"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"net/url"
)
var (
DashboardURL = "/"
LoginURL = "/login"
LogoutURL = "/logout"
AccessCookieName = "auth_token"
ErrContextNotConfigured = errors.New("admin context not configured")
)
type DBConfig struct {
DB *sql.DB
DBInstance database.Driver
DriverName string
DatabaseName string
MigrationsPath string
}
type Config struct {
Host string
Port uint16
Middleware []echo.MiddlewareFunc
BaseURL string
ViewsPath string
DevMode bool
AssetsPath string
DBConfig DBConfig
baseURL *url.URL
}
func (config *Config) Validate() error {
if config.DBConfig.DB == nil {
return errors.New("required DB")
}
uri, err := url.Parse(config.BaseURL)
if err != nil {
return errors.Wrap(err, "parse base url failed")
}
config.baseURL = uri
if config.Port == 0 {
return errors.New("invalid port")
}
return nil
}
type UserUseCase interface {
SearchByLogin(ctx context.Context, login string) (*User, error)
ComparePassword(user *User, password string) (bool, error)
CreateAuthToken(ctx context.Context, user *User) (*Token, error)
SetLastLogged(ctx context.Context, user *User) error
SearchToken(ctx context.Context, token string) (*Token, error)
}
type UserFilter struct {
Name string
Login string
Status UserStatus
Limit, Offset int
}
type UserRepository interface {
Search(ctx context.Context, filter *UserFilter) ([]*User, error)
Create(ctx context.Context, user User) (*User, error)
Update(ctx context.Context, user User) (*User, error)
Delete(ctx context.Context, user User) error
}
type TokenRepository interface {
Search(ctx context.Context) error
}