Skip to content

Commit

Permalink
update config.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Apr 5, 2024
1 parent de11b49 commit 4ae10a9
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 55 deletions.
7 changes: 3 additions & 4 deletions compile_assets.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -54,11 +53,11 @@ var AssetPaths = map[string]string{
listContent += `
}`

err = ioutil.WriteFile(outputPath+"/assets_list.go", []byte(listContent), 0644)
err = os.WriteFile(outputPath+"/assets_list.go", []byte(listContent), 0644)
if err != nil {
return
}
err = ioutil.WriteFile(outputPath+"/assets_path.go", []byte(pathsContent), 0644)
err = os.WriteFile(outputPath+"/assets_path.go", []byte(pathsContent), 0644)
if err != nil {
return
}
Expand All @@ -67,7 +66,7 @@ var AssetPaths = map[string]string{

func getAllFiles(dirPth string) (files []string, err error) {
var dirs []string
dir, err := ioutil.ReadDir(dirPth)
dir, err := os.ReadDir(dirPth)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions compile_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path"
"strings"
)
Expand All @@ -16,7 +16,7 @@ var ` + varName + ` = map[string]string{`

content += `}`

_ = ioutil.WriteFile(outputPath, []byte(content), 0644)
_ = os.WriteFile(outputPath, []byte(content), 0644)
}

func fixPath(p string) string {
Expand All @@ -27,7 +27,7 @@ func fixPath(p string) string {
}

func getContentFromDir(content, dirPath, rootPath string) string {
files, _ := ioutil.ReadDir(dirPath)
files, _ := os.ReadDir(dirPath)

for _, f := range files {

Expand All @@ -36,7 +36,7 @@ func getContentFromDir(content, dirPath, rootPath string) string {
continue
}

b, err := ioutil.ReadFile(dirPath + f.Name())
b, err := os.ReadFile(dirPath + f.Name())
if err != nil {
fmt.Print(err)
}
Expand Down
18 changes: 9 additions & 9 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ func askForDBConfig(info *dbInfo) config.DatabaseList {

return map[string]config.Database{
"default": {
Host: info.Host,
Port: info.Port,
User: info.User,
Pwd: info.Password,
Name: info.Database,
MaxIdleCon: 5,
MaxOpenCon: 10,
Driver: info.DriverName,
File: "",
Host: info.Host,
Port: info.Port,
User: info.User,
Pwd: info.Password,
Name: info.Database,
MaxIdleConns: 5,
MaxOpenConns: 10,
Driver: info.DriverName,
File: "",
},
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/AlecAivazis/survey/v2 v2.3.1 h1:lzkuHA60pER7L4eYL8qQJor4bUWlJe4V0gqAT
github.com/AlecAivazis/survey/v2 v2.3.1/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GoAdminGroup/go-admin v1.2.23 h1:myn18AVWNs2U2e2OwzzSDk1QNlOsOvv1t8G4X8UygE4=
github.com/GoAdminGroup/go-admin v1.2.23/go.mod h1:EX+fDr3yPIQ8jKoXzjh5A8MbhfCY2KOhcd0rctlxBH4=
github.com/GoAdminGroup/go-admin v1.2.24 h1:s1pyok1zAkDj+Ro0TKsB+2igyJ7sepHIXpB78LeuoQU=
github.com/GoAdminGroup/go-admin v1.2.24/go.mod h1:voQOP8uoaNi/V0EO3WtOvAm3fvTaNlxrmpe4nZdbzas=
github.com/GoAdminGroup/html v0.0.1 h1:SdWNWl4OKPsvDk2GDp5ZKD6ceWoN8n4Pj6cUYxavUd0=
github.com/GoAdminGroup/html v0.0.1/go.mod h1:A1laTJaOx8sQ64p2dE8IqtstDeCNBHEazrEp7hR5VvM=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
Expand Down Expand Up @@ -58,6 +58,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
Expand Down Expand Up @@ -133,8 +135,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/schollz/progressbar v1.0.0 h1:gbyFReLHDkZo8mxy/dLWMr+Mpb1MokGJ1FqCiqacjZM=
github.com/schollz/progressbar v1.0.0/go.mod h1:/l9I7PC3L3erOuz54ghIRKUEFcosiWfLvJv+Eq26UMs=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
12 changes: 6 additions & 6 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"errors"
"fmt"
"go/format"
"io"
"io/fs"
"io/ioutil"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -47,7 +47,7 @@ func getLatestVersion() string {
return ""
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)

if err != nil || body == nil {
return ""
Expand Down Expand Up @@ -95,7 +95,7 @@ func mkdirs(dirs []string) {

func mkEmptyFiles(names []string) {
for _, name := range names {
checkError(ioutil.WriteFile(name, []byte{}, os.ModePerm))
checkError(os.WriteFile(name, []byte{}, os.ModePerm))
}
}

Expand Down Expand Up @@ -157,16 +157,16 @@ func (cfgs *WriteFilesConfig) AddRaw(path, file string, perm fs.FileMode) {

func writeFileOfInstallation(cfg WriteFileConfig) {
if cfg.IsFormat {
checkError(ioutil.WriteFile(cfg.Path, parseFileWithFormat(readFileOfInstallation(&installationTmplFS, cfg.File), cfg.Data), cfg.Perm))
checkError(os.WriteFile(cfg.Path, parseFileWithFormat(readFileOfInstallation(&installationTmplFS, cfg.File), cfg.Data), cfg.Perm))
return
}
checkError(ioutil.WriteFile(cfg.Path, parseFile(readFileOfInstallation(&installationTmplFS, cfg.File), cfg.Data), cfg.Perm))
checkError(os.WriteFile(cfg.Path, parseFile(readFileOfInstallation(&installationTmplFS, cfg.File), cfg.Data), cfg.Perm))
}

func writeFilesOfInstallation(cfgs WriteFilesConfig) {
for _, cfg := range cfgs {
if !cfg.Parse {
checkError(ioutil.WriteFile(cfg.Path, []byte(readFileOfInstallation(&installationTmplFS, cfg.File)), cfg.Perm))
checkError(os.WriteFile(cfg.Path, []byte(readFileOfInstallation(&installationTmplFS, cfg.File)), cfg.Perm))
continue
}
writeFileOfInstallation(cfg)
Expand Down
9 changes: 4 additions & 5 deletions minify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -75,7 +74,7 @@ func jsMinifier(inputDir, outputFile string, hash bool) {
}

filePath := inputDir + name
fileTxt, err := ioutil.ReadFile(filePath)
fileTxt, err := os.ReadFile(filePath)
if err != nil {
checkError(err)
}
Expand Down Expand Up @@ -128,7 +127,7 @@ func removeOutputFile(outputFile string) error {
func getInputFiles(inputDir string) ([]string, error) {
filenames := make([]string, 0, 1)

files, err := ioutil.ReadDir(inputDir)
files, err := os.ReadDir(inputDir)
if err != nil {
log.Panicln("readInputDirError", err)
return filenames, err
Expand Down Expand Up @@ -157,7 +156,7 @@ func combineFiles(filenames []string, inputDir string) (string, error) {
}

filePath := inputDir + name
fileTxt, err := ioutil.ReadFile(filePath)
fileTxt, err := os.ReadFile(filePath)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -189,7 +188,7 @@ func makeMini(notMinifiedString, fileType string) (string, error) {
}

func writeOutputFile(outputText, outputFile string) error {
err := ioutil.WriteFile(outputFile, []byte(outputText), 0644)
err := os.WriteFile(outputFile, []byte(outputText), 0644)
if err != nil {
return err
}
Expand Down
21 changes: 10 additions & 11 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"go/format"
"io/ioutil"
"os"
"strings"
"text/template"
Expand All @@ -18,20 +17,20 @@ func getPluginTemplate(modulePath, pluginName string) {
PluginName: pluginName,
PluginTitle: strings.Title(pluginName),
}
checkError(ioutil.WriteFile("./"+pluginName+".go", parsePluginTmpl("main", data), 0644))
checkError(ioutil.WriteFile("./router.go", parsePluginTmpl("router", data), 0644))
checkError(os.WriteFile("./"+pluginName+".go", parsePluginTmpl("main", data), 0644))
checkError(os.WriteFile("./router.go", parsePluginTmpl("router", data), 0644))
checkError(os.Mkdir("controller", os.ModePerm))
checkError(ioutil.WriteFile("./controller/common.go", parsePluginTmpl("controller", data), 0644))
checkError(ioutil.WriteFile("./controller/example.go", parsePluginTmpl("controller_example", data), 0644))
checkError(os.WriteFile("./controller/common.go", parsePluginTmpl("controller", data), 0644))
checkError(os.WriteFile("./controller/example.go", parsePluginTmpl("controller_example", data), 0644))
checkError(os.Mkdir("guard", os.ModePerm))
checkError(ioutil.WriteFile("./guard/guard.go", parsePluginTmpl("guard", data), 0644))
checkError(ioutil.WriteFile("./guard/example.go", parsePluginTmpl("guard_example", data), 0644))
checkError(os.WriteFile("./guard/guard.go", parsePluginTmpl("guard", data), 0644))
checkError(os.WriteFile("./guard/example.go", parsePluginTmpl("guard_example", data), 0644))
checkError(os.Mkdir("modules", os.ModePerm))
checkError(os.Mkdir("./modules/language", os.ModePerm))
checkError(ioutil.WriteFile("./modules/language/language.go", parsePluginTmpl("language", data), 0644))
checkError(ioutil.WriteFile("./modules/language/cn.go", parsePluginTmpl("language_cn", data), 0644))
checkError(ioutil.WriteFile("./modules/language/en.go", parsePluginTmpl("language_en", data), 0644))
checkError(ioutil.WriteFile("./Makefile", []byte(pluginTemplate["makefile"]), 0644))
checkError(os.WriteFile("./modules/language/language.go", parsePluginTmpl("language", data), 0644))
checkError(os.WriteFile("./modules/language/cn.go", parsePluginTmpl("language_cn", data), 0644))
checkError(os.WriteFile("./modules/language/en.go", parsePluginTmpl("language_en", data), 0644))
checkError(os.WriteFile("./Makefile", []byte(pluginTemplate["makefile"]), 0644))
checkError(os.Mkdir("example", os.ModePerm))
checkError(os.Mkdir("tests", os.ModePerm))
fmt.Println()
Expand Down
25 changes: 25 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ var installationTmplFS embed.FS

func installProjectTmpl(p Project, cfg *config.Config, cfgFile string, info *dbInfo) {

cfg.Logger.Encoder = defaultEncoderCfg
cfg.Logger.Rotate = defaultRotateCfg

mkdirs([]string{"pages", "tables", "logs", "uploads", "html", "build"})
mkEmptyFiles([]string{"./logs/access.log", "./logs/info.log", "./logs/error.log"})

Expand Down Expand Up @@ -278,3 +281,25 @@ func installProjectTmpl(p Project, cfg *config.Config, cfgFile string, info *dbI

writeFilesOfInstallation(*fileConfigs)
}

var (
defaultEncoderCfg = config.EncoderCfg{
TimeKey: "ts",
LevelKey: "level",
NameKey: "logger",
CallerKey: "caller",
MessageKey: "msg",
StacktraceKey: "stacktrace",
Level: "capitalColor",
Time: "ISO8601",
Duration: "seconds",
Caller: "short",
Encoding: "console",
}
defaultRotateCfg = config.RotateCfg{
MaxSize: 10,
MaxBackups: 5,
MaxAge: 30,
Compress: false,
}
)
16 changes: 8 additions & 8 deletions project_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ func buildProjectWeb(port string) {
if info.DriverName != db.DriverSqlite {
dbList = map[string]config.Database{
"default": {
Host: info.Host,
Port: info.Port,
User: info.User,
Pwd: info.Password,
Name: info.Database,
MaxIdleCon: 5,
MaxOpenCon: 10,
Driver: info.DriverName,
Host: info.Host,
Port: info.Port,
User: info.User,
Pwd: info.Password,
Name: info.Database,
MaxIdleConns: 5,
MaxOpenConns: 10,
Driver: info.DriverName,
},
}
} else {
Expand Down
7 changes: 3 additions & 4 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"archive/zip"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -116,19 +115,19 @@ func unzipDir(src, dest string) error {
}

func replaceContents(fileDir, moduleName, themeName string) {
files, err := ioutil.ReadDir(fileDir)
files, err := os.ReadDir(fileDir)
checkError(err)
for _, file := range files {
path := fileDir + "/" + file.Name()
if !file.IsDir() {
buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
checkError(err)
content := string(buf)

newContent := utils.ReplaceAll(content, "github.com/GoAdminGroup/themes/adminlte", moduleName,
"adminlte", themeName, "Adminlte", strings.Title(themeName))

checkError(ioutil.WriteFile(path, []byte(newContent), 0))
checkError(os.WriteFile(path, []byte(newContent), 0))
}
}
}
39 changes: 39 additions & 0 deletions templates/installation/config.yml/cn.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,43 @@ operation_log_off: {{.OperationLogOff}}
# show_create: /info/:__prefix/new
# update: /update/:__prefix

# Logger配置用于设置日志记录器的行为和设置。
# 更多细节:https://pkg.go.dev/go.uber.org/zap
logger:
# Encoder配置用于设置日志编码器的行为和设置。
encoder:
# 时间键
time_key: {{.Logger.Encoder.TimeKey}}
# 级别键
level_key: {{.Logger.Encoder.LevelKey}}
# 名称键
name_key: {{.Logger.Encoder.NameKey}}
# 调用者键
caller_key: {{.Logger.Encoder.CallerKey}}
# 消息键
message_key: {{.Logger.Encoder.MessageKey}}
# 堆栈跟踪键
stacktrace_key: {{.Logger.Encoder.StacktraceKey}}
# 级别格式
level: {{.Logger.Encoder.Level}}
# 时间格式
time: {{.Logger.Encoder.Time}}
# 间隔
duration: {{.Logger.Encoder.Duration}}
# 调用者格式
caller: {{.Logger.Encoder.Caller}}
# 编码格式 console/json
encoding: {{.Logger.Encoder.Encoding}}

# Rotate配置用于设置日志轮转的行为和设置。
rotate:
# 最大保存时间
max_age: {{.Logger.Rotate.MaxSize}}
# 最大保存数量
max_backups: {{.Logger.Rotate.MaxBackups}}
# 最大大小
max_size: {{.Logger.Rotate.MaxAge}}
# 压缩
compress: {{.Logger.Rotate.Compress}}

{{end}}
Loading

0 comments on commit 4ae10a9

Please sign in to comment.