...

Source file src/github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/clients/abe/enum_helper.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/clients/abe

     1  package abe
     2  
     3  import (
     4  	pbexamplepb "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/examplepb"
     5  	pbpathenum "github.com/grpc-ecosystem/grpc-gateway/v2/examples/internal/proto/pathenum"
     6  	"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
     7  )
     8  
     9  // String returns a string representation of "NumericEnum"
    10  func (e ExamplepbNumericEnum) String() string {
    11  	return pbexamplepb.NumericEnum_ONE.String()
    12  }
    13  
    14  // UnmarshalJSON does a no-op unmarshal to ExamplepbNumericEnum.
    15  // It just validates that the input is sane.
    16  func (e ExamplepbNumericEnum) UnmarshalJSON(b []byte) error {
    17  	return unmarshalJSONEnum(b, pbexamplepb.NumericEnum_value)
    18  }
    19  
    20  // String returns a string representation of "MessagePathEnum"
    21  func (e MessagePathEnumNestedPathEnum) String() string {
    22  	return pbpathenum.MessagePathEnum_JKL.String()
    23  }
    24  
    25  // UnmarshalJSON does a no-op unmarshal to MessagePathEnumNestedPathEnum.
    26  // It just validates that the input is sane.
    27  func (e MessagePathEnumNestedPathEnum) UnmarshalJSON(b []byte) error {
    28  	return unmarshalJSONEnum(b, pbpathenum.MessagePathEnum_NestedPathEnum_value)
    29  }
    30  
    31  // String returns a string representation of "PathEnum"
    32  func (e PathenumPathEnum) String() string {
    33  	return pbpathenum.PathEnum_DEF.String()
    34  }
    35  
    36  // UnmarshalJSON does a no-op unmarshal to PathenumPathEnum.
    37  // It just validates that the input is sane.
    38  func (e PathenumPathEnum) UnmarshalJSON(b []byte) error {
    39  	return unmarshalJSONEnum(b, pbpathenum.PathEnum_value)
    40  }
    41  
    42  func unmarshalJSONEnum(b []byte, enumValMap map[string]int32) error {
    43  	val := string(b[1 : len(b)-1])
    44  	_, err := runtime.Enum(val, enumValMap)
    45  	return err
    46  }
    47  

View as plain text