-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprestashop6.go
59 lines (51 loc) · 1.17 KB
/
prestashop6.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
package gocommerce
import (
"os"
"regexp"
"strconv"
"strings"
)
type Prestashop6 struct {
basePlatform
}
var p6LookupRgx = map[string]string{
"host": `define\('_DB_SERVER_',\s?'([^']+)'\);`,
"user": `define\('_DB_USER_',\s?'([^']+)'\);`,
"pass": `define\('_DB_PASSWD_',\s?'([^']+)'\);`,
"db": `define\('_DB_NAME_\',\s?'([^']+)'\);`,
"prefix": `define\('_DB_PREFIX_\',\s?'([^']+)'\);`,
}
func (p *Prestashop6) ParseConfig(cfgPath string) (*StoreConfig, error) {
data, err := os.ReadFile(cfgPath)
if err != nil {
return nil, err
}
matches := map[string]string{}
for k, v := range p6LookupRgx {
m := regexp.MustCompile(v).FindStringSubmatch(string(data))
if len(m) != 2 {
continue
}
matches[k] = m[1]
}
port := 3306
if strings.Contains(matches["host"], ":") {
parts := strings.Split(matches["host"], ":")
matches["host"] = parts[0]
newPort, err := strconv.Atoi(parts[1])
if err != nil {
return nil, err
}
port = newPort
}
return &StoreConfig{
DB: &DBConfig{
Host: matches["host"],
User: matches["user"],
Pass: matches["pass"],
Name: matches["db"],
Prefix: matches["prefix"],
Port: port,
},
}, nil
}