Skip to content

Commit

Permalink
moved xgo to be used on all routes and internalServerMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
kevkevinpal committed Dec 27, 2024
1 parent e87c87e commit 280dfe5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 90 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ WORKDIR /app
COPY go.mod .
COPY go.sum .

# Installing xgo
RUN go install github.com/xhd2015/xgo/cmd/xgo@latest
ENV PATH="/usr/local/xgo/bin:${PATH}"

RUN go mod download

COPY . .

RUN CGO_ENABLED=0 go build
RUN CGO_ENABLED=0 xgo build

# final stage
FROM alpine:latest
Expand All @@ -24,4 +28,4 @@ COPY --from=builder /app/sphinx-tribes /app/
RUN ls app

EXPOSE 5002
ENTRYPOINT ["/app/sphinx-tribes"]
ENTRYPOINT ["/app/sphinx-tribes"]
16 changes: 16 additions & 0 deletions routes/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"os"
"runtime"
"time"
"strings"
"context"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/rs/cors"
"github.com/urfave/negroni"
"github.com/xhd2015/xgo/runtime/core"
"github.com/xhd2015/xgo/runtime/trap"

"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/config"
Expand Down Expand Up @@ -195,6 +199,18 @@ func internalServerErrorHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rr := negroni.NewResponseWriter(w)

trap.AddInterceptor(&trap.Interceptor{
Pre: func(ctx context.Context, f *core.FuncInfo, args core.Object, results core.Object) (interface{}, error) {
index := strings.Index(f.File, "sphinx-tribes")
trimmed := f.File
if index != -1 {
trimmed = f.File[index:]
}
logger.Log.Machine("%s:%d %s\n", trimmed, f.Line, f.Name)

return nil, nil
},
})
defer func() {
if err := recover(); err != nil {
// Get stack trace
Expand Down
9 changes: 4 additions & 5 deletions routes/people.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/go-chi/chi"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stakwork/sphinx-tribes/handlers"
"github.com/stakwork/sphinx-tribes/utils"
)

func PeopleRoutes() chi.Router {
Expand All @@ -15,10 +14,10 @@ func PeopleRoutes() chi.Router {

peopleHandler := handlers.NewPeopleHandler(db.DB)
r.Group(func(r chi.Router) {
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("/", peopleHandler.GetListedPeople)
r.Get("/search", peopleHandler.GetPeopleBySearch)
r.Get("/posts", handlers.GetListedPosts)
r.Get("/wanteds/assigned/{uuid}", bountyHandler.GetPersonAssignedBounties)
r.Get("/wanteds/created/{uuid}", bountyHandler.GetPersonCreatedBounties)
r.Get("/wanteds/header", handlers.GetWantedsHeader)
r.Get("/short", handlers.GetPeopleShortList)
Expand Down
3 changes: 1 addition & 2 deletions routes/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stakwork/sphinx-tribes/handlers"
"github.com/stakwork/sphinx-tribes/utils"
)

func PersonRoutes() chi.Router {
Expand All @@ -14,7 +13,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.AutoLog(peopleHandler.GetPersonByUuid))
r.Get("/uuid/{uuid}", peopleHandler.GetPersonByUuid)
r.Get("/uuid/{uuid}/assets", handlers.GetPersonAssetsByUuid)
r.Get("/githubname/{github}", handlers.GetPersonByGithubName)
})
Expand Down
53 changes: 0 additions & 53 deletions utils/logger.go

This file was deleted.

28 changes: 0 additions & 28 deletions utils/trace.go

This file was deleted.

0 comments on commit 280dfe5

Please sign in to comment.