Skip to content

Commit

Permalink
Dev 1.3.0 (#63)
Browse files Browse the repository at this point in the history
<!--
First of all, thank you for your contribution! 😄

For requesting to pull a new feature or bugfix, please send it from a
feature/bugfix branch based on the `master` branch.

Before submitting your pull request, please make sure the checklist
below is confirmed.

Your pull requests will be merged after one of the collaborators
approve.

Thank you!

-->

### 🤔 This is a ...

- [x] New feature
- [ ] Bug fix
- [x] Site / documentation update
- [ ] Demo update
- [ ] Component style update
- [ ] TypeScript definition update
- [ ] Bundle size optimization
- [ ] Performance optimization
- [ ] Enhancement feature
- [ ] Internationalization
- [ ] Refactoring
- [ ] Code style optimization
- [ ] Test Case
- [ ] Branch merge
- [ ] Other (about what?)

### 🔗 Related issue link

<!--
1. Put the related issue or discussion links here.
-->

### 💡 Background and solution

<!--
1. Describe the problem and the scenario.
2. GIF or snapshot should be provided if includes UI/interactive
modification.
3. How to fix the problem, and list the final API implementation and
usage sample if that is a new feature.
-->

### 📝 Changelog

<!--
Describe changes from the user side, and list all potential break
changes or other risks.
--->

| Language   | Changelog |
| ---------- | --------- |
| 🇺🇸 English |           |
| 🇨🇳 Chinese |           |

### ☑️ Self-Check before Merge

⚠️ Please check all items below before review. ⚠️

- [x] Doc is updated/provided or not needed
- [x] Demo is updated/provided or not needed
- [ ] TypeScript's definition is updated/provided or not needed
- [x] Changelog is provided or not needed
  • Loading branch information
xxl4 authored Nov 17, 2023
2 parents 96431e4 + 781075c commit b5f855f
Show file tree
Hide file tree
Showing 21 changed files with 539 additions and 373 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ jobs:
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: nicesteven/easy-admin

- name: Build and push Docker image version
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: nicesteven/easy-admin:1.3.0

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
Expand Down
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LDFLAGS := -s -w
# application name
PROJECT:=easy-admin
# application version
VERSION := 1.2.0
VERSION := 1.3.0
# application url
URL := https://github.com/nicelizhi/easy-admin

Expand All @@ -26,7 +26,7 @@ build-ui:

# build go application
build:
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -a -installsuffix "" -o $(PROJECT) .
CGO_ENABLED=0 go mod tidy && go build -ldflags="$(LDFLAGS)" -a -installsuffix "" -o $(PROJECT) .

# make build-linux
build-linux:
Expand Down Expand Up @@ -55,9 +55,14 @@ start:
nohup ./$(PROJECT) server -c=config/settings.dev_steve.yml >> acc.txt &
ps aux | grep "$(PROJECT)"

.PHONY: easy-admin
stop:
pkill $(PROJECT)

# debug file
debug:
dlv debug $(file)
dlv debug $(file)

.PHONY: docs
docs:
swag init -g easy-admin.go --parseDependency --parseDepth=6 --instanceName admin -o ./docs/admin
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ English | [简体中文](https://nicelizhi.github.io/easy-admin/zh/)

- TimeZone Support

- Static packaging for vue page


## Internal

Expand Down Expand Up @@ -103,4 +101,4 @@ http://localhost:8000/swagger/admin/index.html
[https://gitee.com/nicelizhi/easy-admin/issues](https://gitee.com/nicelizhi/easy-admin/issues) (中国)

# Discussions
[https://github.com/nicelizhi/easy-admin/discussions](https://github.com/nicelizhi/easy-admin/discussions)
[https://github.com/nicelizhi/easy-admin/discussions](https://github.com/nicelizhi/easy-admin/discussions)
3 changes: 1 addition & 2 deletions app/admin/apis/captcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apis
import (
"github.com/nicelizhi/easy-admin-core/sdk/api"
"github.com/nicelizhi/easy-admin-core/sdk/pkg/captcha"
_ "github.com/nicelizhi/easy-admin-core/sdk/pkg/response"

ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin"
Expand All @@ -21,14 +22,12 @@ type System struct {
func (e System) GenerateCaptchaHandler(c *gin.Context) {
err := e.MakeContext(c).Errors
if err != nil {
//e.Error(500, err, "服务初始化失败!")
e.Error(500, err, ginI18n.MustGetMessage(c, "Service initialization failed"))
return
}
id, b64s, err := captcha.DriverDigitFunc()
if err != nil {
e.Logger.Errorf("DriverDigitFunc error, %s", err.Error())
//e.Error(500, err, "验证码获取失败")
e.Error(500, err, ginI18n.MustGetMessage(c, "Failed to obtain verification code"))
return
}
Expand Down
1 change: 1 addition & 0 deletions app/admin/apis/sys_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"

_ "github.com/nicelizhi/easy-admin-core/sdk/pkg/response"
"github.com/nicelizhi/easy-admin/app/admin/models"
"github.com/nicelizhi/easy-admin/app/admin/service"
"github.com/nicelizhi/easy-admin/app/admin/service/dto"
Expand Down
1 change: 1 addition & 0 deletions app/admin/apis/sys_login_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"

_ "github.com/nicelizhi/easy-admin-core/sdk/pkg/response"
"github.com/nicelizhi/easy-admin/app/admin/service"
"github.com/nicelizhi/easy-admin/app/admin/service/dto"
)
Expand Down
39 changes: 38 additions & 1 deletion app/admin/apis/sys_menu.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package apis

import (
"fmt"

"github.com/nicelizhi/easy-admin/app/admin/models"

"github.com/nicelizhi/easy-admin-core/sdk/api"
Expand All @@ -10,6 +12,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"

_ "github.com/nicelizhi/easy-admin-core/sdk/pkg/response"
"github.com/nicelizhi/easy-admin/app/admin/service"
"github.com/nicelizhi/easy-admin/app/admin/service/dto"
)
Expand Down Expand Up @@ -76,7 +79,41 @@ func (e SysMenu) CusGetPage(c *gin.Context) {
return
}

list2 := make(map[string]interface{}, 0)
list2 := make([]interface{}, 0)

for index, item := range list {
var litem = make(map[string]interface{})
var meta = make(map[string]interface{})
var children = make([]interface{}, 0)
for index1, item2 := range item.Children {
var litem2 = make(map[string]interface{})
var meta2 = make(map[string]interface{})

litem2["name"] = item2.MenuName
litem2["path"] = item2.Path
meta2["locale"] = item2.Permission
meta2["requiresAuth"] = true
meta2["hideInMenu"] = false
meta2["icon"] = item2.Icon
meta2["order"] = item2.Sort
meta2["roles"] = item2.Permission
litem2["meta"] = meta2
fmt.Println(index1)
children = append(children[:len(children)], litem2)
}

meta["locale"] = item.Permission
meta["requiresAuth"] = true
meta["hideInMenu"] = false
meta["icon"] = item.Icon
meta["order"] = item.Sort
litem["name"] = item.MenuName
litem["path"] = item.Path
litem["meta"] = meta
litem["children"] = children
fmt.Println(index, " = ", item)
list2 = append(list2[:len(list2)], litem)
}

e.OK(list2, ginI18n.MustGetMessage(c, "Query successful"))
}
Expand Down
1 change: 1 addition & 0 deletions app/admin/apis/sys_opera_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/nicelizhi/easy-admin/app/admin/service/dto"

"github.com/nicelizhi/easy-admin-core/sdk/api"
_ "github.com/nicelizhi/easy-admin-core/sdk/pkg/response"

ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin"
Expand Down
2 changes: 1 addition & 1 deletion app/admin/apis/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (e SysUser) GetInfo(c *gin.Context) {
req.Id = user.GetUserId(c)
err = s.Get(&req, p, &sysUser)
if err != nil {
e.Error(http.StatusUnauthorized, err, "登录失败")
e.Error(http.StatusUnauthorized, err, ginI18n.MustGetMessage(c, "Login failed"))
return
}
mp["introduction"] = " am a super administrator"
Expand Down
2 changes: 1 addition & 1 deletion app/admin/models/initdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func InitDb(db *gorm.DB) (err error) {
func ExecSql(db *gorm.DB, filePath string) error {
sql, err := Ioutil(filePath)
if err != nil {
fmt.Println("数据库基础数据初始化脚本读取失败!原因:", err.Error())
fmt.Println("Error Detail: ", err.Error())
return err
}
sqlList := strings.Split(sql, ";")
Expand Down
2 changes: 1 addition & 1 deletion cmd/migrate/migration/models/initdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func InitDb(db *gorm.DB) (err error) {
func ExecSql(db *gorm.DB, filePath string) error {
sql, err := Ioutil(filePath)
if err != nil {
fmt.Println("数据库基础数据初始化脚本读取失败!原因:", err.Error())
fmt.Println("Error Detail:", err.Error())
return err
}
sqlList := strings.Split(sql, ";")
Expand Down
11 changes: 9 additions & 2 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"syscall"
"time"

"github.com/gin-contrib/gzip"
"github.com/nicelizhi/easy-admin-core/config/source/file"
"github.com/nicelizhi/easy-admin-core/sdk"
"github.com/nicelizhi/easy-admin-core/sdk/api"
Expand Down Expand Up @@ -180,9 +181,14 @@ func initRouter() {
log.Fatal("not support other engine")
//os.Exit(-1)
}
if config.SslConfig.Enable {
r.Use(handler.TlsHandler())
// if config.SslConfig.Enable {
r.Use(handler.TlsHandler()) // add more secure for it
// }

if config.ApplicationConfig.Gzip {
r.Use(gzip.Gzip(config.ApplicationConfig.GzipLevel))
}

r.Use(common.Sentinel()).
Use(common.RequestId(pkg.TrafficKey)).
Use(api.SetRequestLogger).
Expand All @@ -199,6 +205,7 @@ func initRouter() {
flag := strings.Contains(accept, "text/html")
if flag {
ctx.Writer.WriteHeader(200)
ctx.Header("Content-Type", "text/html; charset=utf-8")
ctx.Writer.WriteString(string(resource.Html))
ctx.Writer.Flush()
}
Expand Down
4 changes: 2 additions & 2 deletions common/global/adm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package global

const (
// Version easy-admin version info
Version = "1.2.0"
VersionNum = 120 // version number
Version = "1.3.0"
VersionNum = 130 // version number
HomePage = "https://github.com/nicelizhi/easy-admin/" //project home page
TemplateVer = "v1"
)
Expand Down
4 changes: 2 additions & 2 deletions common/middleware/handler/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func Authenticator(c *gin.Context) (interface{}, error) {
if config.ApplicationConfig.Mode != "dev" {
if !captcha.Verify(loginVals.UUID, loginVals.Code, true) {
username = loginVals.Username
msg = "验证码错误"
msg = ginI18n.MustGetMessage(c, "Verification code error")
status = "1"

return nil, jwt.ErrInvalidVerificationode
Expand All @@ -104,7 +104,7 @@ func Authenticator(c *gin.Context) (interface{}, error) {

return map[string]interface{}{"user": sysUser, "role": role}, nil
} else {
msg = "登录失败"
msg = ginI18n.MustGetMessage(c, "Login failed")
status = "1"
log.Warnf("%s login failed!", loginVals.Username)
}
Expand Down
33 changes: 26 additions & 7 deletions common/middleware/handler/httpshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,33 @@ import (

func TlsHandler() gin.HandlerFunc {
return func(c *gin.Context) {
secureMiddleware := secure.New(secure.Options{
SSLRedirect: true,
SSLHost: config.SslConfig.Domain,
})
err := secureMiddleware.Process(c.Writer, c.Request)
if err != nil {
return
if config.SslConfig.Enable {
secureMiddleware := secure.New(secure.Options{
SSLRedirect: true,
SSLHost: config.SslConfig.Domain,
IsDevelopment: true,
})
err := secureMiddleware.Process(c.Writer, c.Request)
if err != nil {
c.Abort()
return
}
} else {
secureMiddleware := secure.New(secure.Options{
IsDevelopment: true,
})
err := secureMiddleware.Process(c.Writer, c.Request)
if err != nil {
c.Abort()
return
}
}

// Avoid header rewrite if response is a redirection.
if status := c.Writer.Status(); status > 300 && status < 399 {
c.Abort()
}

c.Next()
}
}
9 changes: 9 additions & 0 deletions config/settings.full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ settings:
timezone: "Africa/Cairo"
# local
local: "en"
# gzip enable
gzip: true
#gzip level
# options 1、BestCompression 1、BestSpeed 1、DefaultCompression 1、NoCompression
# NoCompression = 0
# BestSpeed = 1
# BestCompression = 9
# DefaultCompression = -1
gziplevel: 9
ssl:
# https domain
domain: localhost:8000
Expand Down
Loading

0 comments on commit b5f855f

Please sign in to comment.