Skip to content

Conversation

fluxynet
Copy link

@fluxynet fluxynet commented Oct 8, 2025

Scaffold for Golang with inertiaJS

moved ui stuffs to ui package
changed frontend build to ui/build
embedded build files for serve
serve command now serves embedded files
dev command runs inertia in dev mode
Copy link

semanticdiff-com bot commented Oct 8, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  vite.config.ts  56% smaller
  .gitignore Unsupported file format
  bin/.gitignore Unsupported file format
  explorer/explorer.go  0% smaller
  explorer/fake.go  0% smaller
  explorer/inertia/adapters.go  0% smaller
  explorer/inertia/inertia.go  0% smaller
  explorer/inertia/internal/inertia/inertia.go  0% smaller
  go.mod Unsupported file format
  go.sum Unsupported file format
  logger.go  0% smaller
  main.go  0% smaller
  resources/css/app.css  0% smaller
  resources/js/Pages/Explore.jsx  0% smaller
  ui/build/.gitignore Unsupported file format
  ui/build/assets/app-DYd5-_m_.js  0% smaller
  ui/build/assets/app-tn0RQdqM.css  0% smaller
  ui/build/manifest.json  0% smaller
  ui/css/app.css  0% smaller
  ui/js/Pages/Details.jsx  0% smaller
  ui/js/Pages/Explore.jsx  0% smaller
  ui/js/app.jsx  0% smaller
  ui/ui.go  0% smaller
  ui/views/app.html Unsupported file format

Copy link
Owner

@eznix86 eznix86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good, it is just that inertia.go for vite already handle most of the parts.

Comment on lines +1 to +2
*
!.gitignore
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add ui/build folder to gitignore, you can put a .gitkeep to ui/build/.gitkeep if you want,

Comment on lines +30 to +33
inertia, err := gonertia.NewFromBytes(ui.BuildHtml())
if err != nil {
panic(err)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use inertia.NewFromFileFS(embedFS, "...") https://github.com/romsar/gonertia?tab=readme-ov-file#basic-example

Comment on lines +54 to +62
in, err := gonertia.NewFromFile("ui/views/app.html")
if err != nil {
panic(err)
}

i, err := inertia.NewWithVite(in)
if err != nil {
log.Fatal(err)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for dual func, the inertia.go for vite handle both cases.

Comment on lines +10 to +48
//go:embed views/app.html
var buildHtml []byte

func BuildHtml() []byte {
return buildHtml[:]
}

//go:embed build
var build embed.FS

func Assets() fs.FS {
assets, err := fs.Sub(build, "build/assets")
if err != nil {
panic(fmt.Errorf("failed to get subdirectory %q: %w", "build/assets", err))
}

return assets
}

//go:embed build/manifest.json
var manifest []byte

type manitestData map[string]struct {
File string `json:"file"`
}

func Manifest() func(name string) (string, error) {
var data manitestData
err := json.Unmarshal(manifest, &data)
if err != nil {
panic(fmt.Errorf("failed to unmarshal manifest: %w", err))
}

return func(name string) (string, error) {
entry, ok := data[name]
if !ok {
return "", fmt.Errorf("entry %q not found in manifest", name)
}

Copy link
Owner

@eznix86 eznix86 Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to handle all of this, as it already handled in the inertia.go for vite

we can have a simple:

//go:embed public/*
var embeddedUI embed.FS

subFS, err := fs.Sub(embeddedFiles, "ui")


and use  http.FileServer with it

Can use the ViteConfig with Options Pattern to override behaviour which points to public right now.

Comment on lines +30 to +40
cmdServe := &cobra.Command{
Use: "serve",
Short: "Start the explorer server",
RunE: serveCommand(logger, "127.0.0.1", 1337, false),
}

cmdDev := &cobra.Command{
Use: "dev",
Short: "Start the explorer server in development mode",
RunE: serveCommand(logger, "127.0.0.1", 1337, true),
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inertia.go for vite already knows if it is dev or not, it detect the hot file. if it exists, it will call vite for assets to do hot reload. If it doesn't see hot file, it will serve the assets directly.

@eznix86 eznix86 changed the title scaffolding golang with inertia feat: scaffold v1 Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants