-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (64 loc) · 1.27 KB
/
main.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
package main
import (
"Bank/db"
"Bank/models"
"Bank/pkg/core/services"
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
"log"
"os"
)
func main() {
database, err := sql.Open("sqlite3", "test")
if err != nil {
log.Fatal("error1", err)
} else {
fmt.Println("CONNECTION TO DB IS SUCCESS")
}
db.DBInit(database)
Start(database)
}
const AuthorizationOperation = `1.Authorization
0.Exit`
func Start(database *sql.DB) {
intro(database)
}
func intro(database *sql.DB) {
for {
fmt.Println(AuthorizationOperation)
fmt.Println(`select a command:`)
var cmd int64
_, err := fmt.Scan(&cmd)
if err != nil {
log.Println(`error on line 35 main.go`)
}
var User models.User
switch cmd {
case 1:
ok, id, isAdmin := services.Login(database)
row := database.QueryRow(`select id, isAdmin from users where id = ($1) and isAdmin = ($2) `, id, isAdmin)
_ = row.Scan(
&User.ID,
&User.IsAdmin,
)
if ok {
if User.IsAdmin {
fmt.Println(`You are admin.`)
services.Authorization(database, id)
}
if !User.IsAdmin {
fmt.Println(`You are user`)
services.UserAuthorization(database, id)
}
fmt.Println(ok)
} else {
fmt.Println(`not ok`)
}
case 0:
os.Exit(0)
default:
fmt.Println(`repeat again`)
}
}
}