Initial migration

This commit is contained in:
pro100ton 2024-11-02 14:09:44 +03:00
commit c732fdec46
18 changed files with 462 additions and 0 deletions

46
.air.toml Normal file
View file

@ -0,0 +1,46 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ./cmd/main.go"
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
main_only = false
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
keep_scroll = true

25
.gitignore vendored Normal file
View file

@ -0,0 +1,25 @@
# ---> Go
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work
.eslintrc.js
tmp/*
tmp

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM golang:1.23-alpine
WORKDIR /app
RUN go install github.com/air-verse/air@latest
COPY go.mod go.sum ./
RUN go mod download && go mod verify
CMD ["air", "-c", ".air.toml"]

27
README.md Normal file
View file

@ -0,0 +1,27 @@
# go_templates
Go templates playground project
# Описание
Данный проект использует фреймворк fiber + стандартные темплейты go - "html"
# Полезные команды
Сборка проекта
```
docker compose build
```
Сборка без кэша
```
docker compose build --no-cache
```
Чтобы провалиться во внутрь контейнера
```
docker exec -ti <container_name> sh
```

24
cmd/main.go Normal file
View file

@ -0,0 +1,24 @@
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
"git.pro100code.ru/pro100ton/go_templates/routes"
)
type TrainingEquipment struct {
Name []string
}
func main() {
engine := html.New("./views", ".html")
app := fiber.New(fiber.Config{
Views: engine,
})
routes.RegisterRoutes(app)
app.Listen(":3000")
}

17
compose.yaml Normal file
View file

@ -0,0 +1,17 @@
services:
fiber:
build:
context: .
dockerfile: Dockerfile
ports:
- target: 3000
published: 3001
networks:
- fiber-net
volumes:
- type: bind
source: .
target: /app
networks:
fiber-net:

21
go.mod Normal file
View file

@ -0,0 +1,21 @@
module git.pro100code.ru/pro100ton/go_templates
go 1.22.5
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/template/html/v2 v2.1.2 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)

33
go.sum Normal file
View file

@ -0,0 +1,33 @@
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
github.com/gofiber/template/html/v2 v2.1.2 h1:wkK/mYJ3nIhongTkG3t0QgV4ADdgOYJYVSAF2AHnh8Y=
github.com/gofiber/template/html/v2 v2.1.2/go.mod h1:E98Z/FzvpaSib06aWEgYk6GXNf3ctoyaJH8yW5ay5ak=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

18
models/exerciseModels.go Normal file
View file

@ -0,0 +1,18 @@
package models
// TODO: Create actual models instead of simple structs
// TODO: Add correct types
type ExerciseSandbox struct {
Name string
Weight string
Reps string
}
type ExerciseAttempt struct {
Weight float32
Reps int32
}
type Exercise struct {
Name string
}

16
routes/routes.go Normal file
View file

@ -0,0 +1,16 @@
package routes
import (
"github.com/gofiber/fiber/v2"
"git.pro100code.ru/pro100ton/go_templates/services"
)
func RegisterRoutes(app *fiber.App) {
app.Get("/", services.TrainingItemsRenderer)
app.Get("/training/equipment", services.TrainingEquipmentJSONGetter)
app.Get("/training/equipment/render", services.TrainingEquipmentRenderer)
// app.Get("/exercises/render", services.ExercisesRenderer)
app.Get("/exercises/form", services.ExercisesFormRenderer)
app.Post("/exercises/form/submit", services.ExercisesFormHanlder)
}

51
services/exercises.go Normal file
View file

@ -0,0 +1,51 @@
package services
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"git.pro100code.ru/pro100ton/go_templates/models"
// "git.pro100code.ru/pro100ton/go_templates/utils"
)
var exercise []models.ExerciseSandbox
// func ExercisesJSONGetter(c *fiber.Ctx) error {
// exercies := utils.GenerateExercises()
// return c.JSON(exercies)
// }
//
// func ExercisesRenderer(c *fiber.Ctx) error {
// exercies := utils.GenerateExercises()
// return c.Render("exercises/exercises", fiber.Map{
// "data": exercies,
// })
// }
func ExercisesFormRenderer(c *fiber.Ctx) error {
return c.Render("forms/exercise_enter_form", nil)
}
func ExercisesFormHanlder(c *fiber.Ctx) error {
log.Info(c.FormValue("exercise-name"))
log.Info(c.FormValue("attempt-weight-name"))
log.Info(c.FormValue("attempt-reps-name"))
exerciseName := c.FormValue("exercise-name")
attemptWeight := c.FormValue("attempt-weight-name")
attemptReps := c.FormValue("attempt-reps-name")
log.Info(exerciseName, attemptWeight, attemptReps)
exercise = append(
exercise,
models.ExerciseSandbox{
Name: exerciseName,
Weight: attemptWeight,
Reps: attemptReps,
},
)
log.Info("---")
log.Info(exercise)
return c.Render("training/training_table", fiber.Map{
"data": exercise,
})
}

27
services/sandbox.go Normal file
View file

@ -0,0 +1,27 @@
package services
import "github.com/gofiber/fiber/v2"
type TrainingEquipment struct {
Name []string
}
func TrainingItemsRenderer(c *fiber.Ctx) error {
trainDevices := [3]string{"Гравитроныч", "Тяга горизонтального блока", "Тяга вертикального блока"}
return c.Render("index", fiber.Map{
"TrainingItems": trainDevices,
})
}
func TrainingEquipmentJSONGetter(c *fiber.Ctx) error {
equipment_data := TrainingEquipment{
Name: []string{"Гравитроныч", "Тяга вертикального блока", "Тяга горизонтального блока"},
}
return c.JSON(equipment_data)
}
func TrainingEquipmentRenderer(c *fiber.Ctx) error {
return c.Render("training/equipment", fiber.Map{
"anchor": "some kek data",
})
}

View file

@ -0,0 +1,45 @@
// package utils
//
// import "git.pro100code.ru/pro100ton/go_templates/models"
//
// func GenerateExercises() []models.ExerciseSandbox {
// exercises := []models.ExerciseSandbox{
// {
// Name: "Гравитрон",
// Weight: 30,
// Reps: 12,
// },
// {
// Name: "Гравитрон",
// Weight: 10,
// Reps: 10,
// },
// {
// Name: "Гравитрон",
// Weight: 10,
// Reps: 10,
// },
// {
// Name: "Жим гантели в наклоне",
// Weight: 28,
// Reps: 12,
// },
// {
// Name: "Жим гантели в наклоне",
// Weight: 28,
// Reps: 10,
// },
// {
// Name: "Жим гантели в наклоне",
// Weight: 26,
// Reps: 10,
// },
// {
// Name: "Жим гантели в наклонe",
// Weight: 26,
// Reps: 8,
// },
// }
//
// return exercises
// }

View file

@ -0,0 +1,25 @@
<!doctype html>
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
</head>
<body>
<table>
<tr>
<th>Имя</th>
<th>Вес</th>
<th>Повторения</th>
</tr>
{{range .data}}
<tr>
<td>{{.Name}}</td>
<td>{{.Weight}}</td>
<td>{{.Reps}}</td>
</tr>
{{end}}
</table>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!doctype html>
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Exercise form</title>
</head>
<body>
<h1>Please, enter exercise details</h1>
<form>
<label for="exercise-name-id">Exercise name</label><br>
<input type="text" name="exercise-name" id="exercise-name-id"><br>
<label for="attempt-weight-id">Weight</label><br>
<input type="text" name="attempt-weight-name" id="attempt-weight-id"><br>
<label for="attempt-reps-id">Reps</label><br>
<input type="text" name="attempt-reps-name" id="attempt-reps-id"><br>
<input hx-post="/exercises/form/submit" type="submit" value="Submit" hx-target="#exercise-table-id">
</form>
<div id="exercise-table-id"></div>
</body>
</html>

34
views/index.html Normal file
View file

@ -0,0 +1,34 @@
<!doctype html>
<script src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script src="https://code.jquery.com/ui/1.14.0/jquery-ui.js"></script>
<script src="https://unpkg.com/htmx.org@2.0.3"></script>
<link
rel="stylesheet"
href="https://code.jquery.com/ui/1.14.0/themes/base/jquery-ui.css"
/>
<link rel="stylesheet" href="/resources/demos/style.css" />
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Some fancy template index page</title>
</head>
<body>
<h1>Some Hello {{ .Username}}!!</h1>
<button hx-put="/messages">Put To Messages</button>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
<button hx-get="/exercises/render" hx-target="#equipmentData">Press to test</button>
<div id="equipmentData"></div>
</body>
</html>
<script>
$(function () {
var availableTags = {{.TrainingItems}};
$("#tags").autocomplete({
source: availableTags,
});
});
</script>

View file

@ -0,0 +1,4 @@
<p>1</p>
<p>2</p>
<p>{{ .anchor }}</p>
<p>4</p>

View file

@ -0,0 +1,15 @@
<table>
<tr>
<th>Имя упражнения</th>
<th>Вес</th>
<th>Повторения</th>
</tr>
{{range .data}}
<tr>
<td>{{.Name}}</td>
<td>{{.Weight}}</td>
<td>{{.Reps}}</td>
</tr>
{{end}}
</table>