-
-
Notifications
You must be signed in to change notification settings - Fork 620
/
configs_form.go
69 lines (63 loc) · 1.6 KB
/
configs_form.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
package configs
import (
"github.com/pkg/errors"
"github.com/statping/statping/utils"
"net/http"
"strconv"
)
func LoadConfigForm(r *http.Request) (*DbConfig, error) {
if err := r.ParseForm(); err != nil {
return nil, err
}
g := r.PostForm.Get
dbHost := g("db_host")
dbUser := g("db_user")
dbPass := g("db_password")
dbDatabase := g("db_database")
dbConn := g("db_connection")
dbPort := utils.ToInt(g("db_port"))
project := g("project")
username := g("username")
password := g("password")
description := g("description")
domain := g("domain")
email := g("email")
language := g("language")
reports, _ := strconv.ParseBool(g("send_reports"))
if project == "" || username == "" || password == "" {
err := errors.New("Missing required elements on setup form")
return nil, err
}
p := utils.Params
p.Set("DB_CONN", dbConn)
p.Set("DB_HOST", dbHost)
p.Set("DB_USER", dbUser)
p.Set("DB_PORT", dbPort)
p.Set("DB_PASS", dbPass)
p.Set("DB_DATABASE", dbDatabase)
p.Set("NAME", project)
p.Set("DESCRIPTION", description)
p.Set("LANGUAGE", language)
p.Set("ALLOW_REPORTS", reports)
p.Set("ADMIN_USER", username)
p.Set("ADMIN_PASSWORD", password)
p.Set("ADMIN_EMAIL", email)
confg := &DbConfig{
DbConn: dbConn,
DbHost: dbHost,
DbUser: dbUser,
DbPass: dbPass,
DbData: dbDatabase,
DbPort: int(dbPort),
Project: project,
Description: description,
Domain: domain,
Username: username,
Password: password,
Email: email,
Location: utils.Directory,
Language: language,
AllowReports: reports,
}
return confg, nil
}