github.com/infraboard/keyauth@v0.8.1/apps/verifycode/enum.pb_enum_generate.go (about)

     1  // Code generated by github.com/infraboard/mcube
     2  // DO NOT EDIT
     3  
     4  package verifycode
     5  
     6  import (
     7  	"bytes"
     8  	"fmt"
     9  	"strings"
    10  )
    11  
    12  // ParseNotifyTypeFromString Parse NotifyType from string
    13  func ParseNotifyTypeFromString(str string) (NotifyType, error) {
    14  	key := strings.Trim(string(str), `"`)
    15  	v, ok := NotifyType_value[strings.ToUpper(key)]
    16  	if !ok {
    17  		return 0, fmt.Errorf("unknown NotifyType: %s", str)
    18  	}
    19  
    20  	return NotifyType(v), nil
    21  }
    22  
    23  // Equal type compare
    24  func (t NotifyType) Equal(target NotifyType) bool {
    25  	return t == target
    26  }
    27  
    28  // IsIn todo
    29  func (t NotifyType) IsIn(targets ...NotifyType) bool {
    30  	for _, target := range targets {
    31  		if t.Equal(target) {
    32  			return true
    33  		}
    34  	}
    35  
    36  	return false
    37  }
    38  
    39  // MarshalJSON todo
    40  func (t NotifyType) MarshalJSON() ([]byte, error) {
    41  	b := bytes.NewBufferString(`"`)
    42  	b.WriteString(strings.ToUpper(t.String()))
    43  	b.WriteString(`"`)
    44  	return b.Bytes(), nil
    45  }
    46  
    47  // UnmarshalJSON todo
    48  func (t *NotifyType) UnmarshalJSON(b []byte) error {
    49  	ins, err := ParseNotifyTypeFromString(string(b))
    50  	if err != nil {
    51  		return err
    52  	}
    53  	*t = ins
    54  	return nil
    55  }
    56  
    57  // ParseIssueTypeFromString Parse IssueType from string
    58  func ParseIssueTypeFromString(str string) (IssueType, error) {
    59  	key := strings.Trim(string(str), `"`)
    60  	v, ok := IssueType_value[strings.ToUpper(key)]
    61  	if !ok {
    62  		return 0, fmt.Errorf("unknown IssueType: %s", str)
    63  	}
    64  
    65  	return IssueType(v), nil
    66  }
    67  
    68  // Equal type compare
    69  func (t IssueType) Equal(target IssueType) bool {
    70  	return t == target
    71  }
    72  
    73  // IsIn todo
    74  func (t IssueType) IsIn(targets ...IssueType) bool {
    75  	for _, target := range targets {
    76  		if t.Equal(target) {
    77  			return true
    78  		}
    79  	}
    80  
    81  	return false
    82  }
    83  
    84  // MarshalJSON todo
    85  func (t IssueType) MarshalJSON() ([]byte, error) {
    86  	b := bytes.NewBufferString(`"`)
    87  	b.WriteString(strings.ToUpper(t.String()))
    88  	b.WriteString(`"`)
    89  	return b.Bytes(), nil
    90  }
    91  
    92  // UnmarshalJSON todo
    93  func (t *IssueType) UnmarshalJSON(b []byte) error {
    94  	ins, err := ParseIssueTypeFromString(string(b))
    95  	if err != nil {
    96  		return err
    97  	}
    98  	*t = ins
    99  	return nil
   100  }