Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-gaitzsch committed Oct 21, 2024
1 parent a52b244 commit 9103e5e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 36 deletions.
10 changes: 4 additions & 6 deletions loopback/loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ func (s *Server) Serve(ctx context.Context) {
WriteTimeout: 1 * time.Second,
ReadTimeout: 1 * time.Second,
IdleTimeout: 5 * time.Second,
})
})

app.Use(
recover.New(),
serverutils.ProvideUserCtxMiddleware(ctx),
)

conf := config.Get(ctx)

servingAddr := fmt.Sprintf("127.0.0.1:%d", conf.LoopbackPort)
Expand Down Expand Up @@ -75,7 +75,7 @@ func GetBundleFileHandler(c *fiber.Ctx) error {

ctx := c.UserContext()

bundleIdFromRoute := c.Params(bundleIdKey)
bundleIdFromRoute := c.Params(bundleIdKey)

urlPathPrefix := BundlePath + "/" + bundleIdFromRoute + "/"

Expand Down Expand Up @@ -108,7 +108,6 @@ func GetBundleFileHandler(c *fiber.Ctx) error {
Error().
Msg("cant find bundle")


return c.SendStatus(http.StatusNotFound)
}

Expand All @@ -124,11 +123,10 @@ func GetBundleFileHandler(c *fiber.Ctx) error {
Err(err).
Msg("cant get file")


return c.SendStatus(http.StatusInternalServerError)
}
defer fileReader.Close()

c.Set(fiber.HeaderContentType, mimeType)
c.Set(fiber.HeaderContentType, mimeType)
return c.SendStream(fileReader)
}
4 changes: 2 additions & 2 deletions server/handlers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

func writePdf(c *fiber.Ctx, data io.Reader) error {
ctx:=c.UserContext()
ctx := c.UserContext()

if data == nil {
log.Ctx(ctx).Info().Msg("nothing to writeout: pdf data empty")
return c.SendStatus(http.StatusNoContent)
Expand Down
14 changes: 7 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func (s *Server) Serve(ctx context.Context) {
WriteTimeout: 45 * time.Second,
ReadTimeout: 45 * time.Second,
IdleTimeout: 60 * time.Second,
BodyLimit: conf.MaxBodySizeInMb * 1024 * 1024,
})
BodyLimit: conf.MaxBodySizeInMb * 1024 * 1024,
})

app.Use(
cors.New(cors.Config{
AllowOrigins: "*",
AllowHeaders: "*",
AllowMethods: strings.Join([]string{http.MethodGet, http.MethodPost}, ","),
AllowOrigins: "*",
AllowHeaders: "*",
AllowMethods: strings.Join([]string{http.MethodGet, http.MethodPost}, ","),
AllowCredentials: false,
}),
recover.New(),
Expand Down Expand Up @@ -136,9 +136,9 @@ func servePlaygroundFronted(app *fiber.App) {
return ctx.SendFile(config.PathStaticExternPlayground + ctx.Path())
})
app.Get("/favicon.ico", func(ctx *fiber.Ctx) error {
return ctx.SendFile(config.PathStaticExternPlayground+"favicon.ico")
return ctx.SendFile(config.PathStaticExternPlayground + "favicon.ico")
})
app.Get("/*", func(ctx *fiber.Ctx) error {
return ctx.SendFile(config.PathStaticExternPlayground+"index.html")
return ctx.SendFile(config.PathStaticExternPlayground + "index.html")
})
}
12 changes: 6 additions & 6 deletions serverutils/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func ProvideUserCtxMiddleware(ctx context.Context) func(c *fiber.Ctx) error {
if requestCtx != nil {
go func() {
select {
case <- requestCtx.Done():
cancel()
return
case <-combinedCtx.Done():
return
case <-requestCtx.Done():
cancel()
return
case <-combinedCtx.Done():
return
}
}()
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func RecoverMiddleware() func(c *fiber.Ctx) error {
logRequestErr(c, rec)
}
}()

err := c.Next()

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions services/renderer/headlesschromium/headless-chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func NewChromiumBrowser(ctx context.Context) (context.Context, context.CancelFun
chromedp.Flag("mute-audio", true),
)

if (config.Get(ctx).NoSandbox) {
if config.Get(ctx).NoSandbox {
opts = append(
opts,
chromedp.Flag("no-sandbox", true),
)
}

allocCtx, cancelAllocCtx := chromedp.NewExecAllocator(ctx, opts...)

cctx, cancelCctx := chromedp.NewContext(allocCtx)
Expand Down
2 changes: 1 addition & 1 deletion services/renderer/renderer-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestWorkerBeyondTheLimit(t *testing.T) {
for i := 0; i < jobCount-workerInstances; i++ {
<-rendererMock.HitRenderChan
}

<-time.After(50 * time.Millisecond)

if currLen := len(service.workerSlots); currLen != jobCount-workerInstances {
Expand Down
10 changes: 5 additions & 5 deletions utils/html-css.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func MergeCss(css ...*string) *string {
var urlReferenceRegex = regexp.MustCompile(`(\ssrc="|\shref="|src:\s*(local\(.*\),)?\s*url\(["'])([^"']+)(["']\)|")`)

type HttpClientExecuter interface {
Do(req *http.Request) (*http.Response, error)
Do(req *http.Request) (*http.Response, error)
}

func RequestAndInlineAllHtmlResources(ctx context.Context, htmlPtr *string, baseUrl string) *string {
Expand Down Expand Up @@ -103,10 +103,10 @@ func requestAndReturnBase64IfPossible(ctx context.Context, htmlAttribute string,
base64 := base64.StdEncoding.EncodeToString(bytes)

isCssSrcUrl := strings.HasSuffix(prefix, `url("`)
if (isCssSrcUrl) {
prefix = strings.TrimRight(prefix,`"`)
suffix = strings.TrimLeft(suffix,`"`)

if isCssSrcUrl {
prefix = strings.TrimRight(prefix, `"`)
suffix = strings.TrimLeft(suffix, `"`)
}

return prefix + "data:" + mimeType + ";base64," + base64 + suffix
Expand Down
14 changes: 7 additions & 7 deletions utils/html-css_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAppendStyleToHtml(t *testing.T) {

output := *outputPtr

if !strings.HasSuffix(output, "<style>" + css + "</style>") {
if !strings.HasSuffix(output, "<style>"+css+"</style>") {
t.Fatal("Result should have appended css")
}
if !strings.HasPrefix(output, inputHtml) {
Expand All @@ -38,7 +38,7 @@ func TestAppendStyleToHtmlReturnsEmptyWithNilInput(t *testing.T) {
t.Fatal("Result should not be nil")
}

if (*outputPtr != emptyString) {
if *outputPtr != emptyString {
t.Fatal("Result should be empty")
}
}
Expand All @@ -48,8 +48,7 @@ func TestMergeCss(t *testing.T) {
css2 := ".test2 { color: blue; }"
css3 := ".test3 { color: green; }"

expectedMergedCss := css1+css2+css3

expectedMergedCss := css1 + css2 + css3

outputPtr := MergeCss(&css1, &css2, &css3)

Expand All @@ -65,17 +64,18 @@ func TestMergeCss(t *testing.T) {
type HttpClientMock struct {
RequestedResources []string
}

func (c *HttpClientMock) Do(req *http.Request) (*http.Response, error) {
c.RequestedResources = append(c.RequestedResources, req.URL.String())

return &http.Response{
return &http.Response{
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
}, nil
}

func TestRequestAndInlineAllHtmlResources(t *testing.T) {
inputHtml := "<head><style>@font-face{ src: url(\"http://my-font.org/font.eot\"); }</style></head> <body>Hello World <img src=\"http://my-image.org/test1.png\"/> <img src=\"test2.png\"/> </body>"

httpClientMock := &HttpClientMock{}
ctx := context.WithValue(context.Background(), "httpClient", httpClientMock)

Expand All @@ -102,4 +102,4 @@ func TestRequestAndInlineAllHtmlResources(t *testing.T) {
if *outputPtr != expectedHtml {
t.Fatalf("Result was not expected: %s != %s", *outputPtr, expectedHtml)
}
}
}

0 comments on commit 9103e5e

Please sign in to comment.