// Copyright The OpenTelemetry Authors// SPDX-License-Identifier: Apache-2.0package codes // import "go.opentelemetry.io/otel/codes"import ()const (// Unset is the default status code.UnsetCode = 0// Error indicates the operation contains an error. // // NOTE: The error code in OTLP is 2. // The value of this enum is only relevant to the internals // of the Go SDK.ErrorCode = 1// Ok indicates operation has been validated by an Application developers // or Operator to have completed successfully, or contain no error. // // NOTE: The Ok code in OTLP is 1. // The value of this enum is only relevant to the internals // of the Go SDK.OkCode = 2 maxCode = 3)// Code is an 32-bit representation of a status state.typeCodeuint32var codeToStr = map[Code]string{Unset: "Unset",Error: "Error",Ok: "Ok",}var strToCode = map[string]Code{`"Unset"`: Unset,`"Error"`: Error,`"Ok"`: Ok,}// String returns the Code as a string.func ( Code) () string {returncodeToStr[]}// UnmarshalJSON unmarshals b into the Code.//// This is based on the functionality in the gRPC codes package:// https://github.com/grpc/grpc-go/blob/bb64fee312b46ebee26be43364a7a966033521b1/codes/codes.go#L218-L244func ( *Code) ( []byte) error {// From json.Unmarshaler: By convention, to approximate the behavior of // Unmarshal itself, Unmarshalers implement UnmarshalJSON([]byte("null")) as // a no-op.ifstring() == "null" {returnnil }if == nil {returnerrors.New("nil receiver passed to UnmarshalJSON") }varanyif := json.Unmarshal(, &); != nil {return }switch .(type) {casestring:if , := strToCode[string()]; { * = returnnil }returnfmt.Errorf("invalid code: %q", string())casefloat64:if , := strconv.ParseUint(string(), 10, 32); == nil {if >= maxCode {returnfmt.Errorf("invalid code: %q", ) } * = Code() // nolint: gosec // Bit size of 32 check above.returnnil }returnfmt.Errorf("invalid code: %q", string())default:returnfmt.Errorf("invalid code: %q", string()) }}// MarshalJSON returns c as the JSON encoding of c.func ( *Code) () ([]byte, error) {if == nil {return []byte("null"), nil } , := codeToStr[*]if ! {returnnil, fmt.Errorf("invalid code: %d", *) }returnfmt.Appendf(nil, "%q", ), nil}
The pages are generated with Goldsv0.8.2. (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.