initial commit
This commit is contained in:
24
LICENSE
Normal file
24
LICENSE
Normal file
@@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
30
go.mod
Normal file
30
go.mod
Normal file
@@ -0,0 +1,30 @@
|
||||
module github.com/juls0730/zqdgr-fiber-starter
|
||||
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
github.com/atotto/clipboard v0.1.4 // indirect
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/catppuccin/go v0.2.0 // indirect
|
||||
github.com/charmbracelet/bubbles v0.20.0 // indirect
|
||||
github.com/charmbracelet/bubbletea v1.1.0 // indirect
|
||||
github.com/charmbracelet/huh v0.6.0 // indirect
|
||||
github.com/charmbracelet/lipgloss v0.13.0 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.2.3 // indirect
|
||||
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-localereader v0.0.1 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
golang.org/x/sys v0.25.0 // indirect
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
)
|
||||
51
go.sum
Normal file
51
go.sum
Normal file
@@ -0,0 +1,51 @@
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||
github.com/catppuccin/go v0.2.0 h1:ktBeIrIP42b/8FGiScP9sgrWOss3lw0Z5SktRoithGA=
|
||||
github.com/catppuccin/go v0.2.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc=
|
||||
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
|
||||
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
||||
github.com/charmbracelet/bubbletea v1.1.0 h1:FjAl9eAL3HBCHenhz/ZPjkKdScmaS5SK69JAK2YJK9c=
|
||||
github.com/charmbracelet/bubbletea v1.1.0/go.mod h1:9Ogk0HrdbHolIKHdjfFpyXJmiCzGwy+FesYkZr7hYU4=
|
||||
github.com/charmbracelet/huh v0.6.0 h1:mZM8VvZGuE0hoDXq6XLxRtgfWyTI3b2jZNKh0xWmax8=
|
||||
github.com/charmbracelet/huh v0.6.0/go.mod h1:GGNKeWCeNzKpEOh/OJD8WBwTQjV3prFAtQPpLv+AVwU=
|
||||
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
|
||||
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
|
||||
github.com/charmbracelet/x/ansi v0.2.3 h1:VfFN0NUpcjBRd4DnKfRaIRo53KRgey/nhOoEqosGDEY=
|
||||
github.com/charmbracelet/x/ansi v0.2.3/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
||||
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4=
|
||||
github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ=
|
||||
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
|
||||
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
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-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
|
||||
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
|
||||
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4=
|
||||
github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
|
||||
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
|
||||
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
|
||||
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
|
||||
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a h1:2MaM6YC3mGu54x+RKAA6JiFFHlHDY1UbkxqppT7wYOg=
|
||||
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a/go.mod h1:hxSnBBYLK21Vtq/PHd0S2FYCxBXzBua8ov5s1RobyRQ=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
281
main.go
Normal file
281
main.go
Normal file
@@ -0,0 +1,281 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
type Middleware struct {
|
||||
Name string
|
||||
Url string
|
||||
}
|
||||
|
||||
var middlewares = []Middleware{
|
||||
{
|
||||
Name: "Adaptor",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/adaptor",
|
||||
},
|
||||
{
|
||||
Name: "BasicAuth",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/basicauth",
|
||||
},
|
||||
{
|
||||
Name: "Cache",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/cache",
|
||||
},
|
||||
{
|
||||
Name: "Compress",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/compress",
|
||||
},
|
||||
{
|
||||
Name: "Cors",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/cors",
|
||||
},
|
||||
{
|
||||
Name: "CSRF",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/csrf",
|
||||
},
|
||||
{
|
||||
Name: "EarlyData",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/earlydata",
|
||||
},
|
||||
{
|
||||
Name: "EncryptCookie",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/encryptcookie",
|
||||
},
|
||||
{
|
||||
Name: "EnvVar",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/envvar",
|
||||
},
|
||||
{
|
||||
Name: "Etag",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/etag",
|
||||
},
|
||||
{
|
||||
Name: "ExpVar",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/expvar",
|
||||
},
|
||||
{
|
||||
Name: "Favicon",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/favicon",
|
||||
},
|
||||
{
|
||||
Name: "Health Check",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/healthcheck",
|
||||
},
|
||||
{
|
||||
Name: "Helmet",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/helmet",
|
||||
},
|
||||
{
|
||||
Name: "Idempotency",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/idempotency",
|
||||
},
|
||||
{
|
||||
Name: "KeyAuth",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/keyauth",
|
||||
},
|
||||
{
|
||||
Name: "Limiter",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/limiter",
|
||||
},
|
||||
{
|
||||
Name: "Logger",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/logger",
|
||||
},
|
||||
{
|
||||
Name: "Monitor",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/monitor",
|
||||
},
|
||||
{
|
||||
Name: "Pprof",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/pprof",
|
||||
},
|
||||
{
|
||||
Name: "Proxy",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/proxy",
|
||||
},
|
||||
{
|
||||
Name: "Recover",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/recover",
|
||||
},
|
||||
{
|
||||
Name: "Redirect",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/redirect",
|
||||
},
|
||||
{
|
||||
Name: "RequestID",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/requestid",
|
||||
},
|
||||
{
|
||||
Name: "Rewrite",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/rewrite",
|
||||
},
|
||||
{
|
||||
Name: "Session",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/session",
|
||||
},
|
||||
{
|
||||
Name: "Skip",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/skip",
|
||||
},
|
||||
{
|
||||
Name: "Static",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/static",
|
||||
},
|
||||
{
|
||||
Name: "Timeout",
|
||||
Url: "github.com/gofiber/fiber/v3/middleware/timeout",
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Printf("Usage: %s <targetDir>\n", os.Args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
targetDir := os.Args[1]
|
||||
cmd := exec.Command("go", "get", "-u", "github.com/gofiber/fiber/v3")
|
||||
cmd.Dir = targetDir
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
options := []huh.Option[Middleware]{}
|
||||
for _, m := range middlewares {
|
||||
options = append(options, huh.NewOption(m.Name, m))
|
||||
}
|
||||
|
||||
selectedMiddlewares := make([]Middleware, 0)
|
||||
|
||||
form := huh.NewForm(
|
||||
huh.NewGroup(
|
||||
huh.NewMultiSelect[Middleware]().
|
||||
Title("Middlewares").
|
||||
Options(
|
||||
options...,
|
||||
).
|
||||
Value(&selectedMiddlewares),
|
||||
),
|
||||
)
|
||||
|
||||
err = form.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Remove("main.go")
|
||||
|
||||
goMod, err := os.Open("go.mod")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: erratic directory structure\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
defer goMod.Close()
|
||||
|
||||
moduleName := ""
|
||||
scanner := bufio.NewScanner(goMod)
|
||||
for scanner.Scan() {
|
||||
if strings.HasPrefix(scanner.Text(), "module ") {
|
||||
moduleName = strings.TrimSpace(strings.TrimPrefix(scanner.Text(), "module "))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if moduleName == "" {
|
||||
fmt.Printf("Error: could not find module name in go.mod\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
goMain, err := os.Create("main.go")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer goMain.Close()
|
||||
|
||||
err = goMain.Truncate(0)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = goMain.Seek(0, 0)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
middlewaresImport := ""
|
||||
middlewaresUse := ""
|
||||
|
||||
for i, middleware := range selectedMiddlewares {
|
||||
if i == 0 {
|
||||
middlewaresUse += "\n"
|
||||
}
|
||||
|
||||
middlewaresUse += fmt.Sprintf("\tapp.Use(%s.New())\n", strings.ReplaceAll(strings.ToLower(middleware.Name), " ", ""))
|
||||
middlewaresImport += fmt.Sprintf("\t\"%s\"\n", middleware.Url)
|
||||
|
||||
if i == len(selectedMiddlewares)-1 {
|
||||
middlewaresUse += "\n"
|
||||
}
|
||||
}
|
||||
|
||||
os.MkdirAll("internal/handlers", 0755)
|
||||
handlers, err := os.Create("internal/handlers/time.go")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer handlers.Close()
|
||||
|
||||
_, err = handlers.WriteString(`package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
func Time(c fiber.Ctx) error {
|
||||
return c.SendString(fmt.Sprintf("The time is %s", time.Now().Format(time.RFC1123)))
|
||||
}
|
||||
|
||||
`)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = goMain.WriteString(fmt.Sprintf(`package main
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
%s
|
||||
"%s/internal/handlers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := fiber.New()
|
||||
%s
|
||||
app.Get("/", handlers.Time)
|
||||
|
||||
app.Listen(":3000")
|
||||
}
|
||||
`, middlewaresImport, moduleName, middlewaresUse))
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
13
zqdgr.config.json
Normal file
13
zqdgr.config.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "Go Project",
|
||||
"version": "0.0.1",
|
||||
"description": "Example description",
|
||||
"author": "you",
|
||||
"license": "BSL-1.0",
|
||||
"scripts": {
|
||||
"build": "go build -o main",
|
||||
"dev": "go run main.go"
|
||||
},
|
||||
"pattern": "**/*.go",
|
||||
"excluded_dirs": []
|
||||
}
|
||||
Reference in New Issue
Block a user