Paul LeDuc
Paul LeDuc

Reputation: 149

Problems with static files Go-Echo-Templ

I am starting a Go project using Echo and Templ.

I have a project structure as follows:

/
/cmd
    main.go
/static
    css
        style.css
/view
    /layout
        base.templ

The problem I am experiencing is that I don't seem to be able to include a stylesheet.

My main. go is as follows:

package main

import (
    "fmt"
    "os"

    "github.com/RollingITGuy/go-rerun-dist/handler"
    "github.com/labstack/echo/v4"
)

func main() {

    app := echo.New()
    app.Static("/static", "static")
    handler := handler.IndexHandler{}

    app.GET("/", handler.HandleShowIndex)

    err := app.Start(":5150")
    if err != nil {
        apperr := fmt.Errorf("server start failed; %w", err)
        fmt.Fprintf(os.Stderr, "%+v\n", apperr)
    }

    os.Exit(0)
}

The Templ file is:

package layout

templ Base() {
    <html>
        <head>
            <link rel="stylesheet" href="static/css/style.css" />
            <title>Here</title>
        </head>
        <body>
            { children... }
        </body>
        <footer>
        </footer>
    </html>
}

When I view the page source I get:

<link rel="stylesheet" href="static/css/style.css">

When I click the link to the stylesheet I receive:

{"message":"Not Found"}

What am I missing? What can I fix?

Upvotes: 1

Views: 475

Answers (0)

Related Questions