forked from go-sonic/sonic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum.go
1018 lines (912 loc) · 21.8 KB
/
enum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package consts
import (
"database/sql/driver"
"strconv"
"strings"
"github.com/go-sonic/sonic/util/xerr"
)
type DBType string
const (
DBTypeMySQL = "MySQL"
DBTypeSQLite = "SQLite"
)
type AttachmentType int32
const (
AttachmentTypeLocal AttachmentType = iota
// AttachmentTypeUpOSS 又拍云
AttachmentTypeUpOSS
// AttachmentTypeQiNiuOSS 七牛云
AttachmentTypeQiNiuOSS
// AttachmentTypeSMMS sm.ms
AttachmentTypeSMMS
// AttachmentTypeAliOSS 阿里云OSS
AttachmentTypeAliOSS
// AttachmentTypeBaiDuOSS 百度云OSS
AttachmentTypeBaiDuOSS
// AttachmentTypeTencentCOS 腾讯COS
AttachmentTypeTencentCOS
// AttachmentTypeHuaweiOBS 华为OBS
AttachmentTypeHuaweiOBS
// AttachmentTypeMinIO AttachmentTypeMinIO
AttachmentTypeMinIO
)
func (a AttachmentType) String() string {
switch a {
case AttachmentTypeLocal:
return "LOCAL"
case AttachmentTypeUpOSS:
return "UPOSS"
case AttachmentTypeQiNiuOSS:
return "QINIUOSS"
case AttachmentTypeSMMS:
return "AttachmentTypeSMMS"
case AttachmentTypeAliOSS:
return "ALIOSS"
case AttachmentTypeBaiDuOSS:
return "BAIDUOSS"
case AttachmentTypeTencentCOS:
return "TENCENTOSS"
case AttachmentTypeHuaweiOBS:
return "HUAWEIOBS"
case AttachmentTypeMinIO:
return "MINIO"
default:
return "UNKNOWN"
}
}
func (a AttachmentType) MarshalJSON() ([]byte, error) {
switch a {
case AttachmentTypeLocal:
return []byte(`"LOCAL"`), nil
case AttachmentTypeUpOSS:
return []byte(`"UPOSS"`), nil
case AttachmentTypeQiNiuOSS:
return []byte(`"QINIUOSS"`), nil
case AttachmentTypeSMMS:
return []byte(`"AttachmentTypeSMMS"`), nil
case AttachmentTypeAliOSS:
return []byte(`"ALIOSS"`), nil
case AttachmentTypeBaiDuOSS:
return []byte(`"BAIDUOSS"`), nil
case AttachmentTypeTencentCOS:
return []byte(`"TENCENTOSS"`), nil
case AttachmentTypeHuaweiOBS:
return []byte(`"HUAWEIOBS"`), nil
case AttachmentTypeMinIO:
return []byte(`"MINIO"`), nil
default:
return []byte(`"UNKNOWN"`), nil
}
}
func (a *AttachmentType) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"LOCAL"`:
*a = AttachmentTypeLocal
case `"UPOSS"`:
*a = AttachmentTypeUpOSS
case `"QINIUOSS"`:
*a = AttachmentTypeQiNiuOSS
case `"AttachmentTypeSMMS"`:
*a = AttachmentTypeSMMS
case `"ALIOSS"`:
*a = AttachmentTypeAliOSS
case `"BAIDUBOS"`:
*a = AttachmentTypeBaiDuOSS
case `"TENCENTCOS"`:
*a = AttachmentTypeTencentCOS
case `"HUAWEIOBS"`:
*a = AttachmentTypeHuaweiOBS
case `"MINIO"`:
*a = AttachmentTypeMinIO
default:
return xerr.BadParam.New("").WithMsg("unknown AttachmentType")
}
return nil
}
func (a *AttachmentType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*a = AttachmentType(data)
case int32:
*a = AttachmentType(data)
case int:
*a = AttachmentType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (a AttachmentType) Value() (driver.Value, error) {
return int64(a), nil
}
type LogType int32
const (
LogTypeBlogInitialized LogType = iota
LogTypePostPublished
LogTypePostEdited
LogTypePostDeleted
LogTypeLoggedIn
LogTypeLoggedOut
LogTypeLoginFailed
LogTypePasswordUpdated
LogTypeProfileUpdated
LogTypeSheetPublished
LogTypeSheetEdited
LogTypeSheetDeleted
LogTypeMfaUpdated
LogTypeLoggedPreCheck
)
func (l LogType) MarshalJSON() ([]byte, error) {
switch l {
case LogTypeBlogInitialized:
return []byte(`"BLOG_INITIALIZED"`), nil
case LogTypePostPublished:
return []byte(`"POST_PUBLISHED"`), nil
case LogTypePostEdited:
return []byte(`"POST_EDITED"`), nil
case LogTypePostDeleted:
return []byte(`"POST_DELETED"`), nil
case LogTypeLoggedIn:
return []byte(`"LOGGED_IN"`), nil
case LogTypeLoggedOut:
return []byte(`"LOGGED_OUT"`), nil
case LogTypeLoginFailed:
return []byte(`"LOGIN_FAILED"`), nil
case LogTypePasswordUpdated:
return []byte(`"PASSWORD_UPDATED"`), nil
case LogTypeProfileUpdated:
return []byte(`"PROFILE_UPDATED"`), nil
case LogTypeSheetPublished:
return []byte(`"SHEET_PUBLISHED"`), nil
case LogTypeSheetEdited:
return []byte(`"SHEET_EDITED"`), nil
case LogTypeSheetDeleted:
return []byte(`"SHEET_DELETED"`), nil
case LogTypeMfaUpdated:
return []byte(`"MFA_UPDATED"`), nil
case LogTypeLoggedPreCheck:
return []byte(`"LOGGED_PRE_CHECK"`), nil
}
return nil, nil
}
func (l *LogType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*l = LogType(data)
case int32:
*l = LogType(data)
case int:
*l = LogType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (l LogType) Value() (driver.Value, error) {
return int64(l), nil
}
type MFAType int32
const (
MFANone MFAType = iota
// MFATFATotp Time-based One-time Password (rfc6238).
// see: https://tools.ietf.org/html/rfc6238
MFATFATotp
)
func (m MFAType) MarshalJSON() ([]byte, error) {
if m == MFANone {
return []byte(`"NONE"`), nil
} else if m == MFATFATotp {
return []byte(`"TFA_TOTP"`), nil
}
return nil, nil
}
func (m *MFAType) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"NONE"`:
*m = MFANone
case `"TFA_TOTP"`:
*m = MFATFATotp
default:
return xerr.BadParam.New("").WithMsg("unknown MFAType")
}
return nil
}
func (m *MFAType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*m = MFAType(data)
case int32:
*m = MFAType(data)
case int:
*m = MFAType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (m MFAType) Value() (driver.Value, error) {
return int64(m), nil
}
type PostStatus int32
const (
PostStatusPublished PostStatus = iota
PostStatusDraft
PostStatusRecycle
PostStatusIntimate
)
func (c PostStatus) MarshalJSON() ([]byte, error) {
switch c {
case PostStatusPublished:
return []byte(`"PUBLISHED"`), nil
case PostStatusDraft:
return []byte(`"DRAFT"`), nil
case PostStatusRecycle:
return []byte(`"RECYCLE"`), nil
case PostStatusIntimate:
return []byte(`"INTIMATE"`), nil
}
return nil, nil
}
func (c *PostStatus) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"PUBLISHED"`:
*c = PostStatusPublished
case `"DRAFT"`:
*c = PostStatusDraft
case `"RECYCLE"`:
*c = PostStatusRecycle
case `"INTIMATE"`:
*c = PostStatusIntimate
case "":
*c = PostStatusDraft
default:
return xerr.BadParam.New("").WithMsg("unknown PostStatus")
}
return nil
}
func (c *PostStatus) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*c = PostStatus(data)
case int32:
*c = PostStatus(data)
case int:
*c = PostStatus(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (c PostStatus) Value() (driver.Value, error) {
return int64(c), nil
}
func (c PostStatus) Ptr() *PostStatus {
return &c
}
func PostStatusFromString(str string) (PostStatus, error) {
switch str {
case "PUBLISHED":
return PostStatusPublished, nil
case "DRAFT":
return PostStatusDraft, nil
case "RECYCLE":
return PostStatusRecycle, nil
case "INTIMATE":
return PostStatusIntimate, nil
default:
return PostStatusDraft, xerr.BadParam.New("").WithMsg("unknown PostStatus")
}
}
type CommentStatus int32
const (
CommentStatusPublished CommentStatus = iota
CommentStatusAuditing
CommentStatusRecycle
)
func (c CommentStatus) MarshalJSON() ([]byte, error) {
switch c {
case CommentStatusPublished:
return []byte(`"PUBLISHED"`), nil
case CommentStatusAuditing:
return []byte(`"AUDITING"`), nil
case CommentStatusRecycle:
return []byte(`"RECYCLE"`), nil
}
return nil, nil
}
func (c *CommentStatus) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"PUBLISHED"`:
*c = CommentStatusPublished
case `"AUDITING"`:
*c = CommentStatusAuditing
case `"RECYCLE"`:
*c = CommentStatusRecycle
default:
return xerr.BadParam.New("").WithMsg("unknown CommentStatus")
}
return nil
}
func (c *CommentStatus) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*c = CommentStatus(data)
case int32:
*c = CommentStatus(data)
case int:
*c = CommentStatus(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func CommentStatusFromString(str string) (CommentStatus, error) {
switch str {
case "PUBLISHED":
return CommentStatusPublished, nil
case "AUDITING":
return CommentStatusAuditing, nil
case "RECYCLE":
return CommentStatusRecycle, nil
default:
return CommentStatusPublished, xerr.BadParam.New("").WithMsg("unknown CommentStatus")
}
}
func (c CommentStatus) Value() (driver.Value, error) {
return int64(c), nil
}
func (c CommentStatus) Ptr() *CommentStatus {
return &c
}
type PostPermalinkType string
const (
PostPermalinkTypeDefault PostPermalinkType = "DEFAULT"
PostPermalinkTypeDate PostPermalinkType = "DATE"
PostPermalinkTypeDay PostPermalinkType = "DAY"
PostPermalinkTypeID PostPermalinkType = "ID"
PostPermalinkTypeYear PostPermalinkType = "YEAR"
PostPermalinkTypeIDSlug PostPermalinkType = "ID_SLUG"
)
type EditorType int32
const (
EditorTypeMarkdown EditorType = iota
EditorTypeRichText
)
func (e EditorType) Ptr() *EditorType {
return &e
}
func (e *EditorType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*e = EditorType(data)
case int32:
*e = EditorType(data)
case int:
*e = EditorType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (e EditorType) Value() (driver.Value, error) {
return int64(e), nil
}
func (e EditorType) MarshalJSON() ([]byte, error) {
if e == EditorTypeMarkdown {
return []byte(`"MARKDOWN"`), nil
} else if e == EditorTypeRichText {
return []byte(`"RICHTEXT"`), nil
}
return nil, nil
}
func (e *EditorType) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"MARKDOWN"`:
*e = EditorTypeMarkdown
case `"RICHTEXT"`:
*e = EditorTypeRichText
case "":
*e = EditorTypeMarkdown
default:
return xerr.BadParam.New("").WithMsg("unknown editorType")
}
return nil
}
type OptionType int32
const (
OptionTypeInternal = iota
OptionTypeCustom
)
func (o OptionType) MarshalJSON() ([]byte, error) {
if o == OptionTypeInternal {
return []byte(`"INTERNAL"`), nil
} else if o == OptionTypeCustom {
return []byte(`"CUSTOM"`), nil
}
return nil, nil
}
func (o *OptionType) UnmarshalJSON(data []byte) error {
switch string(data) {
case `"INTERNAL"`:
*o = OptionTypeInternal
case `"CUSTOM"`:
*o = OptionTypeCustom
default:
return xerr.BadParam.New("").WithMsg("unknown OptionType")
}
return nil
}
func (o *OptionType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*o = OptionType(data)
case int32:
*o = OptionType(data)
case int:
*o = OptionType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (o OptionType) Value() (driver.Value, error) {
return int64(o), nil
}
type PostType int32
const (
PostTypePost PostType = iota
PostTypeSheet
)
func (p *PostType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*p = PostType(data)
case int32:
*p = PostType(data)
case int:
*p = PostType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (p PostType) Value() (driver.Value, error) {
return int64(p), nil
}
type CommentType int32
const (
CommentTypePost CommentType = iota
CommentTypeSheet
CommentTypeJournal
)
func (ct *CommentType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("unknown OptionType")
}
switch data := src.(type) {
case int64:
*ct = CommentType(data)
case int32:
*ct = CommentType(data)
case int:
*ct = CommentType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (ct CommentType) Value() (driver.Value, error) {
return int64(ct), nil
}
type SheetPermaLinkType string
const (
SheetPermaLinkTypeSecondary = "SECONDARY"
SheetPermaLinkTypeRoot = "ROOT"
)
type JournalType int32
const (
JournalTypePublic JournalType = iota
JournalTypeIntimate
)
func (j JournalType) Ptr() *JournalType {
return &j
}
func (j JournalType) MarshalJSON() ([]byte, error) {
if j == JournalTypePublic {
return []byte(`"PUBLIC"`), nil
} else if j == JournalTypeIntimate {
return []byte(`"INTIMATE"`), nil
}
return nil, nil
}
func (j *JournalType) UnmarshalJSON(data []byte) error {
switch string(data) {
case `"PUBLIC"`:
*j = JournalTypePublic
case `"INTIMATE"`:
*j = JournalTypeIntimate
default:
return xerr.BadParam.New("").WithMsg("unknown JournalType")
}
return nil
}
func (j *JournalType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*j = JournalType(data)
case int32:
*j = JournalType(data)
case int:
*j = JournalType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (j JournalType) Value() (driver.Value, error) {
return int64(j), nil
}
type MetaType int32
const (
MetaTypePost = iota
MetaTypeSheet = iota
)
func (m *MetaType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64:
*m = MetaType(data)
case int32:
*m = MetaType(data)
case int:
*m = MetaType(data)
default:
return xerr.BadParam.New("").WithMsg("bad type")
}
return nil
}
func (m MetaType) Value() (driver.Value, error) {
return int64(m), nil
}
type ThemeUpdateStrategy int32
const (
ThemeUpdateStrategyBranch = iota
ThemeUpdateStrategyRelease
)
type ThemeConfigInputType int32
const (
// ThemeConfigInputTypeTEXT Text input type
ThemeConfigInputTypeTEXT = iota
// ThemeConfigInputTypeNUMBER Number input type
ThemeConfigInputTypeNUMBER
// ThemeConfigInputTypeRADIO Radio box input type
ThemeConfigInputTypeRADIO
// ThemeConfigInputTypeSELECT Select input type
ThemeConfigInputTypeSELECT
// ThemeConfigInputTypeTEXTAREA Textarea input type
ThemeConfigInputTypeTEXTAREA
// ThemeConfigInputTypeCOLOR Color picker input type
ThemeConfigInputTypeCOLOR
// ThemeConfigInputTypeATTACHMENT Attachment picker input type
ThemeConfigInputTypeATTACHMENT
// ThemeConfigInputTypeSWITCH Switch input type, only true or false
ThemeConfigInputTypeSWITCH
)
func (t ThemeConfigInputType) MarshalJSON() ([]byte, error) {
switch t {
case ThemeConfigInputTypeTEXT:
return []byte(`"TEXT"`), nil
case ThemeConfigInputTypeNUMBER:
return []byte(`"NUMBER"`), nil
case ThemeConfigInputTypeRADIO:
return []byte(`"RADIO"`), nil
case ThemeConfigInputTypeSELECT:
return []byte(`"SELECT"`), nil
case ThemeConfigInputTypeTEXTAREA:
return []byte(`"TEXTAREA"`), nil
case ThemeConfigInputTypeCOLOR:
return []byte(`"COLOR"`), nil
case ThemeConfigInputTypeATTACHMENT:
return []byte(`"ATTACHMENT"`), nil
case ThemeConfigInputTypeSWITCH:
return []byte(`"SWITCH"`), nil
default:
return nil, xerr.BadParam.New("").WithMsg("unknown ThemeConfigInputType")
}
}
func (t *ThemeConfigInputType) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"TEXT"`:
*t = ThemeConfigInputTypeTEXT
return nil
case `"NUMBER"`:
*t = ThemeConfigInputTypeNUMBER
return nil
case `"RADIO"`:
*t = ThemeConfigInputTypeRADIO
return nil
case `"SELECT"`:
*t = ThemeConfigInputTypeSELECT
return nil
case `"TEXTAREA"`:
*t = ThemeConfigInputTypeTEXTAREA
return nil
case `"COLOR"`:
*t = ThemeConfigInputTypeCOLOR
return nil
case `"SWITCH"`:
*t = ThemeConfigInputTypeSWITCH
return nil
case `"ATTACHMENT"`:
*t = ThemeConfigInputTypeATTACHMENT
return nil
default:
return xerr.BadParam.New("").WithMsg("unknown ThemeConfigInputType")
}
}
func (t *ThemeConfigInputType) UnmarshalYAML(unmarshal func(interface{}) error) error {
strType := ""
err := unmarshal(&strType)
if err != nil {
return xerr.BadParam.New("").WithMsg("ThemeConfigInputType yaml unmarshal err")
}
strType = strings.ToUpper(strType)
switch strType {
case "TEXT":
*t = ThemeConfigInputTypeTEXT
return nil
case "NUMBER":
*t = ThemeConfigInputTypeNUMBER
return nil
case "RADIO":
*t = ThemeConfigInputTypeRADIO
return nil
case "SELECT":
*t = ThemeConfigInputTypeSELECT
return nil
case "TEXTAREA":
*t = ThemeConfigInputTypeTEXTAREA
return nil
case "COLOR":
*t = ThemeConfigInputTypeCOLOR
return nil
case "SWITCH":
*t = ThemeConfigInputTypeSWITCH
return nil
case "ATTACHMENT":
*t = ThemeConfigInputTypeATTACHMENT
return nil
default:
return xerr.BadParam.New("").WithMsg("unknown ThemeConfigInputType")
}
}
type ThemeConfigDataType int32
const (
ThemeConfigDataTypeString ThemeConfigDataType = iota
ThemeConfigDataTypeLong
ThemeConfigDataTypeDouble
ThemeConfigDataTypeBool
)
func (t ThemeConfigDataType) Convert(value string) (interface{}, error) {
switch t {
case ThemeConfigDataTypeString:
return value, nil
case ThemeConfigDataTypeLong:
result, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return nil, xerr.WithErrMsgf(err, "value invalid ThemeConfigDataType")
}
return result, nil
case ThemeConfigDataTypeDouble:
result, err := strconv.ParseFloat(value, 64)
if err != nil {
return nil, xerr.WithErrMsgf(err, "value invalid ThemeConfigDataType")
}
return result, nil
case ThemeConfigDataTypeBool:
result, err := strconv.ParseBool(value)
if err != nil {
return nil, xerr.WithErrMsgf(err, "value invalid ThemeConfigDataType")
}
return result, nil
default:
return nil, xerr.WithErrMsgf(nil, "invalid ThemeConfigDataType")
}
}
func (t ThemeConfigDataType) FormatToStr(value interface{}) (string, error) {
switch t {
case ThemeConfigDataTypeString:
valueStr, ok := value.(string)
if !ok {
return "", xerr.WithErrMsgf(nil, "value invalid ThemeConfigDataType")
}
return valueStr, nil
case ThemeConfigDataTypeLong:
var valueStr string
switch data := value.(type) {
case int:
valueStr = strconv.FormatInt(int64(data), 10)
case int64:
valueStr = strconv.FormatInt(data, 10)
case int32:
valueStr = strconv.FormatInt(int64(data), 10)
default:
return "", xerr.WithErrMsgf(nil, "value invalid ThemeConfigDataType")
}
return valueStr, nil
case ThemeConfigDataTypeDouble:
var valueStr string
switch data := value.(type) {
case float32:
valueStr = strconv.FormatFloat(float64(data), 'f', 5, 32)
case float64:
valueStr = strconv.FormatFloat(data, 'f', 5, 64)
default:
return "", xerr.WithErrMsgf(nil, "value invalid ThemeConfigDataType")
}
return valueStr, nil
case ThemeConfigDataTypeBool:
var valueStr string
switch data := value.(type) {
case bool:
valueStr = strconv.FormatBool(data)
default:
return "", xerr.WithErrMsgf(nil, "value invalid ThemeConfigDataType")
}
return valueStr, nil
default:
return "", xerr.WithErrMsgf(nil, "invalid ThemeConfigDataType")
}
}
func (t ThemeConfigDataType) MarshalJSON() ([]byte, error) {
switch t {
case ThemeConfigDataTypeString:
return []byte(`"STRING"`), nil
case ThemeConfigDataTypeLong:
return []byte(`"LONG"`), nil
case ThemeConfigDataTypeDouble:
return []byte(`"DOUBLE"`), nil
case ThemeConfigDataTypeBool:
return []byte(`"BOOL"`), nil
default:
return nil, xerr.BadParam.New("").WithMsg("unknown ThemeConfigDataType")
}
}
func (t *ThemeConfigDataType) UnmarshalJSON(data []byte) error {
str := string(data)
switch str {
case `"STRING"`:
*t = ThemeConfigDataTypeString
return nil
case `"LONG"`:
*t = ThemeConfigDataTypeLong
return nil
case `"DOUBLE"`:
*t = ThemeConfigDataTypeDouble
return nil
case `"BOOL"`:
*t = ThemeConfigDataTypeBool
return nil
default:
return xerr.BadParam.New("").WithMsg("unknown ThemeConfigInputType")
}
}
func (t *ThemeConfigDataType) UnmarshalYAML(unmarshal func(interface{}) error) error {
strType := ""
err := unmarshal(&strType)
if err != nil {
return xerr.BadParam.New("").WithMsg("ThemeConfigDataType yaml unmarshal err")
}
strType = strings.ToUpper(strType)
switch strType {
case "STRING":
*t = ThemeConfigDataTypeString
return nil
case "LONG":
*t = ThemeConfigDataTypeLong
return nil
case "DOUBLE":
*t = ThemeConfigDataTypeDouble
return nil
case "BOOL":
*t = ThemeConfigDataTypeBool
return nil
default:
return xerr.BadParam.New("").WithMsg("unknown ThemeConfigDataType")
}
}
type EncryptType int32
const (
EncryptTypePost EncryptType = iota
EncryptTypeCategory
)
func (e EncryptType) Name() string {
if e == EncryptTypePost {
return "post"
}
if e == EncryptTypeCategory {
return "category"
}
return ""
}
type CategoryType int32
const (
CategoryTypeNormal CategoryType = iota
CategoryTypeIntimate
)
func (c CategoryType) MarshalJSON() ([]byte, error) {
if c == CategoryTypeNormal {
return []byte(`"NORMAL"`), nil
} else if c == CategoryTypeIntimate {
return []byte(`"INTIMATE"`), nil
}
return nil, nil
}
func (c *CategoryType) UnmarshalJSON(data []byte) error {
switch string(data) {
case `"NORMAL"`:
*c = CategoryTypeNormal
case `"INTIMATE"`:
*c = CategoryTypeIntimate
default:
return xerr.BadParam.New("").WithMsg("unknown PostStatus")
}
return nil
}
func (c *CategoryType) Scan(src interface{}) error {
if src == nil {
return xerr.BadParam.New("").WithMsg("field nil")
}
switch data := src.(type) {
case int64: