This repository was archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmanage.go
More file actions
76 lines (64 loc) · 1.3 KB
/
Copy pathmanage.go
File metadata and controls
76 lines (64 loc) · 1.3 KB
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
package main
import (
"fmt"
"log"
"os"
"gopkg.in/urfave/cli.v1"
"github.com/dominik-zeglen/inkster/api/schema"
server "github.com/dominik-zeglen/inkster/app"
"github.com/dominik-zeglen/inkster/core"
)
func main() {
app := cli.NewApp()
app.Action = func(c *cli.Context) error {
if c.NArg() > 0 {
operation := c.Args().Get(0)
if operation == "runserver" {
server := server.Server{}
server.Init(".")
server.Run()
return nil
}
if operation == "add-user" {
server := server.Server{}
server.Init(".")
dataSource := server.DataSource
email := c.Args().Get(1)
password := c.Args().Get(2)
newUser := core.User{
Email: email,
Active: true,
}
newUser.CreatedAt = server.
DataSource.
GetCurrentTime()
newUser.UpdatedAt = server.
DataSource.
GetCurrentTime()
err := newUser.CreatePassword(password)
if err != nil {
return err
}
_, err = dataSource.
DB().
Model(&newUser).
Insert()
if err != nil {
return err
}
fmt.Println("Added user " + email)
return nil
}
if operation == "print-schema" {
fmt.Println(schema.String())
return nil
}
}
fmt.Println("No operation given")
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}