From 51cb4c238604be66c66bc27bbb951fcb18cbd8fe Mon Sep 17 00:00:00 2001 From: kevkevinpal Date: Thu, 19 Dec 2024 16:06:50 -0500 Subject: [PATCH] added xgo and started using Trap to intercept function calls --- config/config.go | 2 +- go.mod | 1 + go.sum | 2 + main.go | 1 + routes/people.go | 8 ++-- routes/person.go | 2 +- routes/test_routes.go | 23 +----------- trace.out | Bin 0 -> 4073 bytes utils/logger.go | 14 +++---- utils/trace.go | 85 ++++++++---------------------------------- 10 files changed, 33 insertions(+), 105 deletions(-) create mode 100644 trace.out diff --git a/config/config.go b/config/config.go index 860c66005..a1662fe49 100644 --- a/config/config.go +++ b/config/config.go @@ -68,7 +68,7 @@ func InitConfig() { V2BotUrl = os.Getenv("V2_BOT_URL") V2BotToken = os.Getenv("V2_BOT_TOKEN") FfWebsocket = os.Getenv("FF_WEBSOCKET") == "true" - LogLevel = os.Getenv("LOG_LEVEL") + LogLevel = strings.ToUpper(os.Getenv("LOG_LEVEL")) // Add to super admins SuperAdmins = StripSuperAdmins(AdminStrings) diff --git a/go.mod b/go.mod index 8b0898986..3a073f373 100644 --- a/go.mod +++ b/go.mod @@ -61,6 +61,7 @@ require ( github.com/onsi/gomega v1.26.0 // indirect github.com/robfig/cron v1.2.0 github.com/urfave/negroni v1.0.0 // indirect + github.com/xhd2015/xgo/runtime v1.0.52 // indirect golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect gopkg.in/go-playground/assert.v1 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index d389d674c..d4ae95b46 100644 --- a/go.sum +++ b/go.sum @@ -2168,6 +2168,8 @@ github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= +github.com/xhd2015/xgo/runtime v1.0.52 h1:njcRzY3Xo2AFu/qQSC4ak9+JN7xFmaI3iEUyJxoErWM= +github.com/xhd2015/xgo/runtime v1.0.52/go.mod h1:9GBQ2SzJCzpD3T+HRN+2C0TUOGv7qIz4s0mad1xJ8Jo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo= github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= diff --git a/main.go b/main.go index 58843ddf5..396d2b871 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "gopkg.in/go-playground/validator.v9" ) + func main() { if err := godotenv.Load(); err != nil { fmt.Println("no .env file") diff --git a/routes/people.go b/routes/people.go index 1f11e5735..9a9d61f8f 100644 --- a/routes/people.go +++ b/routes/people.go @@ -15,10 +15,10 @@ func PeopleRoutes() chi.Router { peopleHandler := handlers.NewPeopleHandler(db.DB) r.Group(func(r chi.Router) { - r.Get("/", utils.TraceWithLogging(peopleHandler.GetListedPeople)) - r.Get("/search", utils.TraceWithLogging(peopleHandler.GetPeopleBySearch)) - r.Get("/posts", utils.TraceWithLogging(handlers.GetListedPosts)) - r.Get("/wanteds/assigned/{uuid}", bountyHandler.GetPersonAssignedBounties) + r.Get("/", utils.AutoLog(peopleHandler.GetListedPeople)) + r.Get("/search", utils.AutoLog(peopleHandler.GetPeopleBySearch)) + r.Get("/posts", utils.AutoLog(handlers.GetListedPosts)) + r.Get("/wanteds/assigned/{uuid}", utils.AutoLog(bountyHandler.GetPersonAssignedBounties)) r.Get("/wanteds/created/{uuid}", bountyHandler.GetPersonCreatedBounties) r.Get("/wanteds/header", handlers.GetWantedsHeader) r.Get("/short", handlers.GetPeopleShortList) diff --git a/routes/person.go b/routes/person.go index 1c98b4625..5cb45c9bd 100644 --- a/routes/person.go +++ b/routes/person.go @@ -14,7 +14,7 @@ func PersonRoutes() chi.Router { r.Group(func(r chi.Router) { r.Get("/{pubkey}", peopleHandler.GetPersonByPubkey) r.Get("/id/{id}", peopleHandler.GetPersonById) - r.Get("/uuid/{uuid}", utils.TraceWithLogging(peopleHandler.GetPersonByUuid)) + r.Get("/uuid/{uuid}", utils.AutoLog(peopleHandler.GetPersonByUuid)) r.Get("/uuid/{uuid}/assets", handlers.GetPersonAssetsByUuid) r.Get("/githubname/{github}", handlers.GetPersonByGithubName) }) diff --git a/routes/test_routes.go b/routes/test_routes.go index 5b944adf5..ead2e78a6 100644 --- a/routes/test_routes.go +++ b/routes/test_routes.go @@ -2,11 +2,6 @@ package routes import ( "net/http" - "runtime/trace" - "log" -// "os" - "bytes" - "github.com/go-chi/chi" ) @@ -14,23 +9,7 @@ func TestRoutes() chi.Router { r := chi.NewRouter() r.Get("/internal-server-error", func(w http.ResponseWriter, r *http.Request) { - // Enable tracing - //f, err := os.Create("trace.out") - var buf bytes.Buffer - //if err != nil { - // log.Fatalf("Failed to create trace output file: %v", err) - //} - //defer f.Close() - - if err := trace.Start(&buf); err != nil { - log.Fatalf("Failed to start trace: %v", err) - } - defer func() { - trace.Stop() - log.Println("Trace Data:") - log.Println(buf.String()) - }() - //panic("Forced internal server error") + panic("Forced internal server error") }) return r diff --git a/trace.out b/trace.out new file mode 100644 index 0000000000000000000000000000000000000000..83de2b6f90d346ecfc7970fd38ab2f86b2bd7198 GIT binary patch literal 4073 zcmdT{U2GIp6zoIykh7ZnvzCAaJsmAmoL+3~l7&x{scMgHU8o%T^BHxG|o zziLg5?XjlAztDT5h;zErsRO3RmE);a3Iwzt-PQ=u^&_Wk# za-n4|)a^p+Txh)uZE&HDPK0{DK0Lw%y}KMnXCmL(ZzXc-IXjUwR{M1Xwe2chu85@s%`>Jm-xBk-p zW4qpseb8dS1=f{t*OCu*Jd;a?~6Ku34Y{M@;nP8W- zcG>XD8xw3B-($nCzA+{2`19m>Mrb%wd-lb1Onbx4GR8x_@ervl=$@Lp!7-upV+ZKYl^2S~FPkBa(sMo}x^CakW++$Zes)mky%RZl zRlN0(m7J&NesX-F%Lj6F7xaeLtdRE3`H-A_@$?_oZ9G0^_eBq)innM6w_78Fm>{}z zLpK+Zv8+g1zCNN#e59pYQ{^bXLsSe@>@jVqgq4z_%IR2@(Y$%qcY-CX3}F~?e=Qwa<2}Y%LFx@Xog9)N#RhiRwW1PV-X|k79=_9&<(_BJ>Swm5A z-d@gT2*&9Q#E0frP7}(wKbznrF_l6U6_z!t8cK=-40z4@>CaOzhJY1I()q)4#5QznoxVePsn)^6&(D}ewc#?As6 z2wKj zsI|@6;V5r8wD`C+LQ+d(VGs|&pQ4&6$P6Zgv?dF8rFdj0#&_@?LOMHaI$C^hM>E2g zMD9vwE7}ajYL`UgBaWr_-hV|^jBbdl4~h@ckWW4zLrp#ZH!MYlUEdAa6U>4(IU&mM z!wyA67bK17*108m)J{~}K>Bu5p%$B0-p!M@uAZIZza>k3G1cRGt#lwB65+STZ)PE$j&Y_=5`| z`OtPMvRRk{XCHn(fB5Zm&m6q=>ggqs7D-c8Xq0B3K(R%3JGGkWHnS=BVo~niy1k$` z-h5}XaW%}il*yVhmN&SldNc`cPPh!x;&6s&l8#oi%*JFB09!|e4J=K4=6~0yv&uHY m5g