package runtimeimport ()// String just returns the given string.// It is just for compatibility to other types.func ( string) (string, error) {return , nil}// StringSlice converts 'val' where individual strings are separated by// 'sep' into a string slice.func (, string) ([]string, error) {returnstrings.Split(, ), nil}// Bool converts the given string representation of a boolean value into bool.func ( string) (bool, error) {returnstrconv.ParseBool()}// BoolSlice converts 'val' where individual booleans are separated by// 'sep' into a bool slice.func (, string) ([]bool, error) { := strings.Split(, ) := make([]bool, len())for , := range { , := Bool()if != nil {returnnil, } [] = }return , nil}// parseFloat parses a floating point value the way the proto3 JSON mapping// does: a decimal number, or the exact strings "Infinity", "-Infinity" and// "NaN". strconv.ParseFloat additionally accepts hexadecimal floats ("0x1p4"),// underscore digit separators ("1_000") and alternate infinity/NaN spellings// ("Inf", "nan", "infinity"), none of which protojson (and so the request body// and backend) accept. Reject those so a value bound from a query or path// parameter can't differ from the same value sent in the body.func parseFloat( string, int) (float64, error) {switch {case"Infinity":returnmath.Inf(1), nilcase"-Infinity":returnmath.Inf(-1), nilcase"NaN":returnmath.NaN(), nil }ifstrings.ContainsAny(, "xX_") {return0, fmt.Errorf("invalid syntax %q", ) } , := strconv.ParseFloat(, )if != nil {return0, }// ParseFloat only yields Inf/NaN without an error for the alternate // spellings handled above; overflow returns a range error instead.ifmath.IsInf(, 0) || math.IsNaN() {return0, fmt.Errorf("invalid syntax %q", ) }return , nil}// Float64 converts the given string representation into representation of a floating point number into float64.func ( string) (float64, error) {returnparseFloat(, 64)}// Float64Slice converts 'val' where individual floating point numbers are separated by// 'sep' into a float64 slice.func (, string) ([]float64, error) { := strings.Split(, ) := make([]float64, len())for , := range { , := Float64()if != nil {returnnil, } [] = }return , nil}// Float32 converts the given string representation of a floating point number into float32.func ( string) (float32, error) { , := parseFloat(, 32)if != nil {return0, }returnfloat32(), nil}// Float32Slice converts 'val' where individual floating point numbers are separated by// 'sep' into a float32 slice.func (, string) ([]float32, error) { := strings.Split(, ) := make([]float32, len())for , := range { , := Float32()if != nil {returnnil, } [] = }return , nil}// Int64 converts the given string representation of an integer into int64.func ( string) (int64, error) {returnstrconv.ParseInt(, 10, 64)}// Int64Slice converts 'val' where individual integers are separated by// 'sep' into an int64 slice.func (, string) ([]int64, error) { := strings.Split(, ) := make([]int64, len())for , := range { , := Int64()if != nil {returnnil, } [] = }return , nil}// Int32 converts the given string representation of an integer into int32.func ( string) (int32, error) { , := strconv.ParseInt(, 10, 32)if != nil {return0, }returnint32(), nil}// Int32Slice converts 'val' where individual integers are separated by// 'sep' into an int32 slice.func (, string) ([]int32, error) { := strings.Split(, ) := make([]int32, len())for , := range { , := Int32()if != nil {returnnil, } [] = }return , nil}// Uint64 converts the given string representation of an integer into uint64.func ( string) (uint64, error) {returnstrconv.ParseUint(, 10, 64)}// Uint64Slice converts 'val' where individual integers are separated by// 'sep' into a uint64 slice.func (, string) ([]uint64, error) { := strings.Split(, ) := make([]uint64, len())for , := range { , := Uint64()if != nil {returnnil, } [] = }return , nil}// Uint32 converts the given string representation of an integer into uint32.func ( string) (uint32, error) { , := strconv.ParseUint(, 10, 32)if != nil {return0, }returnuint32(), nil}// Uint32Slice converts 'val' where individual integers are separated by// 'sep' into a uint32 slice.func (, string) ([]uint32, error) { := strings.Split(, ) := make([]uint32, len())for , := range { , := Uint32()if != nil {returnnil, } [] = }return , nil}// Bytes converts the given string representation of a byte sequence into a slice of bytes.// Like the protobuf JSON mapping, it accepts standard or URL-safe base64, with or// without padding.func ( string) ([]byte, error) { := base64.StdEncodingifstrings.ContainsAny(, "-_") { = base64.URLEncoding }iflen()%4 != 0 { = .WithPadding(base64.NoPadding) }return .DecodeString()}// BytesSlice converts 'val' where individual bytes sequences, encoded in standard or// URL-safe base64, are separated by 'sep' into a slice of byte slices.func (, string) ([][]byte, error) { := strings.Split(, ) := make([][]byte, len())for , := range { , := Bytes()if != nil {returnnil, } [] = }return , nil}// Timestamp converts the given RFC3339 formatted string into a timestamp.Timestamp.func ( string) (*timestamppb.Timestamp, error) {vartimestamppb.Timestamp = strconv.Quote(strings.Trim(, `"`)) := &protojson.UnmarshalOptions{}if := .Unmarshal([]byte(), &); != nil {returnnil, }return &, nil}// Duration converts the given string into a timestamp.Duration.func ( string) (*durationpb.Duration, error) {vardurationpb.Duration = strconv.Quote(strings.Trim(, `"`)) := &protojson.UnmarshalOptions{}if := .Unmarshal([]byte(), &); != nil {returnnil, }return &, nil}// Enum converts the given string into an int32 that should be type casted into the// correct enum proto type.func ( string, map[string]int32) (int32, error) { , := []if {return , nil } , := Int32()if != nil {return0, fmt.Errorf("%s is not valid", ) }for , := range {if == {return , nil } }return0, fmt.Errorf("%s is not valid", )}// EnumSlice converts 'val' where individual enums are separated by 'sep'// into a int32 slice. Each individual int32 should be type casted into the// correct enum proto type.func (, string, map[string]int32) ([]int32, error) { := strings.Split(, ) := make([]int32, len())for , := range { , := Enum(, )if != nil {returnnil, } [] = }return , nil}// Support for google.protobuf.wrappers on top of primitive types// StringValue well-known type support as wrapper around string typefunc ( string) (*wrapperspb.StringValue, error) {returnwrapperspb.String(), nil}// FloatValue well-known type support as wrapper around float32 typefunc ( string) (*wrapperspb.FloatValue, error) { , := Float32()returnwrapperspb.Float(), }// DoubleValue well-known type support as wrapper around float64 typefunc ( string) (*wrapperspb.DoubleValue, error) { , := Float64()returnwrapperspb.Double(), }// BoolValue well-known type support as wrapper around bool typefunc ( string) (*wrapperspb.BoolValue, error) { , := Bool()returnwrapperspb.Bool(), }// Int32Value well-known type support as wrapper around int32 typefunc ( string) (*wrapperspb.Int32Value, error) { , := Int32()returnwrapperspb.Int32(), }// UInt32Value well-known type support as wrapper around uint32 typefunc ( string) (*wrapperspb.UInt32Value, error) { , := Uint32()returnwrapperspb.UInt32(), }// Int64Value well-known type support as wrapper around int64 typefunc ( string) (*wrapperspb.Int64Value, error) { , := Int64()returnwrapperspb.Int64(), }// UInt64Value well-known type support as wrapper around uint64 typefunc ( string) (*wrapperspb.UInt64Value, error) { , := Uint64()returnwrapperspb.UInt64(), }// BytesValue well-known type support as wrapper around bytes[] typefunc ( string) (*wrapperspb.BytesValue, error) { , := Bytes()returnwrapperspb.Bytes(), }
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.