Reorganized directories and packages.
This commit is contained in:
parent
965fb540c7
commit
dceb232cb2
61 changed files with 83 additions and 83 deletions
25
pkg/context/context.go
Normal file
25
pkg/context/context.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const (
|
||||
// AuthenticatedUserKey is the key value used to store the authenticated user in context
|
||||
AuthenticatedUserKey = "auth_user"
|
||||
|
||||
// UserKey is the key value used to store a user in context
|
||||
UserKey = "user"
|
||||
|
||||
// FormKey is the key value used to store a form in context
|
||||
FormKey = "form"
|
||||
|
||||
// PasswordTokenKey is the key value used to store a password token in context
|
||||
PasswordTokenKey = "password_token"
|
||||
)
|
||||
|
||||
// IsCanceledError determines if an error is due to a context cancelation
|
||||
func IsCanceledError(err error) bool {
|
||||
return errors.Is(err, context.Canceled)
|
||||
}
|
||||
24
pkg/context/context_test.go
Normal file
24
pkg/context/context_test.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsCanceled(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
assert.False(t, IsCanceledError(ctx.Err()))
|
||||
cancel()
|
||||
assert.True(t, IsCanceledError(ctx.Err()))
|
||||
|
||||
ctx, cancel = context.WithTimeout(context.Background(), time.Microsecond)
|
||||
time.Sleep(time.Microsecond * 5)
|
||||
cancel()
|
||||
assert.False(t, IsCanceledError(ctx.Err()))
|
||||
|
||||
assert.False(t, IsCanceledError(errors.New("test error")))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue