add jobs
This commit is contained in:
23
backend/app/events/publishers/post_created.go
Normal file
23
backend/app/events/publishers/post_created.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package publishers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"backend/app/events"
|
||||||
|
|
||||||
|
"git.ipao.vip/rogeecn/atom/contracts"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ contracts.EventPublisher = (*UserRegister)(nil)
|
||||||
|
|
||||||
|
type PostCreated struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *PostCreated) Marshal() ([]byte, error) {
|
||||||
|
return json.Marshal(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *PostCreated) Topic() string {
|
||||||
|
return events.TopicPostCreated.String()
|
||||||
|
}
|
||||||
99
backend/app/events/subscribers/post_created.go
Normal file
99
backend/app/events/subscribers/post_created.go
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package subscribers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"backend/app/events"
|
||||||
|
"backend/app/events/publishers"
|
||||||
|
"backend/app/http/posts"
|
||||||
|
"backend/app/jobs"
|
||||||
|
"backend/database/fields"
|
||||||
|
"backend/providers/job"
|
||||||
|
|
||||||
|
"git.ipao.vip/rogeecn/atom/contracts"
|
||||||
|
"github.com/ThreeDotsLabs/watermill/message"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/samber/lo"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ contracts.EventHandler = (*PostCreated)(nil)
|
||||||
|
|
||||||
|
// @provider(event)
|
||||||
|
type PostCreated struct {
|
||||||
|
log *logrus.Entry `inject:"false"`
|
||||||
|
|
||||||
|
postSvc *posts.Service
|
||||||
|
job *job.Job
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *PostCreated) Prepare() error {
|
||||||
|
e.log = logrus.WithField("module", "events.subscribers.user_register")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PublishToTopic implements contracts.EventHandler.
|
||||||
|
func (e *PostCreated) PublishToTopic() string {
|
||||||
|
return events.TopicProcessed.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Topic implements contracts.EventHandler.
|
||||||
|
func (e *PostCreated) Topic() string {
|
||||||
|
return events.TopicPostCreated.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler implements contracts.EventHandler.
|
||||||
|
func (e *PostCreated) Handler(msg *message.Message) ([]*message.Message, error) {
|
||||||
|
var payload publishers.PostCreated
|
||||||
|
err := json.Unmarshal(msg.Payload, &payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
e.log.Infof("received event %s", msg.Payload)
|
||||||
|
|
||||||
|
post, err := e.postSvc.GetPostByID(context.Background(), payload.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "failed to get user by id: %d", payload.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
video, ok := lo.Find(post.Assets.Data, func(asset fields.MediaAsset) bool {
|
||||||
|
return asset.Type == fields.MediaAssetTypeVideo
|
||||||
|
})
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
e.log.Warnf("post %d %s has no video asset", post.ID, post.Title)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = video
|
||||||
|
|
||||||
|
job, err := e.job.Client()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// cut video
|
||||||
|
_, err = job.Insert(context.Background(), jobs.VideoCut{
|
||||||
|
PostID: post.ID,
|
||||||
|
Hash: video.Hash,
|
||||||
|
TenantID: post.TenantID,
|
||||||
|
UserID: post.UserID,
|
||||||
|
}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract audio
|
||||||
|
_, err = job.Insert(context.Background(), jobs.VideoExtractAudio{
|
||||||
|
PostID: post.ID,
|
||||||
|
Hash: video.Hash,
|
||||||
|
TenantID: post.TenantID,
|
||||||
|
UserID: post.UserID,
|
||||||
|
}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@ const (
|
|||||||
TopicProcessed Topic = "event:processed"
|
TopicProcessed Topic = "event:processed"
|
||||||
// TopicUserRegister is a Topic of type UserRegister.
|
// TopicUserRegister is a Topic of type UserRegister.
|
||||||
TopicUserRegister Topic = "user:register"
|
TopicUserRegister Topic = "user:register"
|
||||||
|
// TopicPostCreated is a Topic of type PostCreated.
|
||||||
|
TopicPostCreated Topic = "post:created"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidTopic = fmt.Errorf("not a valid Topic, try [%s]", strings.Join(_TopicNames, ", "))
|
var ErrInvalidTopic = fmt.Errorf("not a valid Topic, try [%s]", strings.Join(_TopicNames, ", "))
|
||||||
@@ -25,6 +27,7 @@ var ErrInvalidTopic = fmt.Errorf("not a valid Topic, try [%s]", strings.Join(_To
|
|||||||
var _TopicNames = []string{
|
var _TopicNames = []string{
|
||||||
string(TopicProcessed),
|
string(TopicProcessed),
|
||||||
string(TopicUserRegister),
|
string(TopicUserRegister),
|
||||||
|
string(TopicPostCreated),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TopicNames returns a list of possible string values of Topic.
|
// TopicNames returns a list of possible string values of Topic.
|
||||||
@@ -39,6 +42,7 @@ func TopicValues() []Topic {
|
|||||||
return []Topic{
|
return []Topic{
|
||||||
TopicProcessed,
|
TopicProcessed,
|
||||||
TopicUserRegister,
|
TopicUserRegister,
|
||||||
|
TopicPostCreated,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +61,7 @@ func (x Topic) IsValid() bool {
|
|||||||
var _TopicValue = map[string]Topic{
|
var _TopicValue = map[string]Topic{
|
||||||
"event:processed": TopicProcessed,
|
"event:processed": TopicProcessed,
|
||||||
"user:register": TopicUserRegister,
|
"user:register": TopicUserRegister,
|
||||||
|
"post:created": TopicPostCreated,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseTopic attempts to convert a string to a Topic.
|
// ParseTopic attempts to convert a string to a Topic.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package events
|
|||||||
//
|
//
|
||||||
// Processed = "event:processed"
|
// Processed = "event:processed"
|
||||||
// UserRegister = "user:register"
|
// UserRegister = "user:register"
|
||||||
|
// PostCreated = "post:created"
|
||||||
//
|
//
|
||||||
// )
|
// )
|
||||||
type Topic string
|
type Topic string
|
||||||
|
|||||||
@@ -174,12 +174,13 @@ func (ctl *Controller) Create(ctx fiber.Ctx, claim *jwt.Claims, tenantSlug strin
|
|||||||
Title: body.Title,
|
Title: body.Title,
|
||||||
Description: body.Description,
|
Description: body.Description,
|
||||||
Content: body.Content,
|
Content: body.Content,
|
||||||
Stage: fields.PostStagePending,
|
|
||||||
Status: fields.PostStatusPending,
|
|
||||||
Price: body.Price,
|
Price: body.Price,
|
||||||
Discount: body.Discount,
|
Discount: body.Discount,
|
||||||
Assets: body.Assets,
|
Assets: body.Assets,
|
||||||
Tags: body.Tags,
|
Tags: body.Tags,
|
||||||
|
|
||||||
|
Stage: fields.PostStagePending,
|
||||||
|
Status: fields.PostStatusPending,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ctl.svc.Create(ctx.Context(), tenant, user, post); err != nil {
|
if err := ctl.svc.Create(ctx.Context(), tenant, user, post); err != nil {
|
||||||
|
|||||||
52
backend/app/jobs/VideoCut.go
Normal file
52
backend/app/jobs/VideoCut.go
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
_ "git.ipao.vip/rogeecn/atom"
|
||||||
|
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||||
|
. "github.com/riverqueue/river"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ JobArgs = VideoCut{}
|
||||||
|
_ JobArgsWithInsertOpts = VideoCut{}
|
||||||
|
)
|
||||||
|
|
||||||
|
type VideoCut struct {
|
||||||
|
PostID int64 `json:"post_id"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
TenantID int64 `json:"tenant_id"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertOpts implements JobArgsWithInsertOpts.
|
||||||
|
func (s VideoCut) InsertOpts() InsertOpts {
|
||||||
|
return InsertOpts{
|
||||||
|
Queue: QueueDefault,
|
||||||
|
Priority: PriorityDefault,
|
||||||
|
UniqueOpts: UniqueOpts{
|
||||||
|
ByArgs: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (VideoCut) Kind() string {
|
||||||
|
return "VideoCut"
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Worker[VideoCut] = (*VideoCutWorker)(nil)
|
||||||
|
|
||||||
|
// @provider(job)
|
||||||
|
type VideoCutWorker struct {
|
||||||
|
WorkerDefaults[VideoCut]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *VideoCutWorker) NextRetry(job *Job[VideoCut]) time.Time {
|
||||||
|
return time.Now().Add(5 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *VideoCutWorker) Work(ctx context.Context, job *Job[VideoCut]) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
52
backend/app/jobs/VideoExtractAudio.go
Normal file
52
backend/app/jobs/VideoExtractAudio.go
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
_ "git.ipao.vip/rogeecn/atom"
|
||||||
|
_ "git.ipao.vip/rogeecn/atom/contracts"
|
||||||
|
. "github.com/riverqueue/river"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ JobArgs = VideoExtractAudio{}
|
||||||
|
_ JobArgsWithInsertOpts = VideoExtractAudio{}
|
||||||
|
)
|
||||||
|
|
||||||
|
type VideoExtractAudio struct {
|
||||||
|
PostID int64 `json:"post_id"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
TenantID int64 `json:"tenant_id"`
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertOpts implements JobArgsWithInsertOpts.
|
||||||
|
func (s VideoExtractAudio) InsertOpts() InsertOpts {
|
||||||
|
return InsertOpts{
|
||||||
|
Queue: QueueDefault,
|
||||||
|
Priority: PriorityDefault,
|
||||||
|
UniqueOpts: UniqueOpts{
|
||||||
|
ByArgs: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (VideoExtractAudio) Kind() string {
|
||||||
|
return "VideoExtractAudio"
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Worker[VideoExtractAudio] = (*VideoExtractAudioWorker)(nil)
|
||||||
|
|
||||||
|
// @provider(job)
|
||||||
|
type VideoExtractAudioWorker struct {
|
||||||
|
WorkerDefaults[VideoExtractAudio]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *VideoExtractAudioWorker) NextRetry(job *Job[VideoExtractAudio]) time.Time {
|
||||||
|
return time.Now().Add(5 * time.Minute)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *VideoExtractAudioWorker) Work(ctx context.Context, job *Job[VideoExtractAudio]) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
// Code generated by go-enum DO NOT EDIT.
|
|
||||||
// Version: -
|
|
||||||
// Revision: -
|
|
||||||
// Build Date: -
|
|
||||||
// Built By: -
|
|
||||||
|
|
||||||
package fields
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql/driver"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// MediaAssetTypeUnknown is a MediaAssetType of type Unknown.
|
|
||||||
MediaAssetTypeUnknown MediaAssetType = "unknown"
|
|
||||||
// MediaAssetTypePoster is a MediaAssetType of type Poster.
|
|
||||||
MediaAssetTypePoster MediaAssetType = "poster"
|
|
||||||
// MediaAssetTypeImage is a MediaAssetType of type Image.
|
|
||||||
MediaAssetTypeImage MediaAssetType = "image"
|
|
||||||
// MediaAssetTypeVideo is a MediaAssetType of type Video.
|
|
||||||
MediaAssetTypeVideo MediaAssetType = "video"
|
|
||||||
// MediaAssetTypeAudio is a MediaAssetType of type Audio.
|
|
||||||
MediaAssetTypeAudio MediaAssetType = "audio"
|
|
||||||
// MediaAssetTypeDocument is a MediaAssetType of type Document.
|
|
||||||
MediaAssetTypeDocument MediaAssetType = "document"
|
|
||||||
// MediaAssetTypeOther is a MediaAssetType of type Other.
|
|
||||||
MediaAssetTypeOther MediaAssetType = "other"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrInvalidMediaAssetType = fmt.Errorf("not a valid MediaAssetType, try [%s]", strings.Join(_MediaAssetTypeNames, ", "))
|
|
||||||
|
|
||||||
var _MediaAssetTypeNames = []string{
|
|
||||||
string(MediaAssetTypeUnknown),
|
|
||||||
string(MediaAssetTypePoster),
|
|
||||||
string(MediaAssetTypeImage),
|
|
||||||
string(MediaAssetTypeVideo),
|
|
||||||
string(MediaAssetTypeAudio),
|
|
||||||
string(MediaAssetTypeDocument),
|
|
||||||
string(MediaAssetTypeOther),
|
|
||||||
}
|
|
||||||
|
|
||||||
// MediaAssetTypeNames returns a list of possible string values of MediaAssetType.
|
|
||||||
func MediaAssetTypeNames() []string {
|
|
||||||
tmp := make([]string, len(_MediaAssetTypeNames))
|
|
||||||
copy(tmp, _MediaAssetTypeNames)
|
|
||||||
return tmp
|
|
||||||
}
|
|
||||||
|
|
||||||
// MediaAssetTypeValues returns a list of the values for MediaAssetType
|
|
||||||
func MediaAssetTypeValues() []MediaAssetType {
|
|
||||||
return []MediaAssetType{
|
|
||||||
MediaAssetTypeUnknown,
|
|
||||||
MediaAssetTypePoster,
|
|
||||||
MediaAssetTypeImage,
|
|
||||||
MediaAssetTypeVideo,
|
|
||||||
MediaAssetTypeAudio,
|
|
||||||
MediaAssetTypeDocument,
|
|
||||||
MediaAssetTypeOther,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// String implements the Stringer interface.
|
|
||||||
func (x MediaAssetType) 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 MediaAssetType) IsValid() bool {
|
|
||||||
_, err := ParseMediaAssetType(string(x))
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var _MediaAssetTypeValue = map[string]MediaAssetType{
|
|
||||||
"unknown": MediaAssetTypeUnknown,
|
|
||||||
"poster": MediaAssetTypePoster,
|
|
||||||
"image": MediaAssetTypeImage,
|
|
||||||
"video": MediaAssetTypeVideo,
|
|
||||||
"audio": MediaAssetTypeAudio,
|
|
||||||
"document": MediaAssetTypeDocument,
|
|
||||||
"other": MediaAssetTypeOther,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseMediaAssetType attempts to convert a string to a MediaAssetType.
|
|
||||||
func ParseMediaAssetType(name string) (MediaAssetType, error) {
|
|
||||||
if x, ok := _MediaAssetTypeValue[name]; ok {
|
|
||||||
return x, nil
|
|
||||||
}
|
|
||||||
return MediaAssetType(""), fmt.Errorf("%s is %w", name, ErrInvalidMediaAssetType)
|
|
||||||
}
|
|
||||||
|
|
||||||
var errMediaAssetTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
|
||||||
|
|
||||||
// Scan implements the Scanner interface.
|
|
||||||
func (x *MediaAssetType) Scan(value interface{}) (err error) {
|
|
||||||
if value == nil {
|
|
||||||
*x = MediaAssetType("")
|
|
||||||
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 = ParseMediaAssetType(v)
|
|
||||||
case []byte:
|
|
||||||
*x, err = ParseMediaAssetType(string(v))
|
|
||||||
case MediaAssetType:
|
|
||||||
*x = v
|
|
||||||
case *MediaAssetType:
|
|
||||||
if v == nil {
|
|
||||||
return errMediaAssetTypeNilPtr
|
|
||||||
}
|
|
||||||
*x = *v
|
|
||||||
case *string:
|
|
||||||
if v == nil {
|
|
||||||
return errMediaAssetTypeNilPtr
|
|
||||||
}
|
|
||||||
*x, err = ParseMediaAssetType(*v)
|
|
||||||
default:
|
|
||||||
return errors.New("invalid type for MediaAssetType")
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
|
||||||
func (x MediaAssetType) Value() (driver.Value, error) {
|
|
||||||
return x.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set implements the Golang flag.Value interface func.
|
|
||||||
func (x *MediaAssetType) Set(val string) error {
|
|
||||||
v, err := ParseMediaAssetType(val)
|
|
||||||
*x = v
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get implements the Golang flag.Getter interface func.
|
|
||||||
func (x *MediaAssetType) Get() interface{} {
|
|
||||||
return *x
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type implements the github.com/spf13/pFlag Value interface.
|
|
||||||
func (x *MediaAssetType) Type() string {
|
|
||||||
return "MediaAssetType"
|
|
||||||
}
|
|
||||||
|
|
||||||
type NullMediaAssetType struct {
|
|
||||||
MediaAssetType MediaAssetType
|
|
||||||
Valid bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNullMediaAssetType(val interface{}) (x NullMediaAssetType) {
|
|
||||||
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 *NullMediaAssetType) Scan(value interface{}) (err error) {
|
|
||||||
if value == nil {
|
|
||||||
x.MediaAssetType, x.Valid = MediaAssetType(""), false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = x.MediaAssetType.Scan(value)
|
|
||||||
x.Valid = (err == nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
|
||||||
func (x NullMediaAssetType) Value() (driver.Value, error) {
|
|
||||||
if !x.Valid {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
// driver.Value accepts int64 for int values.
|
|
||||||
return string(x.MediaAssetType), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type NullMediaAssetTypeStr struct {
|
|
||||||
NullMediaAssetType
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNullMediaAssetTypeStr(val interface{}) (x NullMediaAssetTypeStr) {
|
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
|
||||||
func (x NullMediaAssetTypeStr) Value() (driver.Value, error) {
|
|
||||||
if !x.Valid {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return x.MediaAssetType.String(), nil
|
|
||||||
}
|
|
||||||
@@ -1,18 +1 @@
|
|||||||
package fields
|
package fields
|
||||||
|
|
||||||
type MediaAsset struct {
|
|
||||||
Type MediaAssetType `json:"type"`
|
|
||||||
Hash string `json:"hash"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// swagger:enum MediaAssetType
|
|
||||||
// ENUM(
|
|
||||||
// Unknown = "unknown",
|
|
||||||
// Poster = "poster",
|
|
||||||
// Image = "image",
|
|
||||||
// Video = "video",
|
|
||||||
// Audio = "audio",
|
|
||||||
// Document = "document",
|
|
||||||
// Other = "other"
|
|
||||||
// )
|
|
||||||
type MediaAssetType string
|
|
||||||
|
|||||||
@@ -15,81 +15,272 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// UserStatusPending is a UserStatus of type Pending.
|
// MediaAssetTypeUnknown is a MediaAssetType of type Unknown.
|
||||||
UserStatusPending UserStatus = iota
|
MediaAssetTypeUnknown MediaAssetType = "unknown"
|
||||||
// UserStatusVerified is a UserStatus of type Verified.
|
// MediaAssetTypePoster is a MediaAssetType of type Poster.
|
||||||
UserStatusVerified
|
MediaAssetTypePoster MediaAssetType = "poster"
|
||||||
// UserStatusBlocked is a UserStatus of type Blocked.
|
// MediaAssetTypeImage is a MediaAssetType of type Image.
|
||||||
UserStatusBlocked
|
MediaAssetTypeImage MediaAssetType = "image"
|
||||||
|
// MediaAssetTypeVideo is a MediaAssetType of type Video.
|
||||||
|
MediaAssetTypeVideo MediaAssetType = "video"
|
||||||
|
// MediaAssetTypeAudio is a MediaAssetType of type Audio.
|
||||||
|
MediaAssetTypeAudio MediaAssetType = "audio"
|
||||||
|
// MediaAssetTypeDocument is a MediaAssetType of type Document.
|
||||||
|
MediaAssetTypeDocument MediaAssetType = "document"
|
||||||
|
// MediaAssetTypeOther is a MediaAssetType of type Other.
|
||||||
|
MediaAssetTypeOther MediaAssetType = "other"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidUserStatus = fmt.Errorf("not a valid UserStatus, try [%s]", strings.Join(_UserStatusNames, ", "))
|
var ErrInvalidMediaAssetType = fmt.Errorf("not a valid MediaAssetType, try [%s]", strings.Join(_MediaAssetTypeNames, ", "))
|
||||||
|
|
||||||
const _UserStatusName = "PendingVerifiedBlocked"
|
var _MediaAssetTypeNames = []string{
|
||||||
|
string(MediaAssetTypeUnknown),
|
||||||
var _UserStatusNames = []string{
|
string(MediaAssetTypePoster),
|
||||||
_UserStatusName[0:7],
|
string(MediaAssetTypeImage),
|
||||||
_UserStatusName[7:15],
|
string(MediaAssetTypeVideo),
|
||||||
_UserStatusName[15:22],
|
string(MediaAssetTypeAudio),
|
||||||
|
string(MediaAssetTypeDocument),
|
||||||
|
string(MediaAssetTypeOther),
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserStatusNames returns a list of possible string values of UserStatus.
|
// MediaAssetTypeNames returns a list of possible string values of MediaAssetType.
|
||||||
func UserStatusNames() []string {
|
func MediaAssetTypeNames() []string {
|
||||||
tmp := make([]string, len(_UserStatusNames))
|
tmp := make([]string, len(_MediaAssetTypeNames))
|
||||||
copy(tmp, _UserStatusNames)
|
copy(tmp, _MediaAssetTypeNames)
|
||||||
return tmp
|
return tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserStatusValues returns a list of the values for UserStatus
|
// MediaAssetTypeValues returns a list of the values for MediaAssetType
|
||||||
func UserStatusValues() []UserStatus {
|
func MediaAssetTypeValues() []MediaAssetType {
|
||||||
return []UserStatus{
|
return []MediaAssetType{
|
||||||
UserStatusPending,
|
MediaAssetTypeUnknown,
|
||||||
UserStatusVerified,
|
MediaAssetTypePoster,
|
||||||
UserStatusBlocked,
|
MediaAssetTypeImage,
|
||||||
|
MediaAssetTypeVideo,
|
||||||
|
MediaAssetTypeAudio,
|
||||||
|
MediaAssetTypeDocument,
|
||||||
|
MediaAssetTypeOther,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _UserStatusMap = map[UserStatus]string{
|
|
||||||
UserStatusPending: _UserStatusName[0:7],
|
|
||||||
UserStatusVerified: _UserStatusName[7:15],
|
|
||||||
UserStatusBlocked: _UserStatusName[15:22],
|
|
||||||
}
|
|
||||||
|
|
||||||
// String implements the Stringer interface.
|
// String implements the Stringer interface.
|
||||||
func (x UserStatus) String() string {
|
func (x MediaAssetType) String() string {
|
||||||
if str, ok := _UserStatusMap[x]; ok {
|
return string(x)
|
||||||
return str
|
|
||||||
}
|
|
||||||
return fmt.Sprintf("UserStatus(%d)", x)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid provides a quick way to determine if the typed value is
|
// IsValid provides a quick way to determine if the typed value is
|
||||||
// part of the allowed enumerated values
|
// part of the allowed enumerated values
|
||||||
func (x UserStatus) IsValid() bool {
|
func (x MediaAssetType) IsValid() bool {
|
||||||
_, ok := _UserStatusMap[x]
|
_, err := ParseMediaAssetType(string(x))
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _MediaAssetTypeValue = map[string]MediaAssetType{
|
||||||
|
"unknown": MediaAssetTypeUnknown,
|
||||||
|
"poster": MediaAssetTypePoster,
|
||||||
|
"image": MediaAssetTypeImage,
|
||||||
|
"video": MediaAssetTypeVideo,
|
||||||
|
"audio": MediaAssetTypeAudio,
|
||||||
|
"document": MediaAssetTypeDocument,
|
||||||
|
"other": MediaAssetTypeOther,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseMediaAssetType attempts to convert a string to a MediaAssetType.
|
||||||
|
func ParseMediaAssetType(name string) (MediaAssetType, error) {
|
||||||
|
if x, ok := _MediaAssetTypeValue[name]; ok {
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
return MediaAssetType(""), fmt.Errorf("%s is %w", name, ErrInvalidMediaAssetType)
|
||||||
|
}
|
||||||
|
|
||||||
|
var errMediaAssetTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
||||||
|
|
||||||
|
// Scan implements the Scanner interface.
|
||||||
|
func (x *MediaAssetType) Scan(value interface{}) (err error) {
|
||||||
|
if value == nil {
|
||||||
|
*x = MediaAssetType("")
|
||||||
|
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 = ParseMediaAssetType(v)
|
||||||
|
case []byte:
|
||||||
|
*x, err = ParseMediaAssetType(string(v))
|
||||||
|
case MediaAssetType:
|
||||||
|
*x = v
|
||||||
|
case *MediaAssetType:
|
||||||
|
if v == nil {
|
||||||
|
return errMediaAssetTypeNilPtr
|
||||||
|
}
|
||||||
|
*x = *v
|
||||||
|
case *string:
|
||||||
|
if v == nil {
|
||||||
|
return errMediaAssetTypeNilPtr
|
||||||
|
}
|
||||||
|
*x, err = ParseMediaAssetType(*v)
|
||||||
|
default:
|
||||||
|
return errors.New("invalid type for MediaAssetType")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value implements the driver Valuer interface.
|
||||||
|
func (x MediaAssetType) Value() (driver.Value, error) {
|
||||||
|
return x.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set implements the Golang flag.Value interface func.
|
||||||
|
func (x *MediaAssetType) Set(val string) error {
|
||||||
|
v, err := ParseMediaAssetType(val)
|
||||||
|
*x = v
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get implements the Golang flag.Getter interface func.
|
||||||
|
func (x *MediaAssetType) Get() interface{} {
|
||||||
|
return *x
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type implements the github.com/spf13/pFlag Value interface.
|
||||||
|
func (x *MediaAssetType) Type() string {
|
||||||
|
return "MediaAssetType"
|
||||||
|
}
|
||||||
|
|
||||||
|
type NullMediaAssetType struct {
|
||||||
|
MediaAssetType MediaAssetType
|
||||||
|
Valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNullMediaAssetType(val interface{}) (x NullMediaAssetType) {
|
||||||
|
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 *NullMediaAssetType) Scan(value interface{}) (err error) {
|
||||||
|
if value == nil {
|
||||||
|
x.MediaAssetType, x.Valid = MediaAssetType(""), false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = x.MediaAssetType.Scan(value)
|
||||||
|
x.Valid = (err == nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value implements the driver Valuer interface.
|
||||||
|
func (x NullMediaAssetType) Value() (driver.Value, error) {
|
||||||
|
if !x.Valid {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
// driver.Value accepts int64 for int values.
|
||||||
|
return string(x.MediaAssetType), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type NullMediaAssetTypeStr struct {
|
||||||
|
NullMediaAssetType
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNullMediaAssetTypeStr(val interface{}) (x NullMediaAssetTypeStr) {
|
||||||
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value implements the driver Valuer interface.
|
||||||
|
func (x NullMediaAssetTypeStr) Value() (driver.Value, error) {
|
||||||
|
if !x.Valid {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
return x.MediaAssetType.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// PostStagePending is a PostStage of type Pending.
|
||||||
|
PostStagePending PostStage = iota
|
||||||
|
// PostStageProcessing is a PostStage of type Processing.
|
||||||
|
PostStageProcessing
|
||||||
|
// PostStageCompleted is a PostStage of type Completed.
|
||||||
|
PostStageCompleted
|
||||||
|
// PostStageDeleted is a PostStage of type Deleted.
|
||||||
|
PostStageDeleted
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrInvalidPostStage = fmt.Errorf("not a valid PostStage, try [%s]", strings.Join(_PostStageNames, ", "))
|
||||||
|
|
||||||
|
const _PostStageName = "PendingProcessingCompletedDeleted"
|
||||||
|
|
||||||
|
var _PostStageNames = []string{
|
||||||
|
_PostStageName[0:7],
|
||||||
|
_PostStageName[7:17],
|
||||||
|
_PostStageName[17:26],
|
||||||
|
_PostStageName[26:33],
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostStageNames returns a list of possible string values of PostStage.
|
||||||
|
func PostStageNames() []string {
|
||||||
|
tmp := make([]string, len(_PostStageNames))
|
||||||
|
copy(tmp, _PostStageNames)
|
||||||
|
return tmp
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostStageValues returns a list of the values for PostStage
|
||||||
|
func PostStageValues() []PostStage {
|
||||||
|
return []PostStage{
|
||||||
|
PostStagePending,
|
||||||
|
PostStageProcessing,
|
||||||
|
PostStageCompleted,
|
||||||
|
PostStageDeleted,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PostStageMap = map[PostStage]string{
|
||||||
|
PostStagePending: _PostStageName[0:7],
|
||||||
|
PostStageProcessing: _PostStageName[7:17],
|
||||||
|
PostStageCompleted: _PostStageName[17:26],
|
||||||
|
PostStageDeleted: _PostStageName[26:33],
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the Stringer interface.
|
||||||
|
func (x PostStage) String() string {
|
||||||
|
if str, ok := _PostStageMap[x]; ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("PostStage(%d)", x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid provides a quick way to determine if the typed value is
|
||||||
|
// part of the allowed enumerated values
|
||||||
|
func (x PostStage) IsValid() bool {
|
||||||
|
_, ok := _PostStageMap[x]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
var _UserStatusValue = map[string]UserStatus{
|
var _PostStageValue = map[string]PostStage{
|
||||||
_UserStatusName[0:7]: UserStatusPending,
|
_PostStageName[0:7]: PostStagePending,
|
||||||
_UserStatusName[7:15]: UserStatusVerified,
|
_PostStageName[7:17]: PostStageProcessing,
|
||||||
_UserStatusName[15:22]: UserStatusBlocked,
|
_PostStageName[17:26]: PostStageCompleted,
|
||||||
|
_PostStageName[26:33]: PostStageDeleted,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseUserStatus attempts to convert a string to a UserStatus.
|
// ParsePostStage attempts to convert a string to a PostStage.
|
||||||
func ParseUserStatus(name string) (UserStatus, error) {
|
func ParsePostStage(name string) (PostStage, error) {
|
||||||
if x, ok := _UserStatusValue[name]; ok {
|
if x, ok := _PostStageValue[name]; ok {
|
||||||
return x, nil
|
return x, nil
|
||||||
}
|
}
|
||||||
return UserStatus(0), fmt.Errorf("%s is %w", name, ErrInvalidUserStatus)
|
return PostStage(0), fmt.Errorf("%s is %w", name, ErrInvalidPostStage)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errUserStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
var errPostStageNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
||||||
|
|
||||||
// Scan implements the Scanner interface.
|
// Scan implements the Scanner interface.
|
||||||
func (x *UserStatus) Scan(value interface{}) (err error) {
|
func (x *PostStage) Scan(value interface{}) (err error) {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
*x = UserStatus(0)
|
*x = PostStage(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,72 +288,72 @@ func (x *UserStatus) Scan(value interface{}) (err error) {
|
|||||||
// driver.Value values at the top of the list for expediency
|
// driver.Value values at the top of the list for expediency
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
*x = UserStatus(v)
|
*x = PostStage(v)
|
||||||
case string:
|
case string:
|
||||||
*x, err = ParseUserStatus(v)
|
*x, err = ParsePostStage(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try parsing the integer value as a string
|
// try parsing the integer value as a string
|
||||||
if val, verr := strconv.Atoi(v); verr == nil {
|
if val, verr := strconv.Atoi(v); verr == nil {
|
||||||
*x, err = UserStatus(val), nil
|
*x, err = PostStage(val), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case []byte:
|
case []byte:
|
||||||
*x, err = ParseUserStatus(string(v))
|
*x, err = ParsePostStage(string(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try parsing the integer value as a string
|
// try parsing the integer value as a string
|
||||||
if val, verr := strconv.Atoi(string(v)); verr == nil {
|
if val, verr := strconv.Atoi(string(v)); verr == nil {
|
||||||
*x, err = UserStatus(val), nil
|
*x, err = PostStage(val), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case UserStatus:
|
case PostStage:
|
||||||
*x = v
|
*x = v
|
||||||
case int:
|
case int:
|
||||||
*x = UserStatus(v)
|
*x = PostStage(v)
|
||||||
case *UserStatus:
|
case *PostStage:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x = *v
|
*x = *v
|
||||||
case uint:
|
case uint:
|
||||||
*x = UserStatus(v)
|
*x = PostStage(v)
|
||||||
case uint64:
|
case uint64:
|
||||||
*x = UserStatus(v)
|
*x = PostStage(v)
|
||||||
case *int:
|
case *int:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x = UserStatus(*v)
|
*x = PostStage(*v)
|
||||||
case *int64:
|
case *int64:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x = UserStatus(*v)
|
*x = PostStage(*v)
|
||||||
case float64: // json marshals everything as a float64 if it's a number
|
case float64: // json marshals everything as a float64 if it's a number
|
||||||
*x = UserStatus(v)
|
*x = PostStage(v)
|
||||||
case *float64: // json marshals everything as a float64 if it's a number
|
case *float64: // json marshals everything as a float64 if it's a number
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x = UserStatus(*v)
|
*x = PostStage(*v)
|
||||||
case *uint:
|
case *uint:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x = UserStatus(*v)
|
*x = PostStage(*v)
|
||||||
case *uint64:
|
case *uint64:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x = UserStatus(*v)
|
*x = PostStage(*v)
|
||||||
case *string:
|
case *string:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errUserStatusNilPtr
|
return errPostStageNilPtr
|
||||||
}
|
}
|
||||||
*x, err = ParseUserStatus(*v)
|
*x, err = ParsePostStage(*v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try parsing the integer value as a string
|
// try parsing the integer value as a string
|
||||||
if val, verr := strconv.Atoi(*v); verr == nil {
|
if val, verr := strconv.Atoi(*v); verr == nil {
|
||||||
*x, err = UserStatus(val), nil
|
*x, err = PostStage(val), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,71 +362,529 @@ func (x *UserStatus) Scan(value interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
// Value implements the driver Valuer interface.
|
||||||
func (x UserStatus) Value() (driver.Value, error) {
|
func (x PostStage) Value() (driver.Value, error) {
|
||||||
return int64(x), nil
|
return int64(x), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set implements the Golang flag.Value interface func.
|
// Set implements the Golang flag.Value interface func.
|
||||||
func (x *UserStatus) Set(val string) error {
|
func (x *PostStage) Set(val string) error {
|
||||||
v, err := ParseUserStatus(val)
|
v, err := ParsePostStage(val)
|
||||||
*x = v
|
*x = v
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get implements the Golang flag.Getter interface func.
|
// Get implements the Golang flag.Getter interface func.
|
||||||
func (x *UserStatus) Get() interface{} {
|
func (x *PostStage) Get() interface{} {
|
||||||
return *x
|
return *x
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type implements the github.com/spf13/pFlag Value interface.
|
// Type implements the github.com/spf13/pFlag Value interface.
|
||||||
func (x *UserStatus) Type() string {
|
func (x *PostStage) Type() string {
|
||||||
return "UserStatus"
|
return "PostStage"
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullUserStatus struct {
|
type NullPostStage struct {
|
||||||
UserStatus UserStatus
|
PostStage PostStage
|
||||||
Valid bool
|
Valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNullUserStatus(val interface{}) (x NullUserStatus) {
|
func NewNullPostStage(val interface{}) (x NullPostStage) {
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan implements the Scanner interface.
|
// Scan implements the Scanner interface.
|
||||||
func (x *NullUserStatus) Scan(value interface{}) (err error) {
|
func (x *NullPostStage) Scan(value interface{}) (err error) {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
x.UserStatus, x.Valid = UserStatus(0), false
|
x.PostStage, x.Valid = PostStage(0), false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = x.UserStatus.Scan(value)
|
err = x.PostStage.Scan(value)
|
||||||
x.Valid = (err == nil)
|
x.Valid = (err == nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
// Value implements the driver Valuer interface.
|
||||||
func (x NullUserStatus) Value() (driver.Value, error) {
|
func (x NullPostStage) Value() (driver.Value, error) {
|
||||||
if !x.Valid {
|
if !x.Valid {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
// driver.Value accepts int64 for int values.
|
// driver.Value accepts int64 for int values.
|
||||||
return int64(x.UserStatus), nil
|
return int64(x.PostStage), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullUserStatusStr struct {
|
type NullPostStageStr struct {
|
||||||
NullUserStatus
|
NullPostStage
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNullUserStatusStr(val interface{}) (x NullUserStatusStr) {
|
func NewNullPostStageStr(val interface{}) (x NullPostStageStr) {
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
// Value implements the driver Valuer interface.
|
||||||
func (x NullUserStatusStr) Value() (driver.Value, error) {
|
func (x NullPostStageStr) Value() (driver.Value, error) {
|
||||||
if !x.Valid {
|
if !x.Valid {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return x.UserStatus.String(), nil
|
return x.PostStage.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
// PostStatusPending is a PostStatus of type Pending.
|
||||||
|
PostStatusPending PostStatus = iota
|
||||||
|
// PostStatusVerified is a PostStatus of type Verified.
|
||||||
|
PostStatusVerified
|
||||||
|
// PostStatusBlocked is a PostStatus of type Blocked.
|
||||||
|
PostStatusBlocked
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrInvalidPostStatus = fmt.Errorf("not a valid PostStatus, try [%s]", strings.Join(_PostStatusNames, ", "))
|
||||||
|
|
||||||
|
const _PostStatusName = "PendingVerifiedBlocked"
|
||||||
|
|
||||||
|
var _PostStatusNames = []string{
|
||||||
|
_PostStatusName[0:7],
|
||||||
|
_PostStatusName[7:15],
|
||||||
|
_PostStatusName[15:22],
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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{
|
||||||
|
PostStatusPending,
|
||||||
|
PostStatusVerified,
|
||||||
|
PostStatusBlocked,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _PostStatusMap = map[PostStatus]string{
|
||||||
|
PostStatusPending: _PostStatusName[0:7],
|
||||||
|
PostStatusVerified: _PostStatusName[7:15],
|
||||||
|
PostStatusBlocked: _PostStatusName[15:22],
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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:7]: PostStatusPending,
|
||||||
|
_PostStatusName[7:15]: PostStatusVerified,
|
||||||
|
_PostStatusName[15:22]: PostStatusBlocked,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,31 @@
|
|||||||
package fields
|
package fields
|
||||||
|
|
||||||
// swagger:enum UserStatus
|
type MediaAsset struct {
|
||||||
|
Type MediaAssetType `json:"type"`
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
Mark *string `json:"mark,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// swagger:enum MediaAssetType
|
||||||
|
// ENUM(
|
||||||
|
// Unknown = "unknown",
|
||||||
|
// Poster = "poster",
|
||||||
|
// Image = "image",
|
||||||
|
// Video = "video",
|
||||||
|
// Audio = "audio",
|
||||||
|
// Document = "document",
|
||||||
|
// Other = "other"
|
||||||
|
// )
|
||||||
|
type MediaAssetType string
|
||||||
|
|
||||||
|
// swagger:enum PostStage
|
||||||
|
// ENUM( Pending, Processing, Completed, Deleted)
|
||||||
|
type PostStage int16
|
||||||
|
|
||||||
|
// swagger:enum PostStatus
|
||||||
// ENUM( Pending, Verified, Blocked)
|
// ENUM( Pending, Verified, Blocked)
|
||||||
type UserStatus int16
|
type PostStatus int16
|
||||||
|
|
||||||
|
// swagger:enum PostType
|
||||||
|
// ENUM( Article, Picture, Video, Audio)
|
||||||
|
type PostType int16
|
||||||
|
|||||||
@@ -15,87 +15,81 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// PostStagePending is a PostStage of type Pending.
|
// UserStatusPending is a UserStatus of type Pending.
|
||||||
PostStagePending PostStage = iota
|
UserStatusPending UserStatus = iota
|
||||||
// PostStageProcessing is a PostStage of type Processing.
|
// UserStatusVerified is a UserStatus of type Verified.
|
||||||
PostStageProcessing
|
UserStatusVerified
|
||||||
// PostStageCompleted is a PostStage of type Completed.
|
// UserStatusBlocked is a UserStatus of type Blocked.
|
||||||
PostStageCompleted
|
UserStatusBlocked
|
||||||
// PostStageDeleted is a PostStage of type Deleted.
|
|
||||||
PostStageDeleted
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrInvalidPostStage = fmt.Errorf("not a valid PostStage, try [%s]", strings.Join(_PostStageNames, ", "))
|
var ErrInvalidUserStatus = fmt.Errorf("not a valid UserStatus, try [%s]", strings.Join(_UserStatusNames, ", "))
|
||||||
|
|
||||||
const _PostStageName = "PendingProcessingCompletedDeleted"
|
const _UserStatusName = "PendingVerifiedBlocked"
|
||||||
|
|
||||||
var _PostStageNames = []string{
|
var _UserStatusNames = []string{
|
||||||
_PostStageName[0:7],
|
_UserStatusName[0:7],
|
||||||
_PostStageName[7:17],
|
_UserStatusName[7:15],
|
||||||
_PostStageName[17:26],
|
_UserStatusName[15:22],
|
||||||
_PostStageName[26:33],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostStageNames returns a list of possible string values of PostStage.
|
// UserStatusNames returns a list of possible string values of UserStatus.
|
||||||
func PostStageNames() []string {
|
func UserStatusNames() []string {
|
||||||
tmp := make([]string, len(_PostStageNames))
|
tmp := make([]string, len(_UserStatusNames))
|
||||||
copy(tmp, _PostStageNames)
|
copy(tmp, _UserStatusNames)
|
||||||
return tmp
|
return tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostStageValues returns a list of the values for PostStage
|
// UserStatusValues returns a list of the values for UserStatus
|
||||||
func PostStageValues() []PostStage {
|
func UserStatusValues() []UserStatus {
|
||||||
return []PostStage{
|
return []UserStatus{
|
||||||
PostStagePending,
|
UserStatusPending,
|
||||||
PostStageProcessing,
|
UserStatusVerified,
|
||||||
PostStageCompleted,
|
UserStatusBlocked,
|
||||||
PostStageDeleted,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _PostStageMap = map[PostStage]string{
|
var _UserStatusMap = map[UserStatus]string{
|
||||||
PostStagePending: _PostStageName[0:7],
|
UserStatusPending: _UserStatusName[0:7],
|
||||||
PostStageProcessing: _PostStageName[7:17],
|
UserStatusVerified: _UserStatusName[7:15],
|
||||||
PostStageCompleted: _PostStageName[17:26],
|
UserStatusBlocked: _UserStatusName[15:22],
|
||||||
PostStageDeleted: _PostStageName[26:33],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the Stringer interface.
|
// String implements the Stringer interface.
|
||||||
func (x PostStage) String() string {
|
func (x UserStatus) String() string {
|
||||||
if str, ok := _PostStageMap[x]; ok {
|
if str, ok := _UserStatusMap[x]; ok {
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("PostStage(%d)", x)
|
return fmt.Sprintf("UserStatus(%d)", x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid provides a quick way to determine if the typed value is
|
// IsValid provides a quick way to determine if the typed value is
|
||||||
// part of the allowed enumerated values
|
// part of the allowed enumerated values
|
||||||
func (x PostStage) IsValid() bool {
|
func (x UserStatus) IsValid() bool {
|
||||||
_, ok := _PostStageMap[x]
|
_, ok := _UserStatusMap[x]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
var _PostStageValue = map[string]PostStage{
|
var _UserStatusValue = map[string]UserStatus{
|
||||||
_PostStageName[0:7]: PostStagePending,
|
_UserStatusName[0:7]: UserStatusPending,
|
||||||
_PostStageName[7:17]: PostStageProcessing,
|
_UserStatusName[7:15]: UserStatusVerified,
|
||||||
_PostStageName[17:26]: PostStageCompleted,
|
_UserStatusName[15:22]: UserStatusBlocked,
|
||||||
_PostStageName[26:33]: PostStageDeleted,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsePostStage attempts to convert a string to a PostStage.
|
// ParseUserStatus attempts to convert a string to a UserStatus.
|
||||||
func ParsePostStage(name string) (PostStage, error) {
|
func ParseUserStatus(name string) (UserStatus, error) {
|
||||||
if x, ok := _PostStageValue[name]; ok {
|
if x, ok := _UserStatusValue[name]; ok {
|
||||||
return x, nil
|
return x, nil
|
||||||
}
|
}
|
||||||
return PostStage(0), fmt.Errorf("%s is %w", name, ErrInvalidPostStage)
|
return UserStatus(0), fmt.Errorf("%s is %w", name, ErrInvalidUserStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
var errPostStageNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
var errUserStatusNilPtr = errors.New("value pointer is nil") // one per type for package clashes
|
||||||
|
|
||||||
// Scan implements the Scanner interface.
|
// Scan implements the Scanner interface.
|
||||||
func (x *PostStage) Scan(value interface{}) (err error) {
|
func (x *UserStatus) Scan(value interface{}) (err error) {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
*x = PostStage(0)
|
*x = UserStatus(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,72 +97,72 @@ func (x *PostStage) Scan(value interface{}) (err error) {
|
|||||||
// driver.Value values at the top of the list for expediency
|
// driver.Value values at the top of the list for expediency
|
||||||
switch v := value.(type) {
|
switch v := value.(type) {
|
||||||
case int64:
|
case int64:
|
||||||
*x = PostStage(v)
|
*x = UserStatus(v)
|
||||||
case string:
|
case string:
|
||||||
*x, err = ParsePostStage(v)
|
*x, err = ParseUserStatus(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try parsing the integer value as a string
|
// try parsing the integer value as a string
|
||||||
if val, verr := strconv.Atoi(v); verr == nil {
|
if val, verr := strconv.Atoi(v); verr == nil {
|
||||||
*x, err = PostStage(val), nil
|
*x, err = UserStatus(val), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case []byte:
|
case []byte:
|
||||||
*x, err = ParsePostStage(string(v))
|
*x, err = ParseUserStatus(string(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try parsing the integer value as a string
|
// try parsing the integer value as a string
|
||||||
if val, verr := strconv.Atoi(string(v)); verr == nil {
|
if val, verr := strconv.Atoi(string(v)); verr == nil {
|
||||||
*x, err = PostStage(val), nil
|
*x, err = UserStatus(val), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case PostStage:
|
case UserStatus:
|
||||||
*x = v
|
*x = v
|
||||||
case int:
|
case int:
|
||||||
*x = PostStage(v)
|
*x = UserStatus(v)
|
||||||
case *PostStage:
|
case *UserStatus:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x = *v
|
*x = *v
|
||||||
case uint:
|
case uint:
|
||||||
*x = PostStage(v)
|
*x = UserStatus(v)
|
||||||
case uint64:
|
case uint64:
|
||||||
*x = PostStage(v)
|
*x = UserStatus(v)
|
||||||
case *int:
|
case *int:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x = PostStage(*v)
|
*x = UserStatus(*v)
|
||||||
case *int64:
|
case *int64:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x = PostStage(*v)
|
*x = UserStatus(*v)
|
||||||
case float64: // json marshals everything as a float64 if it's a number
|
case float64: // json marshals everything as a float64 if it's a number
|
||||||
*x = PostStage(v)
|
*x = UserStatus(v)
|
||||||
case *float64: // json marshals everything as a float64 if it's a number
|
case *float64: // json marshals everything as a float64 if it's a number
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x = PostStage(*v)
|
*x = UserStatus(*v)
|
||||||
case *uint:
|
case *uint:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x = PostStage(*v)
|
*x = UserStatus(*v)
|
||||||
case *uint64:
|
case *uint64:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x = PostStage(*v)
|
*x = UserStatus(*v)
|
||||||
case *string:
|
case *string:
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return errPostStageNilPtr
|
return errUserStatusNilPtr
|
||||||
}
|
}
|
||||||
*x, err = ParsePostStage(*v)
|
*x, err = ParseUserStatus(*v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try parsing the integer value as a string
|
// try parsing the integer value as a string
|
||||||
if val, verr := strconv.Atoi(*v); verr == nil {
|
if val, verr := strconv.Atoi(*v); verr == nil {
|
||||||
*x, err = PostStage(val), nil
|
*x, err = UserStatus(val), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,529 +171,71 @@ func (x *PostStage) Scan(value interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
// Value implements the driver Valuer interface.
|
||||||
func (x PostStage) Value() (driver.Value, error) {
|
func (x UserStatus) Value() (driver.Value, error) {
|
||||||
return int64(x), nil
|
return int64(x), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set implements the Golang flag.Value interface func.
|
// Set implements the Golang flag.Value interface func.
|
||||||
func (x *PostStage) Set(val string) error {
|
func (x *UserStatus) Set(val string) error {
|
||||||
v, err := ParsePostStage(val)
|
v, err := ParseUserStatus(val)
|
||||||
*x = v
|
*x = v
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get implements the Golang flag.Getter interface func.
|
// Get implements the Golang flag.Getter interface func.
|
||||||
func (x *PostStage) Get() interface{} {
|
func (x *UserStatus) Get() interface{} {
|
||||||
return *x
|
return *x
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type implements the github.com/spf13/pFlag Value interface.
|
// Type implements the github.com/spf13/pFlag Value interface.
|
||||||
func (x *PostStage) Type() string {
|
func (x *UserStatus) Type() string {
|
||||||
return "PostStage"
|
return "UserStatus"
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullPostStage struct {
|
type NullUserStatus struct {
|
||||||
PostStage PostStage
|
UserStatus UserStatus
|
||||||
Valid bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNullPostStage(val interface{}) (x NullPostStage) {
|
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan implements the Scanner interface.
|
|
||||||
func (x *NullPostStage) Scan(value interface{}) (err error) {
|
|
||||||
if value == nil {
|
|
||||||
x.PostStage, x.Valid = PostStage(0), false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = x.PostStage.Scan(value)
|
|
||||||
x.Valid = (err == nil)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
|
||||||
func (x NullPostStage) Value() (driver.Value, error) {
|
|
||||||
if !x.Valid {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
// driver.Value accepts int64 for int values.
|
|
||||||
return int64(x.PostStage), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type NullPostStageStr struct {
|
|
||||||
NullPostStage
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewNullPostStageStr(val interface{}) (x NullPostStageStr) {
|
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
|
||||||
func (x NullPostStageStr) Value() (driver.Value, error) {
|
|
||||||
if !x.Valid {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return x.PostStage.String(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
// PostStatusPending is a PostStatus of type Pending.
|
|
||||||
PostStatusPending PostStatus = iota
|
|
||||||
// PostStatusVerified is a PostStatus of type Verified.
|
|
||||||
PostStatusVerified
|
|
||||||
// PostStatusBlocked is a PostStatus of type Blocked.
|
|
||||||
PostStatusBlocked
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrInvalidPostStatus = fmt.Errorf("not a valid PostStatus, try [%s]", strings.Join(_PostStatusNames, ", "))
|
|
||||||
|
|
||||||
const _PostStatusName = "PendingVerifiedBlocked"
|
|
||||||
|
|
||||||
var _PostStatusNames = []string{
|
|
||||||
_PostStatusName[0:7],
|
|
||||||
_PostStatusName[7:15],
|
|
||||||
_PostStatusName[15:22],
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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{
|
|
||||||
PostStatusPending,
|
|
||||||
PostStatusVerified,
|
|
||||||
PostStatusBlocked,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var _PostStatusMap = map[PostStatus]string{
|
|
||||||
PostStatusPending: _PostStatusName[0:7],
|
|
||||||
PostStatusVerified: _PostStatusName[7:15],
|
|
||||||
PostStatusBlocked: _PostStatusName[15:22],
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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:7]: PostStatusPending,
|
|
||||||
_PostStatusName[7:15]: PostStatusVerified,
|
|
||||||
_PostStatusName[15:22]: PostStatusBlocked,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
Valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNullPostStatus(val interface{}) (x NullPostStatus) {
|
func NewNullUserStatus(val interface{}) (x NullUserStatus) {
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan implements the Scanner interface.
|
// Scan implements the Scanner interface.
|
||||||
func (x *NullPostStatus) Scan(value interface{}) (err error) {
|
func (x *NullUserStatus) Scan(value interface{}) (err error) {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
x.PostStatus, x.Valid = PostStatus(0), false
|
x.UserStatus, x.Valid = UserStatus(0), false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = x.PostStatus.Scan(value)
|
err = x.UserStatus.Scan(value)
|
||||||
x.Valid = (err == nil)
|
x.Valid = (err == nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
// Value implements the driver Valuer interface.
|
||||||
func (x NullPostStatus) Value() (driver.Value, error) {
|
func (x NullUserStatus) Value() (driver.Value, error) {
|
||||||
if !x.Valid {
|
if !x.Valid {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
// driver.Value accepts int64 for int values.
|
// driver.Value accepts int64 for int values.
|
||||||
return int64(x.PostStatus), nil
|
return int64(x.UserStatus), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullPostStatusStr struct {
|
type NullUserStatusStr struct {
|
||||||
NullPostStatus
|
NullUserStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNullPostStatusStr(val interface{}) (x NullPostStatusStr) {
|
func NewNullUserStatusStr(val interface{}) (x NullUserStatusStr) {
|
||||||
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value implements the driver Valuer interface.
|
// Value implements the driver Valuer interface.
|
||||||
func (x NullPostStatusStr) Value() (driver.Value, error) {
|
func (x NullUserStatusStr) Value() (driver.Value, error) {
|
||||||
if !x.Valid {
|
if !x.Valid {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return x.PostStatus.String(), nil
|
return x.UserStatus.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
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
package fields
|
package fields
|
||||||
|
|
||||||
// swagger:enum PostStage
|
// swagger:enum UserStatus
|
||||||
// ENUM( Pending, Processing, Completed, Deleted)
|
|
||||||
type PostStage int16
|
|
||||||
|
|
||||||
// swagger:enum PostStatus
|
|
||||||
// ENUM( Pending, Verified, Blocked)
|
// ENUM( Pending, Verified, Blocked)
|
||||||
type PostStatus int16
|
type UserStatus int16
|
||||||
|
|
||||||
// swagger:enum PostType
|
|
||||||
// ENUM( Article, Picture, Video, Audio)
|
|
||||||
type PostType int16
|
|
||||||
|
|||||||
Reference in New Issue
Block a user