Skip to content

Commit

Permalink
add SetLocale from http context
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Nov 17, 2023
1 parent ad9ea11 commit 634ef17
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion contracts/http/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ type Context interface {
// Response returns the ContextResponse
Response() ContextResponse
// SetContext set the custom context
SetContext(ctx Context)
SetContext(ctx context.Context)
}
3 changes: 2 additions & 1 deletion foundation/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ func (app *Application) GetLocale(ctx context.Context) string {
}

func (app *Application) SetLocaleByHttp(ctx http.Context, locale string) {
app.MakeLang(ctx).SetLocale(locale)
ctxWithLocale := app.MakeLang(ctx).SetLocale(locale)
ctx.SetContext(ctxWithLocale)
}

func (app *Application) SetLocale(ctx context.Context, locale string) context.Context {
Expand Down
4 changes: 2 additions & 2 deletions http/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func (r *Context) Response() http.ContextResponse {
return nil
}

func (r *Context) SetContext(ctx http.Context) {
r.Ctx = ctx.Context()
func (r *Context) SetContext(ctx context.Context) {
r.Ctx = ctx
}
5 changes: 2 additions & 3 deletions http/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (s *ContextTestSuite) TestResponse() {
}

func (s *ContextTestSuite) TestSetContext() {
ctx := NewContext()
s.ctx.SetContext(ctx)
s.Equal(ctx.Context(), s.ctx.Context())
s.ctx.SetContext(context.Background())
s.Equal(context.Background(), s.ctx.Context())
}
2 changes: 1 addition & 1 deletion http/middleware/throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (r *TestContext) Response() contractshttp.ContextResponse {
return r.response
}

func (r *TestContext) SetContext(ctx contractshttp.Context) {
func (r *TestContext) SetContext(ctx context.Context) {
panic("do not need to implement it")
}

Expand Down

0 comments on commit 634ef17

Please sign in to comment.