Skip to content

Commit

Permalink
1.工具类新增sm4加解密方法、身份证验证、md5摘要计算、版本打印方法,2.新增计划任务支持,3.更新examples示例,4.更新re…
Browse files Browse the repository at this point in the history
…adme
  • Loading branch information
keepchen committed Dec 27, 2023
1 parent cf6e7f1 commit 68ad55b
Show file tree
Hide file tree
Showing 25 changed files with 821 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ sail.GetRedisCluster()

//nats连接
sail.GetNats()

//kafka完整连接实例
sail.GetKafkaInstance()
```
更多组件持续开发中,也欢迎大家提PR👏🏻👏🏻

Expand Down
3 changes: 3 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ sail.GetRedisCluster()

//nats连接
sail.GetNats()

//kafka完整连接实例
sail.GetKafkaInstance()
```
PR is welcome👏🏻👏🏻

Expand Down
4 changes: 3 additions & 1 deletion constants/sail.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ const (
## #### ## ## ###### ## ## ## ##
## ## ## ## ## ######### ## ##
## ## ## ## ## ## ## ## ## ##
###### ####### ###### ## ## #### ########` //框架logo
###### ####### ###### ## ## #### ########` //框架logo

GoSailVersion = "3.0.0" //框架版本
)
4 changes: 4 additions & 0 deletions constants/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ const (
TimeZoneUTCPlus11 string = "Pacific/Kosrae"
TimeZoneUTCPlus12 string = "Pacific/Nauru"
)

const (
DatetimeLayout = "2006-01-02 15:04:05" //日期时间格式
)
29 changes: 29 additions & 0 deletions examples/logs/running.log
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,32 @@
{"level":"info","time":"2023-12-26T14:08:00.903+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-26T14:08:00.904+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-26T14:08:00.904+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T10:54:08.851+0800","line":"/private/var/www/keepchen/go-sail/http/middleware/printrequestpayload.go:15","func":"github.com/keepchen/go-sail/v3/http/middleware.PrintRequestPayload.func1","msg":"中间件:打印请求载荷","serviceName":"go-sail:<defaultModeName>","value":"GET /go-sail HTTP/1.1\r\nHost: 192.168.124.8:8000\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: zh-CN,zh;q=0.9,en;q=0.8\r\nConnection: keep-alive\r\nDnt: 1\r\nSec-Gpc: 1\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\r\n\r\n"}
{"level":"info","time":"2023-12-27T10:54:09.332+0800","line":"/private/var/www/keepchen/go-sail/http/middleware/printrequestpayload.go:15","func":"github.com/keepchen/go-sail/v3/http/middleware.PrintRequestPayload.func1","msg":"中间件:打印请求载荷","serviceName":"go-sail:<defaultModeName>","value":"GET /favicon.ico HTTP/1.1\r\nHost: 192.168.124.8:8000\r\nAccept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nAccept-Language: zh-CN,zh;q=0.9,en;q=0.8\r\nConnection: keep-alive\r\nDnt: 1\r\nReferer: http://192.168.124.8:8000/go-sail\r\nSec-Gpc: 1\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36\r\n\r\n"}
{"level":"info","time":"2023-12-27T10:54:31.388+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T10:54:31.388+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T10:54:31.388+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:24:37.438+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:24:37.439+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T15:24:37.439+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:26:00.599+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:26:00.599+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T15:26:00.599+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:31:41.373+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:31:41.373+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T15:31:41.373+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:42:22.028+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T15:42:22.029+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T15:42:22.029+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:07:12.681+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:07:12.682+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T16:07:12.682+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:14:20.287+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:14:20.287+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T16:14:20.287+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:32:52.336+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:32:52.338+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T16:32:52.338+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:39:21.054+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:70","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Shutting down server...","serviceName":"go-sail:<defaultModeName>"}
{"level":"info","time":"2023-12-27T16:39:21.055+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:63","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer.func2","msg":"listen error","serviceName":"go-sail:<defaultModeName>","error":[{"error":"http: Server closed"}]}
{"level":"info","time":"2023-12-27T16:39:21.055+0800","line":"/private/var/www/keepchen/go-sail/sail/httpserver/gin.go:76","func":"github.com/keepchen/go-sail/v3/sail/httpserver.RunHttpServer","msg":"Server exiting","serviceName":"go-sail:<defaultModeName>"}
6 changes: 6 additions & 0 deletions examples/pkg/app/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/keepchen/go-sail/v3/sail/config"
"github.com/keepchen/go-sail/v3/schedule"

"github.com/keepchen/go-sail/v3/lib/logger"

Expand Down Expand Up @@ -86,6 +88,10 @@ func StartServer(wg *sync.WaitGroup) {
}
after = func() {
fmt.Println("call user function [after] to do something...")
cancel := schedule.Job("print now datetime", func() {
fmt.Println("now: ", utils.FormatDate(time.Now(), utils.YYYY_MM_DD_HH_MM_SS_EN))
}).RunAt("* * * * *")
time.AfterFunc(time.Minute*3, cancel)
}
)

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ require (
github.com/nats-io/nats.go v1.26.0
github.com/pelletier/go-toml/v2 v2.0.8
github.com/prometheus/client_golang v1.14.0
github.com/robfig/cron/v3 v3.0.1
github.com/segmentio/kafka-go v0.4.47
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.4
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
github.com/swaggo/gin-swagger v1.5.3
github.com/swaggo/swag v1.8.8
github.com/tjfoc/gmsm v1.4.1
go.uber.org/zap v1.24.0
golang.org/x/net v0.17.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand Down Expand Up @@ -532,6 +534,8 @@ github.com/swaggo/gin-swagger v1.5.3/go.mod h1:3XJKSfHjDMB5dBo/0rrTXidPmgLeqsX89
github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ=
github.com/swaggo/swag v1.8.8 h1:/GgJmrJ8/c0z4R4hoEPZ5UeEhVGdvsII4JbVDLbR7Xc=
github.com/swaggo/swag v1.8.8/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho=
github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
Expand Down Expand Up @@ -610,6 +614,7 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down
7 changes: 7 additions & 0 deletions lib/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ func New(conf Conf) (rInstance, wInstance *gorm.DB) {

return
}

// Init 初始化数据库连接
//
// InitDB 的语法糖
func Init(conf Conf) {
InitDB(conf)
}
4 changes: 2 additions & 2 deletions sail/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func printSummaryInfo(conf config.HttpServerConf, ginEngine *gin.Engine) {
localIp, _ = utils.GetLocalIP()
delimiter = []byte(strings.Repeat("=", 88))
subDelimiter = []byte(strings.Repeat("-", 88))
blank = strings.Repeat(" ", len(delimiter)-len(version)-11)
blank = strings.Repeat(" ", len(delimiter)-len(constants.GoSailVersion)-11)
)
messages.Write(delimiter)
info := fmt.Sprintf("%s\n", constants.GoSailLogo)
messages.Write([]byte(info))
versionInfo := fmt.Sprintf("%s(version: %s)\n", blank, version)
versionInfo := fmt.Sprintf("%s(version: %s)\n", blank, constants.GoSailVersion)
messages.Write([]byte(versionInfo))
messages.Write(subDelimiter)
messages.Write([]byte("\n"))
Expand Down
4 changes: 2 additions & 2 deletions sail/sail.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (f *Framework) Launch(registerRoutes func(ginEngine *gin.Engine), before, a
}

//- logger
logger.InitLoggerZap(f.conf.LoggerConf, f.appName)
logger.Init(f.conf.LoggerConf, f.appName)

//- redis(standalone)
if len(f.conf.RedisConf.Host) != 0 {
Expand All @@ -78,7 +78,7 @@ func (f *Framework) Launch(registerRoutes func(ginEngine *gin.Engine), before, a

//- database
if len(f.conf.DBConf.DriverName) != 0 {
db.InitDB(f.conf.DBConf)
db.Init(f.conf.DBConf)
}

//- jwt
Expand Down
4 changes: 0 additions & 4 deletions sail/version.go

This file was deleted.

9 changes: 9 additions & 0 deletions schedule/crontabexpr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package schedule

// 一些常用的crontab表达式
const (
FirstDayOfMonth = "0 0 1 * *" //每月的第一天
LastDayOfMonth = "0 0 L * *" //每月的最后一天
FirstDayOfWeek = "0 0 * * 1" //每周的第一天(周一)
LastDayOfWeek = "0 0 * * 7" //每周的最后一天(周天)
)
Loading

0 comments on commit 68ad55b

Please sign in to comment.