github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/enums/api_operator_attr__generated.go (about)

     1  // This is a generated source file. DO NOT EDIT
     2  // Source: enums/api_operator_attr__generated.go
     3  
     4  package enums
     5  
     6  import (
     7  	"bytes"
     8  	"database/sql/driver"
     9  	"errors"
    10  
    11  	"github.com/machinefi/w3bstream/pkg/depends/kit/enum"
    12  )
    13  
    14  var InvalidApiOperatorAttr = errors.New("invalid ApiOperatorAttr type")
    15  
    16  func ParseApiOperatorAttrFromString(s string) (ApiOperatorAttr, error) {
    17  	switch s {
    18  	default:
    19  		return API_OPERATOR_ATTR_UNKNOWN, InvalidApiOperatorAttr
    20  	case "":
    21  		return API_OPERATOR_ATTR_UNKNOWN, nil
    22  	case "COMMON":
    23  		return API_OPERATOR_ATTR__COMMON, nil
    24  	case "INTERNAL":
    25  		return API_OPERATOR_ATTR__INTERNAL, nil
    26  	case "ADMIN_ONLY":
    27  		return API_OPERATOR_ATTR__ADMIN_ONLY, nil
    28  	case "PUBLIC":
    29  		return API_OPERATOR_ATTR__PUBLIC, nil
    30  	}
    31  }
    32  
    33  func ParseApiOperatorAttrFromLabel(s string) (ApiOperatorAttr, error) {
    34  	switch s {
    35  	default:
    36  		return API_OPERATOR_ATTR_UNKNOWN, InvalidApiOperatorAttr
    37  	case "":
    38  		return API_OPERATOR_ATTR_UNKNOWN, nil
    39  	case "common operator for all users with authorization, used for default attr":
    40  		return API_OPERATOR_ATTR__COMMON, nil
    41  	case "internal for debugging or maintaining only":
    42  		return API_OPERATOR_ATTR__INTERNAL, nil
    43  	case "only admin can access":
    44  		return API_OPERATOR_ATTR__ADMIN_ONLY, nil
    45  	case "can access without authorization":
    46  		return API_OPERATOR_ATTR__PUBLIC, nil
    47  	}
    48  }
    49  
    50  func (v ApiOperatorAttr) Int() int {
    51  	return int(v)
    52  }
    53  
    54  func (v ApiOperatorAttr) String() string {
    55  	switch v {
    56  	default:
    57  		return "UNKNOWN"
    58  	case API_OPERATOR_ATTR_UNKNOWN:
    59  		return ""
    60  	case API_OPERATOR_ATTR__COMMON:
    61  		return "COMMON"
    62  	case API_OPERATOR_ATTR__INTERNAL:
    63  		return "INTERNAL"
    64  	case API_OPERATOR_ATTR__ADMIN_ONLY:
    65  		return "ADMIN_ONLY"
    66  	case API_OPERATOR_ATTR__PUBLIC:
    67  		return "PUBLIC"
    68  	}
    69  }
    70  
    71  func (v ApiOperatorAttr) Label() string {
    72  	switch v {
    73  	default:
    74  		return "UNKNOWN"
    75  	case API_OPERATOR_ATTR_UNKNOWN:
    76  		return ""
    77  	case API_OPERATOR_ATTR__COMMON:
    78  		return "common operator for all users with authorization, used for default attr"
    79  	case API_OPERATOR_ATTR__INTERNAL:
    80  		return "internal for debugging or maintaining only"
    81  	case API_OPERATOR_ATTR__ADMIN_ONLY:
    82  		return "only admin can access"
    83  	case API_OPERATOR_ATTR__PUBLIC:
    84  		return "can access without authorization"
    85  	}
    86  }
    87  
    88  func (v ApiOperatorAttr) TypeName() string {
    89  	return "github.com/machinefi/w3bstream/pkg/enums.ApiOperatorAttr"
    90  }
    91  
    92  func (v ApiOperatorAttr) ConstValues() []enum.IntStringerEnum {
    93  	return []enum.IntStringerEnum{API_OPERATOR_ATTR__COMMON, API_OPERATOR_ATTR__INTERNAL, API_OPERATOR_ATTR__ADMIN_ONLY, API_OPERATOR_ATTR__PUBLIC}
    94  }
    95  
    96  func (v ApiOperatorAttr) MarshalText() ([]byte, error) {
    97  	s := v.String()
    98  	if s == "UNKNOWN" {
    99  		return nil, InvalidApiOperatorAttr
   100  	}
   101  	return []byte(s), nil
   102  }
   103  
   104  func (v *ApiOperatorAttr) UnmarshalText(data []byte) error {
   105  	s := string(bytes.ToUpper(data))
   106  	val, err := ParseApiOperatorAttrFromString(s)
   107  	if err != nil {
   108  		return err
   109  	}
   110  	*(v) = val
   111  	return nil
   112  }
   113  
   114  func (v *ApiOperatorAttr) Scan(src interface{}) error {
   115  	offset := 0
   116  	o, ok := interface{}(v).(enum.ValueOffset)
   117  	if ok {
   118  		offset = o.Offset()
   119  	}
   120  	i, err := enum.ScanIntEnumStringer(src, offset)
   121  	if err != nil {
   122  		return err
   123  	}
   124  	*(v) = ApiOperatorAttr(i)
   125  	return nil
   126  }
   127  
   128  func (v ApiOperatorAttr) Value() (driver.Value, error) {
   129  	offset := 0
   130  	o, ok := interface{}(v).(enum.ValueOffset)
   131  	if ok {
   132  		offset = o.Offset()
   133  	}
   134  	return int64(v) + int64(offset), nil
   135  }