-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathresources.go
124 lines (112 loc) · 2.91 KB
/
resources.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"fmt"
"os"
"path"
"strings"
)
const (
resApplicationYmlTPL = `server:
port: ${PORT:${SERVER_PORT:9000}}
spring:
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://xx.xx.xx.xx:3306/db
username: root
password: 123456
maximum-pool-size: 100
max-idle: 10
max-wait: 10000
min-idle: 5
initial-size: 5
validation-query: SELECT 1
test-on-borrow: false
test-while-idle: true
time-between-eviction-runs-millis: 18800
---
server:
port: 9000
spring:
profiles: dev
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://xx.xx.xx.xx:3306/db
username: root
password: 123456
---
`
resBootstrapYmlTPL = `spring:
application:
name: {{projectName}}
`
resLog4j2XmlTPL = `<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%date %level %class %method : %msg%n"/>
</Console>
<File name="RollingFileError" fileName="E:/logs/error.log"
filePattern="E:logs/logs/$${date:yyyy-MM}/error-%d{yyyy-MM-dd}-%i.log">
<ThresholdFilter level="ERROR"/>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</File>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
<AppenderRef ref="RollingFileError" />
</Root>
<Logger name="org.hibernate.SQL" level="trace" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="org.hibernate.type.descriptor" level="trace" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="java.sql" level="debug" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="springfox.documentation" level="warn" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
</Configuration>
`
)
func writeResourcesFiles(mPath, projectName, fileName, data string) {
fpath := path.Join(mPath, fileName)
var f *os.File
var err error
if isExist(fpath) {
fmt.Printf("[WARN] '%v' already exists. Do you want to overwrite it? [Yes|No] ", fpath)
if askForConfirmation() {
f, err = os.OpenFile(fpath, os.O_RDWR|os.O_TRUNC, 0666)
if err != nil {
fmt.Printf("[WARN] %v\n", err)
return
}
} else {
fmt.Printf("[WARN] Skipped create file '%s'\n", fpath)
return
}
} else {
f, err = os.OpenFile(fpath, os.O_CREATE|os.O_RDWR, 0666)
if err != nil {
fmt.Printf("[WARN] %v\n", err)
return
}
}
fileStr := strings.Replace(data, "{{projectName}}", projectName, -1)
if _, err := f.WriteString(fileStr); err != nil {
fmt.Printf("[ERRO] Could not write resources file to %s\n", fpath)
os.Exit(2)
}
CloseFile(f)
}