2017-09-26 12:50:09 +00:00
|
|
|
package misc
|
|
|
|
|
2022-01-06 08:54:14 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/cuigh/auxo/errors"
|
|
|
|
)
|
2017-09-26 12:50:09 +00:00
|
|
|
|
|
|
|
const (
|
2021-12-06 12:24:22 +00:00
|
|
|
ErrInvalidToken = 1001
|
|
|
|
ErrAccountDisabled = 1002
|
|
|
|
ErrOldPasswordIncorrect = 1003
|
|
|
|
ErrExternalStack = 1004
|
2021-12-16 12:23:08 +00:00
|
|
|
ErrSystemInitialized = 1005
|
2017-09-26 12:50:09 +00:00
|
|
|
)
|
|
|
|
|
2021-12-06 12:24:22 +00:00
|
|
|
func Error(code int32, err error) error {
|
|
|
|
return errors.Coded(code, err.Error())
|
2018-03-20 05:07:19 +00:00
|
|
|
}
|
2017-09-26 12:50:09 +00:00
|
|
|
|
2021-12-06 12:24:22 +00:00
|
|
|
func Page(count, pageIndex, pageSize int) (start, end int) {
|
|
|
|
start = pageSize * (pageIndex - 1)
|
|
|
|
end = pageSize * pageIndex
|
|
|
|
if count < start {
|
|
|
|
start, end = 0, 0
|
|
|
|
} else if count < end {
|
|
|
|
end = count
|
|
|
|
}
|
|
|
|
return
|
2017-09-26 12:50:09 +00:00
|
|
|
}
|
2022-01-06 08:54:14 +00:00
|
|
|
|
|
|
|
func Context(timeout time.Duration) (context.Context, context.CancelFunc) {
|
|
|
|
return context.WithTimeout(context.Background(), timeout)
|
|
|
|
}
|