mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
improve some functions
This commit is contained in:
parent
b753e06f0b
commit
fa750a5068
@ -13,7 +13,6 @@ import (
|
||||
func MustToPBStruct(object interface{}) *pb_struct.Struct {
|
||||
s, err := ToPBStruct(object)
|
||||
logging.Log("PROTO-7Aa3t").OnError(err).Panic("unable to map object to pb-struct")
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@ -24,15 +23,12 @@ func BytesToPBStruct(b []byte) (*pb_struct.Struct, error) {
|
||||
}
|
||||
|
||||
func ToPBStruct(object interface{}) (*pb_struct.Struct, error) {
|
||||
fields := new(pb_struct.Struct)
|
||||
|
||||
marshalled, err := json.Marshal(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fields := new(pb_struct.Struct)
|
||||
err = jsonpb.Unmarshal(bytes.NewReader(marshalled), fields)
|
||||
|
||||
return fields, err
|
||||
}
|
||||
|
||||
@ -47,6 +43,5 @@ func FromPBStruct(object interface{}, s *pb_struct.Struct) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(jsonString), object)
|
||||
}
|
||||
|
@ -8,17 +8,15 @@ import (
|
||||
|
||||
func GetCaller() string {
|
||||
fpcs := make([]uintptr, 1)
|
||||
|
||||
n := runtime.Callers(3, fpcs)
|
||||
if n == 0 {
|
||||
logging.Log("HELPE-rWjfC").Debug("no caller")
|
||||
logging.Log("TRACE-rWjfC").Debug("no caller")
|
||||
return ""
|
||||
}
|
||||
|
||||
caller := runtime.FuncForPC(fpcs[0] - 1)
|
||||
if caller == nil {
|
||||
logging.Log("HELPE-25POw").Debug("caller was nil")
|
||||
logging.Log("TRACE-25POw").Debug("caller was nil")
|
||||
return ""
|
||||
}
|
||||
|
||||
// Print the name of the function
|
||||
return caller.Name()
|
||||
}
|
||||
|
@ -3,9 +3,7 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/tracing"
|
||||
tracing_g "github.com/caos/zitadel/internal/tracing/google"
|
||||
tracing_log "github.com/caos/zitadel/internal/tracing/log"
|
||||
@ -28,7 +26,7 @@ func (c *TracingConfig) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &rc); err != nil {
|
||||
return status.Errorf(codes.Internal, "%v parse config: %v", "TRACE-vmjS", err)
|
||||
return errors.ThrowInternal(err, "TRACE-vmjS", "error parsing config")
|
||||
}
|
||||
|
||||
c.Type = rc.Type
|
||||
@ -36,7 +34,7 @@ func (c *TracingConfig) UnmarshalJSON(data []byte) error {
|
||||
var err error
|
||||
c.Config, err = newTracingConfig(c.Type, rc.Config)
|
||||
if err != nil {
|
||||
return status.Errorf(codes.Internal, "%v parse config: %v", "TRACE-Ws9E", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Config.NewTracer()
|
||||
@ -45,7 +43,7 @@ func (c *TracingConfig) UnmarshalJSON(data []byte) error {
|
||||
func newTracingConfig(tracerType string, configData []byte) (tracing.Config, error) {
|
||||
t, ok := tracer[tracerType]
|
||||
if !ok {
|
||||
return nil, status.Errorf(codes.Internal, "%v No config: %v", "TRACE-HMEJ", tracerType)
|
||||
return nil, errors.ThrowInternalf(nil, "TRACE-HMEJ", "config type %s not supported", tracerType)
|
||||
}
|
||||
|
||||
tracingConfig := t()
|
||||
@ -54,7 +52,7 @@ func newTracingConfig(tracerType string, configData []byte) (tracing.Config, err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(configData, tracingConfig); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "%v Could not read conifg: %v", "TRACE-1tSS", err)
|
||||
return nil, errors.ThrowInternal(err, "TRACE-1tSS", "Could not read config: %v")
|
||||
}
|
||||
|
||||
return tracingConfig, nil
|
||||
|
@ -2,9 +2,8 @@ package google
|
||||
|
||||
import (
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/tracing"
|
||||
)
|
||||
|
||||
@ -16,7 +15,7 @@ type Config struct {
|
||||
|
||||
func (c *Config) NewTracer() error {
|
||||
if !envIsSet() {
|
||||
return status.Error(codes.InvalidArgument, "env not properly set, GOOGLE_APPLICATION_CREDENTIALS is misconfigured or missing")
|
||||
return errors.ThrowInvalidArgument(nil, "GOOGL-sdh3a", "env not properly set, GOOGLE_APPLICATION_CREDENTIALS is misconfigured or missing")
|
||||
}
|
||||
|
||||
tracing.T = &Tracer{projectID: c.ProjectID, metricPrefix: c.MetricPrefix, sampler: trace.ProbabilitySampler(c.Fraction)}
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"go.opencensus.io/trace"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
type Span struct {
|
||||
@ -80,7 +82,7 @@ func toTraceAttribute(key string, value interface{}) (attr trace.Attribute, err
|
||||
if valueInt, err := convertToInt64(value); err == nil {
|
||||
return trace.Int64Attribute(key, valueInt), nil
|
||||
}
|
||||
return attr, status.Error(codes.InvalidArgument, "Attribute is not of type bool, string or int64")
|
||||
return attr, errors.ThrowInternal(nil, "TRACE-jlq3s", "Attribute is not of type bool, string or int64")
|
||||
}
|
||||
|
||||
func convertToInt64(value interface{}) (int64, error) {
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
App *app.Config
|
||||
API *api.Config
|
||||
App app.Config
|
||||
API api.Config
|
||||
}
|
||||
|
||||
func Start(ctx context.Context, config Config, authZ auth.Config) error {
|
||||
|
@ -3,5 +3,5 @@ package api
|
||||
import "github.com/caos/zitadel/internal/api/grpc"
|
||||
|
||||
type Config struct {
|
||||
GRPC *grpc.Config
|
||||
GRPC grpc.Config
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package api
|
||||
import "github.com/caos/zitadel/internal/api/grpc"
|
||||
|
||||
type Config struct {
|
||||
GRPC *grpc.Config
|
||||
GRPC grpc.Config
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import (
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
App *app.Config
|
||||
API *api.Config
|
||||
App app.Config
|
||||
API api.Config
|
||||
}
|
||||
|
||||
func Start(ctx context.Context, config Config, authZ auth.Config) error {
|
||||
|
Loading…
Reference in New Issue
Block a user