Skip to content

Commit

Permalink
Added project files
Browse files Browse the repository at this point in the history
  • Loading branch information
Liviu Ilea committed Aug 4, 2021
1 parent e9cfa95 commit 4588684
Show file tree
Hide file tree
Showing 14 changed files with 7,884 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
public
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# go-alpine-tailwind-sample
# go-alpine-tailwind-sample

### Install & build frontend
1. `npm i`
2. `npm start` or `npm run build`

### Run
1. `go run main.go --dev=true`
11 changes: 11 additions & 0 deletions content/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"title": "Go AlpineJS TailwindCSS Sample",
"backendName": "Backend",
"backendLibName": "Fiber",
"backendLibUrl": "https://gofiber.io",
"frontendName": "Frontend",
"frontendLib1Name": "TailwindCSS",
"frontendLib1Url": "https://tailwindcss.com",
"frontendLib2Name": "AlpineJS",
"frontendLib2Url": "https://alpinejs.dev"
}
46 changes: 46 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/* your custom CSS here */
body {
background: rgb(14, 165, 233);
background: linear-gradient(0deg, rgba(14, 165, 233, 0.15028018043154767) 0%, rgba(215, 233, 241, 0.05504208519345233) 100%);
}

.blue-stripes-background {
--stripes-color: rgba(14, 165, 233, 0.4);
background-image: linear-gradient(45deg, var(--stripes-color) 12.5%, transparent 12.5%, transparent 50%, var(--stripes-color) 50%, var(--stripes-color) 62.5%, transparent 62.5%, transparent 100%);
background-size: 5.66px 5.66px;
}

.yellow-stripes-background {
--stripes-color: rgba(233, 196, 14, 0.85);
background-image: linear-gradient(45deg, var(--stripes-color) 12.5%, transparent 12.5%, transparent 50%, var(--stripes-color) 50%, var(--stripes-color) 62.5%, transparent 62.5%, transparent 100%);
background-size: 5.66px 5.66px;
}

h1 {
color: white;
width: fit-content;
}

.bg-light-blue {
background-color: #0EA5E9;
}

.text-light-blue {
color: #0EA5E9;
}

.bg-yellow {
background-color: rgba(233, 196, 14, 0.85);
}

.bg-yellow-50 {
background-color: rgba(233, 196, 14, 0.5);
}

.text-gold {
color: rgba(112, 93, 0, 1);
}
12 changes: 12 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/sample/project

go 1.16

require (
github.com/andybalholm/brotli v1.0.3 // indirect
github.com/gofiber/fiber/v2 v2.15.0 // indirect
github.com/gofiber/template v1.6.13 // indirect
github.com/klauspost/compress v1.13.1 // indirect
github.com/valyala/fasthttp v1.28.0 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
501 changes: 501 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Alpine from 'alpinejs'
import '../css/styles.css';

Alpine.start()
61 changes: 61 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html"
"io/ioutil"
"log"
"os"
)

func main() {
port := flag.String("port", "8080", "port to use")
devMode := flag.Bool("dev", false, "enable dev mode")
flag.Parse()

templateEngine := html.New("./views", ".html")
templateEngine.Reload(*devMode)

app := fiber.New(fiber.Config{
Views: templateEngine,
})

app.Use(logger.New())

setupRouting(app)

log.Println(log.Ldate|log.Ltime|log.Lshortfile, fmt.Sprintf("Started service v1 on port: : %s. Dev mode is: %t", *port, *devMode))
log.Fatal(app.Listen(":" + *port))
}

func setupRouting(app *fiber.App) {
// => http://localhost:3000/static/js/script.js
// => http://localhost:3000/static/css/style.css
app.Static("/static", "./public")

app.Get("/", func(c *fiber.Ctx) error {
return c.Render("index", getContent("index"))
})
}

func getContent(name string) *fiber.Map {
jsonFile, err := os.Open(fmt.Sprintf("content/%s.json", name))

if err != nil {
fmt.Println(err)
}
defer jsonFile.Close()

byteValue, _ := ioutil.ReadAll(jsonFile)

var result fiber.Map
if err := json.Unmarshal(byteValue, &result); err != nil {
fmt.Println(err)
}

return &result
}
Loading

0 comments on commit 4588684

Please sign in to comment.