feat: migrate serevices
Some checks failed
build quyun / Build (push) Failing after 2m50s

This commit is contained in:
2025-12-19 19:05:12 +08:00
parent 005585c53b
commit 557a641f41
71 changed files with 5626 additions and 280 deletions

View File

@@ -0,0 +1,7 @@
package fields
type MediaMetas struct {
ParentHash string `json:"parent_hash,omitempty"`
Short bool `json:"short,omitempty"`
Duration int64 `json:"duration,omitempty"`
}

View File

@@ -0,0 +1,271 @@
// Code generated by go-enum DO NOT EDIT.
// Version: -
// Revision: -
// Build Date: -
// Built By: -
package fields
import (
"database/sql/driver"
"errors"
"fmt"
"strconv"
"strings"
)
const (
// OrderStatusPending is a OrderStatus of type Pending.
OrderStatusPending OrderStatus = iota
// OrderStatusPaid is a OrderStatus of type Paid.
OrderStatusPaid
// OrderStatusRefundSuccess is a OrderStatus of type Refund_success.
OrderStatusRefundSuccess
// OrderStatusRefundClosed is a OrderStatus of type Refund_closed.
OrderStatusRefundClosed
// OrderStatusRefundProcessing is a OrderStatus of type Refund_processing.
OrderStatusRefundProcessing
// OrderStatusRefundAbnormal is a OrderStatus of type Refund_abnormal.
OrderStatusRefundAbnormal
// OrderStatusCancelled is a OrderStatus of type Cancelled.
OrderStatusCancelled
// OrderStatusCompleted is a OrderStatus of type Completed.
OrderStatusCompleted
)
var ErrInvalidOrderStatus = fmt.Errorf("not a valid OrderStatus, try [%s]", strings.Join(_OrderStatusNames, ", "))
const _OrderStatusName = "pendingpaidrefund_successrefund_closedrefund_processingrefund_abnormalcancelledcompleted"
var _OrderStatusNames = []string{
_OrderStatusName[0:7],
_OrderStatusName[7:11],
_OrderStatusName[11:25],
_OrderStatusName[25:38],
_OrderStatusName[38:55],
_OrderStatusName[55:70],
_OrderStatusName[70:79],
_OrderStatusName[79:88],
}
// OrderStatusNames returns a list of possible string values of OrderStatus.
func OrderStatusNames() []string {
tmp := make([]string, len(_OrderStatusNames))
copy(tmp, _OrderStatusNames)
return tmp
}
// OrderStatusValues returns a list of the values for OrderStatus
func OrderStatusValues() []OrderStatus {
return []OrderStatus{
OrderStatusPending,
OrderStatusPaid,
OrderStatusRefundSuccess,
OrderStatusRefundClosed,
OrderStatusRefundProcessing,
OrderStatusRefundAbnormal,
OrderStatusCancelled,
OrderStatusCompleted,
}
}
var _OrderStatusMap = map[OrderStatus]string{
OrderStatusPending: _OrderStatusName[0:7],
OrderStatusPaid: _OrderStatusName[7:11],
OrderStatusRefundSuccess: _OrderStatusName[11:25],
OrderStatusRefundClosed: _OrderStatusName[25:38],
OrderStatusRefundProcessing: _OrderStatusName[38:55],
OrderStatusRefundAbnormal: _OrderStatusName[55:70],
OrderStatusCancelled: _OrderStatusName[70:79],
OrderStatusCompleted: _OrderStatusName[79:88],
}
// String implements the Stringer interface.
func (x OrderStatus) String() string {
if str, ok := _OrderStatusMap[x]; ok {
return str
}
return fmt.Sprintf("OrderStatus(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x OrderStatus) IsValid() bool {
_, ok := _OrderStatusMap[x]
return ok
}
var _OrderStatusValue = map[string]OrderStatus{
_OrderStatusName[0:7]: OrderStatusPending,
_OrderStatusName[7:11]: OrderStatusPaid,
_OrderStatusName[11:25]: OrderStatusRefundSuccess,
_OrderStatusName[25:38]: OrderStatusRefundClosed,
_OrderStatusName[38:55]: OrderStatusRefundProcessing,
_OrderStatusName[55:70]: OrderStatusRefundAbnormal,
_OrderStatusName[70:79]: OrderStatusCancelled,
_OrderStatusName[79:88]: OrderStatusCompleted,
}
// ParseOrderStatus attempts to convert a string to a OrderStatus.
func ParseOrderStatus(name string) (OrderStatus, error) {
if x, ok := _OrderStatusValue[name]; ok {
return x, nil
}
return OrderStatus(0), fmt.Errorf("%s is %w", name, ErrInvalidOrderStatus)
}
var errOrderStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *OrderStatus) Scan(value interface{}) (err error) {
if value == nil {
*x = OrderStatus(0)
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case int64:
*x = OrderStatus(v)
case string:
*x, err = ParseOrderStatus(v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(v); verr == nil {
*x, err = OrderStatus(val), nil
}
}
case []byte:
*x, err = ParseOrderStatus(string(v))
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(string(v)); verr == nil {
*x, err = OrderStatus(val), nil
}
}
case OrderStatus:
*x = v
case int:
*x = OrderStatus(v)
case *OrderStatus:
if v == nil {
return errOrderStatusNilPtr
}
*x = *v
case uint:
*x = OrderStatus(v)
case uint64:
*x = OrderStatus(v)
case *int:
if v == nil {
return errOrderStatusNilPtr
}
*x = OrderStatus(*v)
case *int64:
if v == nil {
return errOrderStatusNilPtr
}
*x = OrderStatus(*v)
case float64: // json marshals everything as a float64 if it's a number
*x = OrderStatus(v)
case *float64: // json marshals everything as a float64 if it's a number
if v == nil {
return errOrderStatusNilPtr
}
*x = OrderStatus(*v)
case *uint:
if v == nil {
return errOrderStatusNilPtr
}
*x = OrderStatus(*v)
case *uint64:
if v == nil {
return errOrderStatusNilPtr
}
*x = OrderStatus(*v)
case *string:
if v == nil {
return errOrderStatusNilPtr
}
*x, err = ParseOrderStatus(*v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(*v); verr == nil {
*x, err = OrderStatus(val), nil
}
}
}
return
}
// Value implements the driver Valuer interface.
func (x OrderStatus) Value() (driver.Value, error) {
return int64(x), nil
}
// Set implements the Golang flag.Value interface func.
func (x *OrderStatus) Set(val string) error {
v, err := ParseOrderStatus(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *OrderStatus) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *OrderStatus) Type() string {
return "OrderStatus"
}
type NullOrderStatus struct {
OrderStatus OrderStatus
Valid bool
}
func NewNullOrderStatus(val interface{}) (x NullOrderStatus) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Scan implements the Scanner interface.
func (x *NullOrderStatus) Scan(value interface{}) (err error) {
if value == nil {
x.OrderStatus, x.Valid = OrderStatus(0), false
return
}
err = x.OrderStatus.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullOrderStatus) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return int64(x.OrderStatus), nil
}
type NullOrderStatusStr struct {
NullOrderStatus
}
func NewNullOrderStatusStr(val interface{}) (x NullOrderStatusStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullOrderStatusStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.OrderStatus.String(), nil
}

View File

@@ -0,0 +1,16 @@
package fields
import (
"github.com/go-pay/gopay/wechat/v3"
)
// swagger:enum OrderStatus
// ENUM( pending, paid, refund_success, refund_closed, refund_processing, refund_abnormal, cancelled, completed)
type OrderStatus int16
type OrderMeta struct {
PayNotify *wechat.V3DecryptPayResult `json:"pay_notify"`
RefundResp *wechat.RefundOrderResponse `json:"refund_resp"`
RefundNotify *wechat.V3DecryptRefundResult `json:"refund_notify"`
CostBalance int64 `json:"cost_balance"` // 余额支付的金额
}

View File

@@ -0,0 +1,467 @@
// Code generated by go-enum DO NOT EDIT.
// Version: -
// Revision: -
// Build Date: -
// Built By: -
package fields
import (
"database/sql/driver"
"errors"
"fmt"
"strconv"
"strings"
)
const (
// PostStatusDraft is a PostStatus of type Draft.
PostStatusDraft PostStatus = iota
// PostStatusPublished is a PostStatus of type Published.
PostStatusPublished
)
var ErrInvalidPostStatus = fmt.Errorf("not a valid PostStatus, try [%s]", strings.Join(_PostStatusNames, ", "))
const _PostStatusName = "draftpublished"
var _PostStatusNames = []string{
_PostStatusName[0:5],
_PostStatusName[5:14],
}
// PostStatusNames returns a list of possible string values of PostStatus.
func PostStatusNames() []string {
tmp := make([]string, len(_PostStatusNames))
copy(tmp, _PostStatusNames)
return tmp
}
// PostStatusValues returns a list of the values for PostStatus
func PostStatusValues() []PostStatus {
return []PostStatus{
PostStatusDraft,
PostStatusPublished,
}
}
var _PostStatusMap = map[PostStatus]string{
PostStatusDraft: _PostStatusName[0:5],
PostStatusPublished: _PostStatusName[5:14],
}
// String implements the Stringer interface.
func (x PostStatus) String() string {
if str, ok := _PostStatusMap[x]; ok {
return str
}
return fmt.Sprintf("PostStatus(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x PostStatus) IsValid() bool {
_, ok := _PostStatusMap[x]
return ok
}
var _PostStatusValue = map[string]PostStatus{
_PostStatusName[0:5]: PostStatusDraft,
_PostStatusName[5:14]: PostStatusPublished,
}
// ParsePostStatus attempts to convert a string to a PostStatus.
func ParsePostStatus(name string) (PostStatus, error) {
if x, ok := _PostStatusValue[name]; ok {
return x, nil
}
return PostStatus(0), fmt.Errorf("%s is %w", name, ErrInvalidPostStatus)
}
var errPostStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *PostStatus) Scan(value interface{}) (err error) {
if value == nil {
*x = PostStatus(0)
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case int64:
*x = PostStatus(v)
case string:
*x, err = ParsePostStatus(v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(v); verr == nil {
*x, err = PostStatus(val), nil
}
}
case []byte:
*x, err = ParsePostStatus(string(v))
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(string(v)); verr == nil {
*x, err = PostStatus(val), nil
}
}
case PostStatus:
*x = v
case int:
*x = PostStatus(v)
case *PostStatus:
if v == nil {
return errPostStatusNilPtr
}
*x = *v
case uint:
*x = PostStatus(v)
case uint64:
*x = PostStatus(v)
case *int:
if v == nil {
return errPostStatusNilPtr
}
*x = PostStatus(*v)
case *int64:
if v == nil {
return errPostStatusNilPtr
}
*x = PostStatus(*v)
case float64: // json marshals everything as a float64 if it's a number
*x = PostStatus(v)
case *float64: // json marshals everything as a float64 if it's a number
if v == nil {
return errPostStatusNilPtr
}
*x = PostStatus(*v)
case *uint:
if v == nil {
return errPostStatusNilPtr
}
*x = PostStatus(*v)
case *uint64:
if v == nil {
return errPostStatusNilPtr
}
*x = PostStatus(*v)
case *string:
if v == nil {
return errPostStatusNilPtr
}
*x, err = ParsePostStatus(*v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(*v); verr == nil {
*x, err = PostStatus(val), nil
}
}
}
return
}
// Value implements the driver Valuer interface.
func (x PostStatus) Value() (driver.Value, error) {
return int64(x), nil
}
// Set implements the Golang flag.Value interface func.
func (x *PostStatus) Set(val string) error {
v, err := ParsePostStatus(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *PostStatus) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *PostStatus) Type() string {
return "PostStatus"
}
type NullPostStatus struct {
PostStatus PostStatus
Valid bool
}
func NewNullPostStatus(val interface{}) (x NullPostStatus) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Scan implements the Scanner interface.
func (x *NullPostStatus) Scan(value interface{}) (err error) {
if value == nil {
x.PostStatus, x.Valid = PostStatus(0), false
return
}
err = x.PostStatus.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullPostStatus) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return int64(x.PostStatus), nil
}
type NullPostStatusStr struct {
NullPostStatus
}
func NewNullPostStatusStr(val interface{}) (x NullPostStatusStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullPostStatusStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.PostStatus.String(), nil
}
const (
// PostTypeArticle is a PostType of type Article.
PostTypeArticle PostType = iota
// PostTypePicture is a PostType of type Picture.
PostTypePicture
// PostTypeVideo is a PostType of type Video.
PostTypeVideo
// PostTypeAudio is a PostType of type Audio.
PostTypeAudio
)
var ErrInvalidPostType = fmt.Errorf("not a valid PostType, try [%s]", strings.Join(_PostTypeNames, ", "))
const _PostTypeName = "ArticlePictureVideoAudio"
var _PostTypeNames = []string{
_PostTypeName[0:7],
_PostTypeName[7:14],
_PostTypeName[14:19],
_PostTypeName[19:24],
}
// PostTypeNames returns a list of possible string values of PostType.
func PostTypeNames() []string {
tmp := make([]string, len(_PostTypeNames))
copy(tmp, _PostTypeNames)
return tmp
}
// PostTypeValues returns a list of the values for PostType
func PostTypeValues() []PostType {
return []PostType{
PostTypeArticle,
PostTypePicture,
PostTypeVideo,
PostTypeAudio,
}
}
var _PostTypeMap = map[PostType]string{
PostTypeArticle: _PostTypeName[0:7],
PostTypePicture: _PostTypeName[7:14],
PostTypeVideo: _PostTypeName[14:19],
PostTypeAudio: _PostTypeName[19:24],
}
// String implements the Stringer interface.
func (x PostType) String() string {
if str, ok := _PostTypeMap[x]; ok {
return str
}
return fmt.Sprintf("PostType(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x PostType) IsValid() bool {
_, ok := _PostTypeMap[x]
return ok
}
var _PostTypeValue = map[string]PostType{
_PostTypeName[0:7]: PostTypeArticle,
_PostTypeName[7:14]: PostTypePicture,
_PostTypeName[14:19]: PostTypeVideo,
_PostTypeName[19:24]: PostTypeAudio,
}
// ParsePostType attempts to convert a string to a PostType.
func ParsePostType(name string) (PostType, error) {
if x, ok := _PostTypeValue[name]; ok {
return x, nil
}
return PostType(0), fmt.Errorf("%s is %w", name, ErrInvalidPostType)
}
var errPostTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *PostType) Scan(value interface{}) (err error) {
if value == nil {
*x = PostType(0)
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case int64:
*x = PostType(v)
case string:
*x, err = ParsePostType(v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(v); verr == nil {
*x, err = PostType(val), nil
}
}
case []byte:
*x, err = ParsePostType(string(v))
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(string(v)); verr == nil {
*x, err = PostType(val), nil
}
}
case PostType:
*x = v
case int:
*x = PostType(v)
case *PostType:
if v == nil {
return errPostTypeNilPtr
}
*x = *v
case uint:
*x = PostType(v)
case uint64:
*x = PostType(v)
case *int:
if v == nil {
return errPostTypeNilPtr
}
*x = PostType(*v)
case *int64:
if v == nil {
return errPostTypeNilPtr
}
*x = PostType(*v)
case float64: // json marshals everything as a float64 if it's a number
*x = PostType(v)
case *float64: // json marshals everything as a float64 if it's a number
if v == nil {
return errPostTypeNilPtr
}
*x = PostType(*v)
case *uint:
if v == nil {
return errPostTypeNilPtr
}
*x = PostType(*v)
case *uint64:
if v == nil {
return errPostTypeNilPtr
}
*x = PostType(*v)
case *string:
if v == nil {
return errPostTypeNilPtr
}
*x, err = ParsePostType(*v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(*v); verr == nil {
*x, err = PostType(val), nil
}
}
}
return
}
// Value implements the driver Valuer interface.
func (x PostType) Value() (driver.Value, error) {
return int64(x), nil
}
// Set implements the Golang flag.Value interface func.
func (x *PostType) Set(val string) error {
v, err := ParsePostType(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *PostType) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *PostType) Type() string {
return "PostType"
}
type NullPostType struct {
PostType PostType
Valid bool
}
func NewNullPostType(val interface{}) (x NullPostType) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Scan implements the Scanner interface.
func (x *NullPostType) Scan(value interface{}) (err error) {
if value == nil {
x.PostType, x.Valid = PostType(0), false
return
}
err = x.PostType.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullPostType) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return int64(x.PostType), nil
}
type NullPostTypeStr struct {
NullPostType
}
func NewNullPostTypeStr(val interface{}) (x NullPostTypeStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullPostTypeStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.PostType.String(), nil
}

View File

@@ -0,0 +1,16 @@
package fields
type MediaAsset struct {
Type string `json:"type"`
Media int64 `json:"media"`
Metas *MediaMetas `json:"metas,omitempty"`
Mark *string `json:"mark,omitempty"`
}
// swagger:enum PostStatus
// ENUM( draft, published )
type PostStatus int16
// swagger:enum PostType
// ENUM( Article, Picture, Video, Audio)
type PostType int16

View File

@@ -0,0 +1,241 @@
// Code generated by go-enum DO NOT EDIT.
// Version: -
// Revision: -
// Build Date: -
// Built By: -
package fields
import (
"database/sql/driver"
"errors"
"fmt"
"strconv"
"strings"
)
const (
// UserStatusOk is a UserStatus of type Ok.
UserStatusOk UserStatus = iota
// UserStatusBanned is a UserStatus of type Banned.
UserStatusBanned
// UserStatusBlocked is a UserStatus of type Blocked.
UserStatusBlocked
)
var ErrInvalidUserStatus = fmt.Errorf("not a valid UserStatus, try [%s]", strings.Join(_UserStatusNames, ", "))
const _UserStatusName = "okbannedblocked"
var _UserStatusNames = []string{
_UserStatusName[0:2],
_UserStatusName[2:8],
_UserStatusName[8:15],
}
// UserStatusNames returns a list of possible string values of UserStatus.
func UserStatusNames() []string {
tmp := make([]string, len(_UserStatusNames))
copy(tmp, _UserStatusNames)
return tmp
}
// UserStatusValues returns a list of the values for UserStatus
func UserStatusValues() []UserStatus {
return []UserStatus{
UserStatusOk,
UserStatusBanned,
UserStatusBlocked,
}
}
var _UserStatusMap = map[UserStatus]string{
UserStatusOk: _UserStatusName[0:2],
UserStatusBanned: _UserStatusName[2:8],
UserStatusBlocked: _UserStatusName[8:15],
}
// String implements the Stringer interface.
func (x UserStatus) String() string {
if str, ok := _UserStatusMap[x]; ok {
return str
}
return fmt.Sprintf("UserStatus(%d)", x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x UserStatus) IsValid() bool {
_, ok := _UserStatusMap[x]
return ok
}
var _UserStatusValue = map[string]UserStatus{
_UserStatusName[0:2]: UserStatusOk,
_UserStatusName[2:8]: UserStatusBanned,
_UserStatusName[8:15]: UserStatusBlocked,
}
// ParseUserStatus attempts to convert a string to a UserStatus.
func ParseUserStatus(name string) (UserStatus, error) {
if x, ok := _UserStatusValue[name]; ok {
return x, nil
}
return UserStatus(0), fmt.Errorf("%s is %w", name, ErrInvalidUserStatus)
}
var errUserStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes
// Scan implements the Scanner interface.
func (x *UserStatus) Scan(value interface{}) (err error) {
if value == nil {
*x = UserStatus(0)
return
}
// A wider range of scannable types.
// driver.Value values at the top of the list for expediency
switch v := value.(type) {
case int64:
*x = UserStatus(v)
case string:
*x, err = ParseUserStatus(v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(v); verr == nil {
*x, err = UserStatus(val), nil
}
}
case []byte:
*x, err = ParseUserStatus(string(v))
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(string(v)); verr == nil {
*x, err = UserStatus(val), nil
}
}
case UserStatus:
*x = v
case int:
*x = UserStatus(v)
case *UserStatus:
if v == nil {
return errUserStatusNilPtr
}
*x = *v
case uint:
*x = UserStatus(v)
case uint64:
*x = UserStatus(v)
case *int:
if v == nil {
return errUserStatusNilPtr
}
*x = UserStatus(*v)
case *int64:
if v == nil {
return errUserStatusNilPtr
}
*x = UserStatus(*v)
case float64: // json marshals everything as a float64 if it's a number
*x = UserStatus(v)
case *float64: // json marshals everything as a float64 if it's a number
if v == nil {
return errUserStatusNilPtr
}
*x = UserStatus(*v)
case *uint:
if v == nil {
return errUserStatusNilPtr
}
*x = UserStatus(*v)
case *uint64:
if v == nil {
return errUserStatusNilPtr
}
*x = UserStatus(*v)
case *string:
if v == nil {
return errUserStatusNilPtr
}
*x, err = ParseUserStatus(*v)
if err != nil {
// try parsing the integer value as a string
if val, verr := strconv.Atoi(*v); verr == nil {
*x, err = UserStatus(val), nil
}
}
}
return
}
// Value implements the driver Valuer interface.
func (x UserStatus) Value() (driver.Value, error) {
return int64(x), nil
}
// Set implements the Golang flag.Value interface func.
func (x *UserStatus) Set(val string) error {
v, err := ParseUserStatus(val)
*x = v
return err
}
// Get implements the Golang flag.Getter interface func.
func (x *UserStatus) Get() interface{} {
return *x
}
// Type implements the github.com/spf13/pFlag Value interface.
func (x *UserStatus) Type() string {
return "UserStatus"
}
type NullUserStatus struct {
UserStatus UserStatus
Valid bool
}
func NewNullUserStatus(val interface{}) (x NullUserStatus) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Scan implements the Scanner interface.
func (x *NullUserStatus) Scan(value interface{}) (err error) {
if value == nil {
x.UserStatus, x.Valid = UserStatus(0), false
return
}
err = x.UserStatus.Scan(value)
x.Valid = (err == nil)
return
}
// Value implements the driver Valuer interface.
func (x NullUserStatus) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
// driver.Value accepts int64 for int values.
return int64(x.UserStatus), nil
}
type NullUserStatusStr struct {
NullUserStatus
}
func NewNullUserStatusStr(val interface{}) (x NullUserStatusStr) {
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
return
}
// Value implements the driver Valuer interface.
func (x NullUserStatusStr) Value() (driver.Value, error) {
if !x.Valid {
return nil, nil
}
return x.UserStatus.String(), nil
}

View File

@@ -0,0 +1,27 @@
package fields
import "time"
// swagger:enum PostStatus
// ENUM( ok, banned, blocked)
type UserStatus int16
type UserMetas struct {
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
HeadImageUrl string `json:"head_image_url,omitempty"`
Nickname string `json:"nickname,omitempty"`
Privilege []string `json:"privilege,omitempty"`
Province string `json:"province,omitempty"`
Sex int64 `json:"sex,omitempty"`
}
type UserAuthToken struct {
StableAccessToken string `json:"stable_access_token,omitempty"`
StableExpiresAt time.Time `json:"stable_expires_at,omitempty"`
AccessToken string `json:"access_token,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
IsSnapshotuser int64 `json:"is_snapshotuser,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Scope string `json:"scope,omitempty"`
}

View File

@@ -0,0 +1,12 @@
package oauth
import "time"
type OAuthInfo interface {
GetOpenID() string
GetUnionID() string
GetAccessToken() string
GetRefreshToken() string
GetExpiredAt() time.Time
}

View File

@@ -0,0 +1,40 @@
package oauth
import "time"
var _ OAuthInfo = (*WechatOAuthInfo)(nil)
type WechatOAuthInfo struct {
Scope string `json:"scope,omitempty"`
OpenID string `json:"openid,omitempty"`
UnionID string `json:"unionid,omitempty"`
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int64 `json:"expires_in,omitempty"`
}
// GetAccessToken implements OAuthInfo.
func (w *WechatOAuthInfo) GetAccessToken() string {
return w.AccessToken
}
// GetExpiredAt implements OAuthInfo.
func (w *WechatOAuthInfo) GetExpiredAt() time.Time {
return time.Now().Add(time.Duration(w.ExpiresIn) * time.Second)
}
// GetOpenID implements OAuthInfo.
func (w *WechatOAuthInfo) GetOpenID() string {
return w.OpenID
}
// GetRefreshToken implements OAuthInfo.
func (w *WechatOAuthInfo) GetRefreshToken() string {
return w.RefreshToken
}
// GetUnionID implements OAuthInfo.
func (w *WechatOAuthInfo) GetUnionID() string {
return w.UnionID
}

View File

@@ -0,0 +1,69 @@
package utils
import (
"bufio"
"context"
"os/exec"
"github.com/go-pay/errgroup"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
// ExecCommand executes a command and streams its output in real-time
func ExecCommand(name string, args ...string) error {
log.Infof("Executing command: %s %v", name, args)
cmd := exec.Command(name, args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return errors.Wrap(err, "stdout pipe error")
}
stderr, err := cmd.StderrPipe()
if err != nil {
return errors.Wrap(err, "stderr pipe error")
}
if err := cmd.Start(); err != nil {
return errors.Wrap(err, "command start error")
}
var eg errgroup.Group
eg.Go(func(ctx context.Context) error {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
log.Info(scanner.Text())
}
return nil
})
eg.Go(func(ctx context.Context) error {
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
log.Error(scanner.Text())
}
return nil
})
if err := cmd.Wait(); err != nil {
return errors.Wrap(err, "command wait error")
}
if err := eg.Wait(); err != nil {
return errors.Wrap(err, "command wait error")
}
return nil
}
// ExecCommandOutput executes a command and returns its output
func ExecCommandOutput(name string, args ...string) ([]byte, error) {
log.Infof("Executing command: %s %v", name, args)
cmd := exec.Command(name, args...)
output, err := cmd.Output()
if err != nil {
return nil, errors.Wrapf(err, "failed to execute command: %s", name)
}
return output, nil
}

View File

@@ -0,0 +1,62 @@
package utils
import (
"strconv"
"strings"
"github.com/pkg/errors"
)
func GetMediaDuration(path string) (int64, error) {
args := []string{
"-v", "error",
"-show_entries", "format=duration",
"-of", "default=noprint_wrappers=1:nokey=1",
path,
}
output, err := ExecCommandOutput("ffprobe", args...)
if err != nil {
return 0, errors.Wrap(err, "ffprobe error")
}
duration := strings.TrimSpace(string(output))
durationFloat, err := strconv.ParseFloat(duration, 64)
if err != nil {
return 0, errors.Wrap(err, "duration conversion error")
}
return int64(durationFloat), nil
}
func CutMedia(input, output string, start, end int64) error {
args := []string{
"-y",
"-hide_banner",
"-nostats",
"-v", "error",
"-ss", strconv.FormatInt(start, 10),
"-i", input,
"-t", strconv.FormatInt(end, 10),
"-c", "copy",
output,
}
return ExecCommand("ffmpeg", args...)
}
// GetFrameImageFromVideo extracts target time frame from a video file and saves it as an image.
func GetFrameImageFromVideo(input, output string, time int64) error {
args := []string{
"-y",
"-hide_banner",
"-nostats",
"-v", "error",
"-i", input,
"-ss", strconv.FormatInt(time, 10),
"-vframes", "1",
output,
}
return ExecCommand("ffmpeg", args...)
}

View File

@@ -0,0 +1,49 @@
package utils
import (
"path/filepath"
"testing"
"github.com/rogeecn/fabfile"
. "github.com/smartystreets/goconvey/convey"
)
func Test_GetMediaDuration(t *testing.T) {
Convey("test_get_media_duration", t, func() {
target := fabfile.MustFind("fixtures/input.mp4")
duration, err := GetMediaDuration(target)
So(err, ShouldBeNil)
t.Logf("duration is: %d", duration)
})
}
func Test_CutMedia(t *testing.T) {
Convey("test_cut_media", t, func() {
input := fabfile.MustFind("fixtures/input.mp4")
output := fabfile.MustFind("fixtures/output.mp4")
t.Logf("INPUT: %s", input)
t.Logf("OUTPUT: %s", output)
err := CutMedia(input, output, 0, 10)
So(err, ShouldBeNil)
// check output duration
duration, err := GetMediaDuration(output)
So(err, ShouldBeNil)
t.Logf("output duration is: %d", duration)
})
}
func Test_GetFrameImageFromVideo(t *testing.T) {
Convey("test_get_frame_image_from_video", t, func() {
input := fabfile.MustFind("fixtures/input.mp4")
output := filepath.Join(filepath.Dir(input), "output.jpg")
t.Logf("INPUT: %s", input)
t.Logf("OUTPUT: %s", output)
err := GetFrameImageFromVideo(input, output, 1)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,19 @@
package utils
import (
"net/url"
"github.com/gofiber/fiber/v3"
)
func FullURI(ctx fiber.Ctx) string {
fullURL := string(ctx.Request().URI().FullURI())
u, err := url.Parse(fullURL)
if err != nil {
return ""
}
u.Scheme = ctx.Scheme()
u.Host = ctx.Host()
return u.String()
}

View File

@@ -0,0 +1,42 @@
package utils
import (
"crypto/md5"
"fmt"
"io"
"os"
)
// Compare file md5
func CompareFileMd5(file, md5 string) (bool, error) {
fileMd5, err := GetFileMd5(file)
if err != nil {
return false, err
}
return fileMd5 == md5, nil
}
// GetFileMd5
func GetFileMd5(file string) (string, error) {
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
// GetFileSize
func GetFileSize(file string) (int64, error) {
fi, err := os.Stat(file)
if err != nil {
return 0, err
}
return fi.Size(), nil
}

View File

@@ -0,0 +1,45 @@
package utils
import "strings"
// FormatTitle
// Format the title of a media file by replacing spaces with underscores and removing special characters
func FormatTitle(title string) string {
// remove file ext from title
if strings.Contains(title, ".") {
title = strings.Split(title, ".")[0]
}
// replace all spaces with underscores
replacements := []string{
" ", "",
"!", "",
"@", "",
"#", "",
"$", "",
"%", "",
"^", "",
"&", "",
"*", "",
"(", "",
")", "",
"[", "【",
"]", "】",
"{", "《",
"}", "》",
":", "",
";", "",
"'", "",
"\"", "",
"<", "",
">", "",
",", "",
".", "",
"?", "",
}
replacer := strings.NewReplacer(replacements...)
title = replacer.Replace(title)
return title
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
package utils
import "testing"
func TestNames_Random(t *testing.T) {
for i := 0; i < 10; i++ {
name := RandomNickname()
t.Logf("name: %s", name)
}
}