logging and other lint

This commit is contained in:
Michael Quigley 2024-10-07 16:40:07 -04:00
parent d3568c061d
commit 4749411a59
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 19 additions and 13 deletions

View File

@ -95,13 +95,16 @@ func (a *Agent) Config() *AgentConfig {
} }
func (a *Agent) gateway(cfg *AgentConfig) { func (a *Agent) gateway(cfg *AgentConfig) {
logrus.Info("started")
defer logrus.Warn("exited")
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
mux := runtime.NewServeMux() mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
endpoint := "unix:" + a.agentSocket endpoint := "unix:" + a.agentSocket
logrus.Infof("endpoint: %v", endpoint) logrus.Debugf("endpoint: '%v'", endpoint)
if err := agentGrpc.RegisterAgentHandlerFromEndpoint(ctx, mux, "unix:"+a.agentSocket, opts); err != nil { if err := agentGrpc.RegisterAgentHandlerFromEndpoint(ctx, mux, "unix:"+a.agentSocket, opts); err != nil {
logrus.Fatalf("unable to register gateway: %v", err) logrus.Fatalf("unable to register gateway: %v", err)
} }
@ -184,15 +187,3 @@ type agentGrpcImpl struct {
agentGrpc.UnimplementedAgentServer agentGrpc.UnimplementedAgentServer
agent *Agent agent *Agent
} }
func cors(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType, User-Agent")
if r.Method == "OPTIONS" {
return
}
h.ServeHTTP(w, r)
})
}

15
util/cors.go Normal file
View File

@ -0,0 +1,15 @@
package util
import "net/http"
func cors(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType, User-Agent")
if r.Method == "OPTIONS" {
return
}
h.ServeHTTP(w, r)
})
}