Files
HostKeeper/app/backend/internal/handler/snippets.go
T
swanadiva fd7361aa14 Sprint 6: JSON file persistence + real SSH terminal + V1 crypto/knownhosts integration
- go.mod replace directive for git.tukangketik.id/swanadiva/hostkeeper → ../../v1
- store/ package: JSON file persistence for hosts, snippets, keys, settings
  (~/Library/Application Support/hostkeeper/v2/)
- model SSH fields: Hostname, Port, Username, AuthType, Password, KeyID
- sshconn/ package: real SSH client via golang.org/x/crypto/ssh
- Terminal WS: real SSH connection with fallback to mock shell
- Dynamic host list in terminal (server-rendered JSON script tag)
- All mock data defaults removed from model packages
- Settings persist via store/settings.go
2026-07-07 13:53:50 +07:00

41 lines
1.0 KiB
Go

package handler
import (
"github.com/gofiber/fiber/v2"
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/store"
)
var snippetStore = store.NewSnippetStore()
func Snippets(c *fiber.Ctx) error {
snippets := snippetStore.All()
return c.Render("snippets", fiber.Map{
"View": "snippets",
"Title": "Snippets",
"Snippets": snippets,
"NavItems": navItems,
})
}
func SnippetGrid(c *fiber.Ctx) error {
q := c.Query("q", "")
snippets := snippetStore.Search(q)
return c.Render("snippet_grid", fiber.Map{"Snippets": snippets})
}
func CreateSnippet(c *fiber.Ctx) error {
name := c.FormValue("name")
content := c.FormValue("content")
language := c.FormValue("language")
snippetStore.Add(name, content, language, nil)
snippets := snippetStore.All()
return c.Render("snippet_grid", fiber.Map{"Snippets": snippets})
}
func DeleteSnippet(c *fiber.Ctx) error {
id := c.Params("id")
snippetStore.Delete(id)
snippets := snippetStore.All()
return c.Render("snippet_grid", fiber.Map{"Snippets": snippets})
}