So I have been trying to run htmx and have this project structure, this does work when all of these three files i.e main.go static_prod.go and static_dev.go is in root of the project alongside embed.go but with below structure it does not work
static_dev.go
//go:build dev
// +build dev
package main
import (
"fmt"
"net/http"
"os"
)
func public() http.Handler {
fmt.Println("Building static files for development")
return http.StripPrefix("../public/**/*", http.FileServerFS(os.DirFS("public")))
}
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
static "github.com/goemon"
"github.com/goemon/internals/handlers"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
if err := godotenv.Load(); err != nil {
log.Fatal(err)
}
// Echo instance
e := echo.New()
e.GET("/", func(c echo.Context) error {
time.Sleep(5 * time.Second)
return c.JSON(http.StatusOK, "OK")
})
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.GET("/*", echo.WrapHandler(http.FileServer(http.FS(static.PublicFS))))
e.GET("/", handlers.Make(handlers.Hello))
// Start server
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
// Start server
go func() {
if err := e.Start(fmt.Sprintf(":%s", os.Getenv("LISTEN_ADDR"))); err != nil && err != http.ErrServerClosed {
e.Logger.Fatal("shutting down the server")
}
}()
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
<-ctx.Done()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
}
Now this works perfectly fine when building and running it manually
however with air it does not work
initially it asks for permissions to tmp folder
once i set permission via chmod , I get below error
Now, I could understand the error could be in code but this works perfectly fine when building and running it manually
/Users/arvee/Documents/interview/amm-ui/goemx/tmp/main: line 1: syntax error near unexpected token `newline'
/Users/arvee/Documents/interview/amm-ui/goemx/tmp/main: line 1: `!<arch>'
So I have been trying to run htmx and have this project structure, this does work when all of these three files i.e main.go static_prod.go and static_dev.go is in root of the project alongside embed.go but with below structure it does not work
Now this works perfectly fine when building and running it manually
however with air it does not work
Now, I could understand the error could be in code but this works perfectly fine when building and running it manually