clear:formatting code

This commit is contained in:
zhangwenjian
2020-07-23 12:03:17 +08:00
parent 426cec1b62
commit 8c554d7ee7
52 changed files with 486 additions and 502 deletions
+4 -9
View File
@@ -10,10 +10,10 @@ type Response struct {
}
type Page struct {
List interface{} `json:"list"`
Count int `json:"count"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
List interface{} `json:"list"`
Count int `json:"count"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
}
type PageResponse struct {
@@ -25,7 +25,6 @@ type PageResponse struct {
Msg string `json:"msg"`
}
func (res *Response) ReturnOK() *Response {
res.Code = 200
return res
@@ -36,11 +35,7 @@ func (res *Response) ReturnError(code int) *Response {
return res
}
func (res *PageResponse) ReturnOK() *PageResponse {
res.Code = 200
return res
}
+2 -2
View File
@@ -26,7 +26,7 @@ func OK(c *gin.Context, data interface{}, msg string) {
}
// 分页数据处理
func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize int, msg string) {
func PageOK(c *gin.Context, result interface{}, count int, pageIndex int, pageSize int, msg string) {
var res PageResponse
res.Data.List = result
res.Data.Count = count
@@ -40,5 +40,5 @@ func PageOK(c *gin.Context, result interface{},count int,pageIndex int,pageSize
// 兼容函数
func Custum(c *gin.Context, data gin.H) {
c.JSON(http.StatusOK,data)
c.JSON(http.StatusOK, data)
}
+3 -5
View File
@@ -20,9 +20,8 @@ type configJsonBody struct {
DriverDigit *base64Captcha.DriverDigit
}
func DriverStringFunc() (id, b64s string, err error) {
e :=configJsonBody{}
func DriverStringFunc() (id, b64s string, err error) {
e := configJsonBody{}
e.Id = uuid.New().String()
e.DriverString = base64Captcha.NewDriverString(46, 140, 2, 2, 4, "234567890abcdefghjkmnpqrstuvwxyz", &color.RGBA{240, 240, 246, 246}, []string{"wqy-microhei.ttc"})
driver := e.DriverString.ConvertFonts()
@@ -30,7 +29,6 @@ func DriverStringFunc() (id, b64s string, err error) {
return cap.Generate()
}
func DriverDigitFunc() (id, b64s string, err error) {
e := configJsonBody{}
e.Id = uuid.New().String()
@@ -38,4 +36,4 @@ func DriverDigitFunc() (id, b64s string, err error) {
driver := e.DriverDigit
cap := base64Captcha.NewCaptcha(driver, store)
return cap.Generate()
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ func portDefault(cfg *viper.Viper) string {
}
func isHttpsDefault(cfg *viper.Viper) bool {
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false{
if cfg.GetString("ishttps") == "" || cfg.GetBool("ishttps") == false {
return false
} else {
return true
-3
View File
@@ -16,7 +16,6 @@ var cfgLog *viper.Viper
var cfgSsl *viper.Viper
var cfgGen *viper.Viper
//载入配置文件
func ConfigSetup(path string) {
viper.SetConfigFile(path)
@@ -25,7 +24,6 @@ func ConfigSetup(path string) {
log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error()))
}
//Replace environment variables
err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content))))
if err != nil {
@@ -69,7 +67,6 @@ func ConfigSetup(path string) {
GenConfig = InitGen(cfgGen)
}
func SetConfig(configPath string, key string, value interface{}) {
viper.AddConfigPath(configPath)
viper.Set(key, value)
-1
View File
@@ -19,4 +19,3 @@ func InitDatabase(cfg *viper.Viper) *Database {
}
var DatabaseConfig = new(Database)
+4 -4
View File
@@ -3,14 +3,14 @@ package config
import "github.com/spf13/viper"
type Gen struct {
DBName string
FrontPath string
DBName string
FrontPath string
}
func InitGen(cfg *viper.Viper) *Gen {
return &Gen{
DBName: cfg.GetString("dbname"),
FrontPath: cfg.GetString("frontpath"),
DBName: cfg.GetString("dbname"),
FrontPath: cfg.GetString("frontpath"),
}
}
+2 -2
View File
@@ -3,13 +3,13 @@ package config
import "github.com/spf13/viper"
type Log struct {
Dir string
Dir string
Operdb bool
}
func InitLog(cfg *viper.Viper) *Log {
return &Log{
Dir: cfg.GetString("dir"),
Dir: cfg.GetString("dir"),
Operdb: cfg.GetBool("operdb"),
}
}
+4 -4
View File
@@ -5,9 +5,9 @@ type (
)
const (
ModeDev Mode = "dev" //开发模式
ModeTest Mode = "test" //测试模式
ModeProd Mode = "prod" //生产模式
Mysql = "mysql" //mysql数据库标识
ModeDev Mode = "dev" //开发模式
ModeTest Mode = "test" //测试模式
ModeProd Mode = "prod" //生产模式
Mysql = "mysql" //mysql数据库标识
Sqlite = "sqlite3" //sqlite
)
+6 -5
View File
@@ -55,7 +55,7 @@ func FileRemove(name string) {
}
}
func FileZip(dst, src string,notContPath string) (err error) {
func FileZip(dst, src string, notContPath string) (err error) {
//创建准备写入的文件
fw, err := os.Create(dst)
defer fw.Close()
@@ -119,6 +119,7 @@ type ReplaceHelper struct {
OldText string //需要替换的文本
NewText string //新的文本
}
func (h *ReplaceHelper) DoWrok() error {
return filepath.Walk(h.Root, h.walkCallback)
@@ -134,7 +135,7 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
return nil
}
if f.IsDir() {
log.Println("DIR:",path)
log.Println("DIR:", path)
return nil
}
@@ -146,8 +147,8 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
return err
}
content := string(buf)
log.Printf("h.OldText: %s \n",h.OldText)
log.Printf("h.NewText: %s \n",h.NewText)
log.Printf("h.OldText: %s \n", h.OldText)
log.Printf("h.NewText: %s \n", h.NewText)
//替换
newContent := strings.Replace(content, h.OldText, h.NewText, -1)
@@ -156,4 +157,4 @@ func (h ReplaceHelper) walkCallback(path string, f os.FileInfo, err error) error
ioutil.WriteFile(path, []byte(newContent), 0)
return err
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ import "strconv"
func Float64ToString(e float64) string {
return strconv.FormatFloat(e, 'E', -1, 64)
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ import "strconv"
func IntToString(e int) string {
return strconv.Itoa(e)
}
}
+1 -1
View File
@@ -4,4 +4,4 @@ import "strconv"
func Int64ToString(e int64) string {
return strconv.FormatInt(e, 10)
}
}
+1 -1
View File
@@ -30,4 +30,4 @@ func GetLocation(ip string) string {
return "未知位置"
}
return m["province"] + "-" + m["city"]
}
}
-1
View File
@@ -14,7 +14,6 @@ func InitLogger() {
log.FieldKeyLevel: "@level",
log.FieldKeyMsg: "@message"}})
switch Mode(config2.ApplicationConfig.Mode) {
case ModeDev, ModeTest:
log.SetOutput(os.Stdout)
-2
View File
@@ -17,7 +17,6 @@ func StringToInt(e string) (int, error) {
return strconv.Atoi(e)
}
func GetCurrentTimeStr() string {
return time.Now().Format("2006/01/02 15:04:05")
}
@@ -26,7 +25,6 @@ func GetCurrentTime() time.Time {
return time.Now()
}
func StructToJsonStr(e interface{}) (string, error) {
if b, err := json.Marshal(e); err == nil {
return string(b), err
+1 -2
View File
@@ -10,7 +10,6 @@ func IdsStrToIdsIntGroup(key string, c *gin.Context) []int {
return idsStrToIdsIntGroup(c.Param(key))
}
func idsStrToIdsIntGroup(keys string) []int {
IDS := make([]int, 0)
ids := strings.Split(keys, ",")
@@ -19,4 +18,4 @@ func idsStrToIdsIntGroup(keys string) []int {
IDS = append(IDS, ID)
}
return IDS
}
}