Skip to content

Commit

Permalink
Merge pull request #28 from golang-acexy/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
acexy authored Oct 12, 2024
2 parents 7b2b2f7 + 2a959e6 commit a4bba56
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ginstarter/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func panicToError(panicError any) (statusCode int, err error, internalError bool
err = fmt.Errorf("%v", t)
}
}
logger.Logrus().Errorf("panic: %v\n", err)
logger.Logrus().Errorf("panic: %v", err)
return
}

Expand Down
54 changes: 54 additions & 0 deletions ginstarter/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,60 @@ func (r *Request) MustGetRawBodyString() string {
return conversion.FromBytes(r.MustGetRawBodyData())
}

// GetFormValue 获取Form表单的值
func (r *Request) GetFormValue(name string) (string, bool) {
return r.ctx.GetPostForm(name)
}

// MustGetFormValue 获取Form表单的值
// 任何错误将触发Panic流程中断
func (r *Request) MustGetFormValue(name string) string {
v, ok := r.GetFormValue(name)
if !ok {
panic(&internalPanic{
statusCode: http.StatusBadRequest,
rawError: errors.New("param name = " + name + " not set"),
})
}
return v
}

// GetFormArray 获取Form表单的值
func (r *Request) GetFormArray(name string) ([]string, bool) {
return r.ctx.GetPostFormArray(name)
}

// MustGetFormArray 获取Form表单的值
// 任何错误将触发Panic流程中断
func (r *Request) MustGetFormArray(name string) []string {
v, ok := r.GetFormArray(name)
if !ok {
panic(&internalPanic{
statusCode: http.StatusBadRequest,
rawError: errors.New("param name = " + name + " not set"),
})
}
return v
}

// GetFormMap 获取Form表单的值
func (r *Request) GetFormMap(name string) (map[string]string, bool) {
return r.ctx.GetPostFormMap(name)
}

// MustGetFormMap 获取Form表单的值
// 任何错误将触发Panic流程中断
func (r *Request) MustGetFormMap(name string) map[string]string {
v, ok := r.GetFormMap(name)
if !ok {
panic(&internalPanic{
statusCode: http.StatusBadRequest,
rawError: errors.New("param name = " + name + " not set"),
})
}
return v
}

// GetFormFile 获取上传文件内容
func (r *Request) GetFormFile(name string) (*multipart.FileHeader, error) {
return r.ctx.FormFile(name)
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ go 1.21.0
toolchain go1.21.5

require (
github.com/acexy/golang-toolkit v0.0.25
github.com/acexy/golang-toolkit v0.0.28
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.22.1
github.com/golang-acexy/starter-parent v0.1.7
github.com/golang-acexy/starter-parent v0.1.8
github.com/sirupsen/logrus v1.9.3
)

Expand All @@ -31,12 +31,12 @@ require (
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.10.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/arch v0.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/acexy/golang-toolkit v0.0.24 h1:fLVEivBt+nae1xoZfNQZxMTeltUdH+tDVk2Fc
github.com/acexy/golang-toolkit v0.0.24/go.mod h1:yHEqhUw8Lzeusv3C8+h5c5xu1l/tcbr70nm9Zd/tGXg=
github.com/acexy/golang-toolkit v0.0.25 h1:L+T/nmaFcqFx0H3Z5KT3Jw+1iPowUWLmCaqLEJK6drc=
github.com/acexy/golang-toolkit v0.0.25/go.mod h1:JjL+eGrRoyYuyjrFfFi1a3zqmAS4ZZsTBmt+cM21KS8=
github.com/acexy/golang-toolkit v0.0.28 h1:eFWlM6CCD4UI7nNN/2m36JxV7iP78I86fy6BbBEETts=
github.com/acexy/golang-toolkit v0.0.28/go.mod h1:taa7lJBcoobn4+HPdHi6Te2+y/JgiC8OYt5RPyiV+n4=
github.com/bytedance/sonic v1.12.2 h1:oaMFuRTpMHYLpCntGca65YWt5ny+wAceDERTkT2L9lg=
github.com/bytedance/sonic v1.12.2/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU=
Expand Down Expand Up @@ -36,6 +38,8 @@ github.com/golang-acexy/starter-parent v0.1.6 h1:TQMaxW8R5lyL6wAFdGha47gpdF3leLc
github.com/golang-acexy/starter-parent v0.1.6/go.mod h1:KbdDvY0RG6mxbtmGavseOGJivbXEhnHQ1zI33uCT/Mg=
github.com/golang-acexy/starter-parent v0.1.7 h1:H+ttnFP17KP1QvXj8xyCFNdoN5akr87MW08ic9bP2y8=
github.com/golang-acexy/starter-parent v0.1.7/go.mod h1:bcGL/E0WFN1qVe3zHRgiNQv4e3lEfceVq6mL0mtCs6s=
github.com/golang-acexy/starter-parent v0.1.8 h1:zelLyyxZoSHoMsaFLwvWJSaIHZcFqf0fje+jvcC2EaQ=
github.com/golang-acexy/starter-parent v0.1.8/go.mod h1:BokmPvxT4BkEKjN47qn0b981TzYbmD2HIpmfreTYN1w=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -76,21 +80,33 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8=
golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
Expand Down

0 comments on commit a4bba56

Please sign in to comment.