feat: update templates

This commit is contained in:
Rogee
2024-12-21 00:17:48 +08:00
parent 94553081c9
commit 58450dd63d
9 changed files with 44 additions and 245 deletions

View File

@@ -0,0 +1,31 @@
package requests
type Pager struct {
Pagination `json:",inline"`
Total int64 `json:"total"`
Items interface{} `json:"items"`
}
type Pagination struct {
Page int `json:"page" form:"page"`
Limit int `json:"limit" form:"limit"`
}
func (filter *PageQueryFilter) Offset() int {
return (filter.Page - 1) * filter.Limit
}
func (filter *PageQueryFilter) Format() *PageQueryFilter {
if filter.Page <= 0 {
filter.Page = 1
}
if filter.Limit <= 0 {
filter.Limit = 10
}
if filter.Limit > 50 {
filter.Limit = 50
}
return filter
}

View File

@@ -1,4 +1,4 @@
package pkg
package requests
import (
"strings"
@@ -39,33 +39,3 @@ func (s *SortQueryFilter) DescID() *SortQueryFilter {
s.Desc = lo.ToPtr(strings.Join(items, ","))
return s
}
type PageDataResponse struct {
PageQueryFilter `json:",inline"`
Total int64 `json:"total"`
Items interface{} `json:"items"`
}
type PageQueryFilter struct {
Page int `json:"page" form:"page"`
Limit int `json:"limit" form:"limit"`
}
func (filter *PageQueryFilter) Offset() int {
return (filter.Page - 1) * filter.Limit
}
func (filter *PageQueryFilter) Format() *PageQueryFilter {
if filter.Page <= 0 {
filter.Page = 1
}
if filter.Limit <= 0 {
filter.Limit = 10
}
if filter.Limit > 50 {
filter.Limit = 50
}
return filter
}

View File

@@ -1,7 +1 @@
package main
import (
"testing"
"git.ipao.vip/rogeecn/atom"
)

View File

@@ -1,179 +0,0 @@
// Code generated by go-enum DO NOT EDIT.
// Version: -
// Revision: -
// Build Date: -
// Built By: -
package consts
import (
"database/sql/driver"
"errors"
"fmt"
"strings"
)
const (
// CtxKeyTx is a CtxKey of type Tx.
CtxKeyTx CtxKey = "__ctx_db:"
// CtxKeyJwt is a CtxKey of type Jwt.
CtxKeyJwt CtxKey = "__jwt_token:"
// CtxKeyClaim is a CtxKey of type Claim.
CtxKeyClaim CtxKey = "__jwt_claim:"
)
var ErrInvalidCtxKey = fmt.Errorf("not a valid CtxKey, try [%s]", strings.Join(_CtxKeyNames, ", "))
var _CtxKeyNames = []string{
string(CtxKeyTx),
string(CtxKeyJwt),
string(CtxKeyClaim),
}
// CtxKeyNames returns a list of possible string values of CtxKey.
func CtxKeyNames() []string {
tmp := make([]string, len(_CtxKeyNames))
copy(tmp, _CtxKeyNames)
return tmp
}
// CtxKeyValues returns a list of the values for CtxKey
func CtxKeyValues() []CtxKey {
return []CtxKey{
CtxKeyTx,
CtxKeyJwt,
CtxKeyClaim,
}
}
// String implements the Stringer interface.
func (x CtxKey) String() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x CtxKey) IsValid() bool {
_, err := ParseCtxKey(string(x))
return err == nil
}
var _CtxKeyValue = map[string]CtxKey{
"__ctx_db:": CtxKeyTx,
"__jwt_token:": CtxKeyJwt,
"__jwt_claim:": CtxKeyClaim,
}
// ParseCtxKey attempts to convert a string to a CtxKey.
func ParseCtxKey(name string) (CtxKey, error) {
if x, ok := _CtxKeyValue[name]; ok {
return x, nil
}
return CtxKey(""), fmt.Errorf("%s is %w", name, ErrInvalidCtxKey)
}
var errCtxKeyNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *CtxKey) Scan(value interface{}) (err error) {
if value == nil {
*x = CtxKey("")
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case string:
*x, err = ParseCtxKey(v)
case []byte:
*x, err = ParseCtxKey(string(v))
case CtxKey:
*x = v
case *CtxKey:
if v == nil {
return errCtxKeyNilPtr
}
*x = *v
case *string:
if v == nil {
return errCtxKeyNilPtr
}
*x, err = ParseCtxKey(*v)
default:
return errors.New("invalid type for CtxKey")
}
return
}
// Value implements the driver Valuer interface.
func (x CtxKey) Value() (driver.Value, error) {
return x.String(), nil
}
// Set implements the Golang flag.Value interface func.
func (x *CtxKey) Set(val string) error {
v, err := ParseCtxKey(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *CtxKey) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *CtxKey) Type() string {
return "CtxKey"
}
type NullCtxKey struct {
CtxKey CtxKey
Valid bool
}
func NewNullCtxKey(val interface{}) (x NullCtxKey) {
err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
_ = err // make any errcheck linters happy
return
}
// Scan implements the Scanner interface.
func (x *NullCtxKey) Scan(value interface{}) (err error) {
if value == nil {
x.CtxKey, x.Valid = CtxKey(""), false
return
}
err = x.CtxKey.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullCtxKey) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return string(x.CtxKey), nil
}
type NullCtxKeyStr struct {
NullCtxKey
}
func NewNullCtxKeyStr(val interface{}) (x NullCtxKeyStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullCtxKeyStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.CtxKey.String(), nil
}

View File

@@ -1,9 +0,0 @@
package consts
// swagger:enum CacheKey
// ENUM(
// Tx = "__ctx_db:",
// Jwt = "__jwt_token:",
// Claim = "__jwt_claim:",
// )
type CtxKey string

View File

@@ -1,13 +0,0 @@
package pkg
func WrapLike(v string) string {
return "%" + v + "%"
}
func WrapLikeLeft(v string) string {
return "%" + v
}
func WrapLikeRight(v string) string {
return "%" + v
}

View File

@@ -1,7 +0,0 @@
package db
type Pagination struct {
Offset string `json:"offset,omitempty"`
OffsetID int64 `json:"-"`
Action int `json:"action"` // action: 0 : 1:
}

View File

@@ -26,3 +26,15 @@ func TruncateAllTables(ctx context.Context, db *sql.DB, tableName ...string) err
}
return nil
}
func WrapLike(v string) string {
return "%" + v + "%"
}
func WrapLikeLeft(v string) string {
return "%" + v
}
func WrapLikeRight(v string) string {
return "%" + v
}