Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed May 24, 2023
1 parent d3739d1 commit 95104d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion filesystem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"strings"
"time"

"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/filesystem"
supportfile "github.com/goravel/framework/support/file"
"github.com/goravel/framework/support/str"
)

type File struct {
config config.Config
disk string
path string
name string
Expand All @@ -29,6 +31,7 @@ func NewFile(file string) (*File, error) {
}

return &File{
config: ConfigFacade,
disk: ConfigFacade.GetString("filesystems.default"),
path: file,
name: path.Base(file),
Expand Down Expand Up @@ -56,6 +59,7 @@ func NewFileFromRequest(fileHeader *multipart.FileHeader) (*File, error) {
}

return &File{
config: ConfigFacade,
disk: ConfigFacade.GetString("filesystems.default"),
path: tempFile.Name(),
name: fileHeader.Filename,
Expand Down Expand Up @@ -100,7 +104,7 @@ func (f *File) HashName(path ...string) string {
}

func (f *File) LastModified() (time.Time, error) {
return supportfile.LastModified(f.path, facades.Config.GetString("app.timezone"))
return supportfile.LastModified(f.path, f.config.GetString("app.timezone"))
}

func (f *File) MimeType() (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion http/gin_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewGinContext(ctx *gin.Context) http.Context {
}

func (c *GinContext) Request() http.Request {
return NewGinRequest(c, ValidationFacade)
return NewGinRequest(c, LogFacade, ValidationFacade)
}

func (c *GinContext) Response() http.Response {
Expand Down
12 changes: 7 additions & 5 deletions http/gin_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

filesystemcontract "github.com/goravel/framework/contracts/filesystem"
httpcontract "github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/log"
validatecontract "github.com/goravel/framework/contracts/validation"
"github.com/goravel/framework/filesystem"
"github.com/goravel/framework/validation"
Expand All @@ -23,11 +24,12 @@ import (
type GinRequest struct {
ctx *GinContext
instance *gin.Context
log log.Log
validation validatecontract.Validation
}

func NewGinRequest(ctx *GinContext, validation validatecontract.Validation) httpcontract.Request {
return &GinRequest{ctx: ctx, instance: ctx.instance, validation: validation}
func NewGinRequest(ctx *GinContext, log log.Log, validation validatecontract.Validation) httpcontract.Request {
return &GinRequest{ctx: ctx, instance: ctx.instance, log: log, validation: validation}
}

func (r *GinRequest) AbortWithStatus(code int) {
Expand Down Expand Up @@ -55,22 +57,22 @@ func (r *GinRequest) All() map[string]any {
if contentType == "application/json" && r.instance.Request != nil && r.instance.Request.Body != nil {
bodyBytes, err := ioutil.ReadAll(r.instance.Request.Body)
if err != nil {
facades.Log.Errorf("when calling request all method, retrieve json error: %v", err)
r.log.Errorf("when calling request all method, retrieve json error: %v", err)
return nil
}

r.instance.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
if r.instance.Request.Body != nil {
if err := json.NewDecoder(r.instance.Request.Body).Decode(&postMap); err != nil {
facades.Log.Errorf("when calling request all method, decode json error: %v", err)
r.log.Errorf("when calling request all method, decode json error: %v", err)
return nil
}
}
r.instance.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
} else if contentType == "multipart/form-data" && r.instance.Request.ContentLength > 0 {
if r.instance.Request.PostForm == nil {
if err := r.instance.Request.ParseMultipartForm(defaultMemory); err != nil {
facades.Log.Errorf("when calling request all method, parse multipart form error: %v", err)
r.log.Errorf("when calling request all method, parse multipart form error: %v", err)
return nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions http/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
consolecontract "github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/foundation"
"github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/contracts/log"
"github.com/goravel/framework/contracts/validation"
"github.com/goravel/framework/http/console"
)
Expand All @@ -15,6 +16,7 @@ const Binding = "goravel.http"
var (
ConfigFacade config.Config
CacheFacade cache.Cache
LogFacade log.Log
RateLimiterFacade http.RateLimiter
ValidationFacade validation.Validation
)
Expand All @@ -25,6 +27,7 @@ type ServiceProvider struct {
func (database *ServiceProvider) Register(app foundation.Application) {
ConfigFacade = app.MakeConfig()
CacheFacade = app.MakeCache()
LogFacade = app.MakeLog()
ValidationFacade = app.MakeValidation()

app.Singleton(Binding, func() (any, error) {
Expand Down

0 comments on commit 95104d8

Please sign in to comment.