Skip to content

Commit

Permalink
ctx updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yahya077 authored and yahya.hindioglu committed Mar 14, 2024
1 parent 93dee03 commit 89646e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
46 changes: 6 additions & 40 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
)

type Context struct {
ctx context.Context
cancel context.CancelFunc
Ctx context.Context
Cancel context.CancelFunc
}

type IContextBuilder interface {
Expand All @@ -22,16 +22,16 @@ type ContextBuilder struct {
func (b ContextBuilder) Build() Context {
if b.Timeout() == 0 {
return Context{
ctx: context.Background(),
cancel: nil,
Ctx: context.Background(),
Cancel: nil,
}
}

ctx, cancel := context.WithTimeout(context.Background(), b.Timeout())

return Context{
ctx: ctx,
cancel: cancel,
Ctx: ctx,
Cancel: cancel,
}
}

Expand All @@ -42,37 +42,3 @@ func (b ContextBuilder) Timeout() time.Duration {
func NewContextBuilder(timeout time.Duration) ContextBuilder {
return ContextBuilder{timeout}
}

/*
// If you want to use this, you need to add a dependency to the transaction package in the go.mod file. (eq. newrelic, opentracing, etc.)
type ContextWithTransaction struct {
txn *Transaction
}
func (b ContextWithTransaction) Build() (context.Context, context.CancelFunc) {
return NewContext(context.Background(), txn), nil
}
*/

//Example: NewRelicContextBuilder
/*
type NewRelicContextBuilder struct {
txn *newrelic.Transaction
}
func (b NewRelicContextBuilder) Build() (context.Context, context.CancelFunc) {
ctx, cancel := context.WithTimeout(context.Background(), b.Timeout())
return newrelic.NewContext(ctx, b.txn), cancel
}
func (b NewRelicContextBuilder) Timeout() time.Duration {
return time.Second * 15
}
func NewContextBuilder(txn *newrelic.Transaction) room.IContextBuilder {
return NewRelicContextBuilder{txn}
}
*/
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *Request) request() *http.Request {
r.uri = NewURI(r.path)
}

req, _ := http.NewRequestWithContext(context.ctx, r.method.String(), r.uri.String(), r.BodyParser.Parse())
req, _ := http.NewRequestWithContext(context.Ctx, r.method.String(), r.uri.String(), r.BodyParser.Parse())

if r.Header != nil {
r.Header.Properties().Each(func(k string, v any) {
Expand Down

0 comments on commit 89646e8

Please sign in to comment.