Loading ask/ask.go +9 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,15 @@ func GetLine(prompt string) (string, error) { return line, err } // GetInt64 gets a line. func GetInt64(prompt string) (int64, error) { line, err := GetLine(prompt) if err != nil { return 0, err } return strconv.ParseInt(line, 10, 64) } // Choose presents a list and asks a user to choose one. func Choose(prompt string, choices []string) (int, error) { fmt.Println(prompt) Loading batch/batch.go +14 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,20 @@ the following files: To complete the installation, please enter the login, name and ssh key for the first user.`) system := storage.System{} system.Name, err = ask.GetLine("Enter system name: ") ask.CheckErr(err) system.DefaultExpire, err = ask.GetInt64("Enter default expiry in days: ") ask.CheckErr(err) system.ExpireLimit, err = ask.GetInt64("Enter expiration limit in days: ") ask.CheckErr(err) err = q.SetSystem(ctx, storage.SetSystemParams{ Name: system.Name, DefaultExpire: system.DefaultExpire, ExpireLimit: system.ExpireLimit, }) ask.CheckErr(err) login, err := ask.GetLine("Enter login of initial user: ") login = strings.ToUpper(login) ask.CheckErr(err) Loading storage/queries/standard.sql +6 −3 Original line number Diff line number Diff line Loading @@ -91,8 +91,11 @@ SELECT * FROM folder_configs WHERE login = ? AND folder = ?; -- name: DeleteFolderConfig :exec DELETE FROM folder_configs WHERE login = ? AND folder = ?; -- name: AddSystem :exec INSERT INTO system (name) VALUES (?); -- name: SetSystem :exec INSERT INTO system (rowid, name, default_expire, expire_limit) VALUES (1, ?1, ?2, ?3) ON CONFLICT(rowid) DO UPDATE SET name = ?1, default_expire = ?2, expire_limit = ?3; -- name: GetSystem :one SELECT * FROM system WHERE name = ?; SELECT * FROM system LIMIT 1; storage/standard.sql.go +21 −12 Original line number Diff line number Diff line Loading @@ -104,15 +104,6 @@ func (q *Queries) AddSeen(ctx context.Context, arg AddSeenParams) error { return err } const addSystem = `-- name: AddSystem :exec INSERT INTO system (name) VALUES (?) ` func (q *Queries) AddSystem(ctx context.Context, name string) error { _, err := q.db.ExecContext(ctx, addSystem, name) return err } const deleteFolder = `-- name: DeleteFolder :exec DELETE FROM folders WHERE name = ? ` Loading Loading @@ -398,11 +389,11 @@ func (q *Queries) GetSeen(ctx context.Context, arg GetSeenParams) (Seen, error) } const getSystem = `-- name: GetSystem :one SELECT name, default_expire, expire_limit FROM system WHERE name = ? SELECT name, default_expire, expire_limit FROM system LIMIT 1 ` func (q *Queries) GetSystem(ctx context.Context, name string) (System, error) { row := q.db.QueryRowContext(ctx, getSystem, name) func (q *Queries) GetSystem(ctx context.Context) (System, error) { row := q.db.QueryRowContext(ctx, getSystem) var i System err := row.Scan(&i.Name, &i.DefaultExpire, &i.ExpireLimit) return i, err Loading Loading @@ -677,3 +668,21 @@ func (q *Queries) ListUsers(ctx context.Context) ([]User, error) { } return items, nil } const setSystem = `-- name: SetSystem :exec INSERT INTO system (rowid, name, default_expire, expire_limit) VALUES (1, ?1, ?2, ?3) ON CONFLICT(rowid) DO UPDATE SET name = ?1, default_expire = ?2, expire_limit = ?3 ` type SetSystemParams struct { Name string DefaultExpire int64 ExpireLimit int64 } func (q *Queries) SetSystem(ctx context.Context, arg SetSystemParams) error { _, err := q.db.ExecContext(ctx, setSystem, arg.Name, arg.DefaultExpire, arg.ExpireLimit) return err } this/this.go +9 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ var MsgID int64 // used in a folder since changing into it. var ReadFirstCall bool // System has the information about the system. var System storage.System // StartThis starts a session. func StartThis(login string) error { // Validate the login name. Loading @@ -56,6 +59,12 @@ func StartThis(login string) error { Q = storage.New(Store.DB) ctx := storage.Context() System, err = Q.GetSystem(ctx) if err != nil { return err } fmt.Printf("Connected to the %s BULLETIN system.\n\n", System.Name) User, err = Q.GetUser(ctx, login) if User.Login != login { Loading Loading
ask/ask.go +9 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,15 @@ func GetLine(prompt string) (string, error) { return line, err } // GetInt64 gets a line. func GetInt64(prompt string) (int64, error) { line, err := GetLine(prompt) if err != nil { return 0, err } return strconv.ParseInt(line, 10, 64) } // Choose presents a list and asks a user to choose one. func Choose(prompt string, choices []string) (int, error) { fmt.Println(prompt) Loading
batch/batch.go +14 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,20 @@ the following files: To complete the installation, please enter the login, name and ssh key for the first user.`) system := storage.System{} system.Name, err = ask.GetLine("Enter system name: ") ask.CheckErr(err) system.DefaultExpire, err = ask.GetInt64("Enter default expiry in days: ") ask.CheckErr(err) system.ExpireLimit, err = ask.GetInt64("Enter expiration limit in days: ") ask.CheckErr(err) err = q.SetSystem(ctx, storage.SetSystemParams{ Name: system.Name, DefaultExpire: system.DefaultExpire, ExpireLimit: system.ExpireLimit, }) ask.CheckErr(err) login, err := ask.GetLine("Enter login of initial user: ") login = strings.ToUpper(login) ask.CheckErr(err) Loading
storage/queries/standard.sql +6 −3 Original line number Diff line number Diff line Loading @@ -91,8 +91,11 @@ SELECT * FROM folder_configs WHERE login = ? AND folder = ?; -- name: DeleteFolderConfig :exec DELETE FROM folder_configs WHERE login = ? AND folder = ?; -- name: AddSystem :exec INSERT INTO system (name) VALUES (?); -- name: SetSystem :exec INSERT INTO system (rowid, name, default_expire, expire_limit) VALUES (1, ?1, ?2, ?3) ON CONFLICT(rowid) DO UPDATE SET name = ?1, default_expire = ?2, expire_limit = ?3; -- name: GetSystem :one SELECT * FROM system WHERE name = ?; SELECT * FROM system LIMIT 1;
storage/standard.sql.go +21 −12 Original line number Diff line number Diff line Loading @@ -104,15 +104,6 @@ func (q *Queries) AddSeen(ctx context.Context, arg AddSeenParams) error { return err } const addSystem = `-- name: AddSystem :exec INSERT INTO system (name) VALUES (?) ` func (q *Queries) AddSystem(ctx context.Context, name string) error { _, err := q.db.ExecContext(ctx, addSystem, name) return err } const deleteFolder = `-- name: DeleteFolder :exec DELETE FROM folders WHERE name = ? ` Loading Loading @@ -398,11 +389,11 @@ func (q *Queries) GetSeen(ctx context.Context, arg GetSeenParams) (Seen, error) } const getSystem = `-- name: GetSystem :one SELECT name, default_expire, expire_limit FROM system WHERE name = ? SELECT name, default_expire, expire_limit FROM system LIMIT 1 ` func (q *Queries) GetSystem(ctx context.Context, name string) (System, error) { row := q.db.QueryRowContext(ctx, getSystem, name) func (q *Queries) GetSystem(ctx context.Context) (System, error) { row := q.db.QueryRowContext(ctx, getSystem) var i System err := row.Scan(&i.Name, &i.DefaultExpire, &i.ExpireLimit) return i, err Loading Loading @@ -677,3 +668,21 @@ func (q *Queries) ListUsers(ctx context.Context) ([]User, error) { } return items, nil } const setSystem = `-- name: SetSystem :exec INSERT INTO system (rowid, name, default_expire, expire_limit) VALUES (1, ?1, ?2, ?3) ON CONFLICT(rowid) DO UPDATE SET name = ?1, default_expire = ?2, expire_limit = ?3 ` type SetSystemParams struct { Name string DefaultExpire int64 ExpireLimit int64 } func (q *Queries) SetSystem(ctx context.Context, arg SetSystemParams) error { _, err := q.db.ExecContext(ctx, setSystem, arg.Name, arg.DefaultExpire, arg.ExpireLimit) return err }
this/this.go +9 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ var MsgID int64 // used in a folder since changing into it. var ReadFirstCall bool // System has the information about the system. var System storage.System // StartThis starts a session. func StartThis(login string) error { // Validate the login name. Loading @@ -56,6 +59,12 @@ func StartThis(login string) error { Q = storage.New(Store.DB) ctx := storage.Context() System, err = Q.GetSystem(ctx) if err != nil { return err } fmt.Printf("Connected to the %s BULLETIN system.\n\n", System.Name) User, err = Q.GetUser(ctx, login) if User.Login != login { Loading