add tracing and refactor some api pkgs

This commit is contained in:
Livio Amstutz
2020-03-24 14:15:01 +01:00
parent a5ca611dcc
commit 96b88f5d8c
26 changed files with 1198 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
package http
import (
"net"
"strings"
"github.com/caos/logging"
)
func CreateListener(endpoint string) net.Listener {
l, err := net.Listen("tcp", listenerEndpoint(endpoint))
logging.Log("SERVE-6vasef").OnError(err).Fatal("creating listener failed")
return l
}
func listenerEndpoint(endpoint string) string {
if strings.Contains(endpoint, ":") {
return endpoint
}
return ":" + endpoint
}

View File

@@ -0,0 +1,47 @@
package middleware
import (
"net/http"
"github.com/rs/cors"
"github.com/caos/zitadel/internal/api"
)
var (
DefaultCORSOptions = cors.Options{
AllowCredentials: true,
AllowedHeaders: []string{
api.Origin,
api.ContentType,
api.Accept,
api.AcceptLanguage,
api.Authorization,
api.ZitadelOrgID,
"x-grpc-web", //TODO: needed
},
AllowedMethods: []string{
http.MethodOptions,
http.MethodGet,
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
},
ExposedHeaders: []string{
api.Location,
},
AllowedOrigins: []string{
"http://localhost:*",
},
}
)
func CORSInterceptorOpts(opts cors.Options, h http.Handler) http.Handler {
return cors.New(opts).Handler(h)
}
func CORSInterceptor(h http.Handler) http.Handler {
return CORSInterceptorOpts(DefaultCORSOptions, h)
}

View File

@@ -0,0 +1,12 @@
package middleware
import (
"net/http"
"github.com/caos/zitadel/internal/api"
"github.com/caos/zitadel/internal/tracing"
)
func DefaultTraceHandler(handler http.Handler) http.Handler {
return tracing.TraceHandler(handler, api.Probes...)
}