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

     1  // Code generated by github.com/infraboard/mcube
     2  // DO NOT EDIT
     3  
     4  package namespace
     5  
     6  import (
     7  	"bytes"
     8  	"fmt"
     9  	"strings"
    10  )
    11  
    12  // ParseVisibleFromString Parse Visible from string
    13  func ParseVisibleFromString(str string) (Visible, error) {
    14  	key := strings.Trim(string(str), `"`)
    15  	v, ok := Visible_value[strings.ToUpper(key)]
    16  	if !ok {
    17  		return 0, fmt.Errorf("unknown Visible: %s", str)
    18  	}
    19  
    20  	return Visible(v), nil
    21  }
    22  
    23  // Equal type compare
    24  func (t Visible) Equal(target Visible) bool {
    25  	return t == target
    26  }
    27  
    28  // IsIn todo
    29  func (t Visible) IsIn(targets ...Visible) 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 Visible) 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 *Visible) UnmarshalJSON(b []byte) error {
    49  	ins, err := ParseVisibleFromString(string(b))
    50  	if err != nil {
    51  		return err
    52  	}
    53  	*t = ins
    54  	return nil
    55  }