Skip to content

destinio/go-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Stack

Backend

fiber

go get -u github.com/gofiber/fiber/v2`
package main

import (
	"github.com/gofiber/fiber/v2"
)

func main() {
	app := fiber.New()

	// static files
	app.Static("/", "./public")

	app.Get("/", func(c *fiber.Ctx) error {
		c.Set("Content-Type", "text/html")
		return c.SendString("<h1>Hello, World!</h1>")
	})

	app.Listen(":1337")
}

Database

Gorm (ORM)

go get -u gorm.io/gorm
go get -u gorm.io/driver/sqlite
// for code examples see:
// https://gorm.io/docs/#Quick-Start

db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
if err != nil {
  panic("failed to connect database")
}

Frontend

HTMX

<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<!-- have a button POST a click via AJAX -->
<button hx-post="/clicked" hx-swap="outerHTML">
  Click Me
</button>

Fiber Templates

Tailwind CSS

npx tailwindcss init
/* ./styles/tailwind.css */

@tailwind base;
@tailwind components;
@tailwind utilities;
// ./tailwind.config.js
module.exports = {
  content: ["./views/**/*.html"], // add other files types here
  theme: {
    extend: {},
  },
  plugins: [],
}

scripts

# ./makefile

tw-b:
	@npx tailwindcss -i ./styles/tailwind.css -o ./public/main.css

tw-w:
	@npx tailwindcss -i ./styles/tailwind.css -o ./public/main.css --watch