From 68832eaf353ce284f6026a09bf0e8f6954452134 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 9 Mar 2023 09:01:56 +0300 Subject: [PATCH] feat: initial commit --- go.mod | 16 ++++++++++++++++ main.go | 20 ++++++++++++++++++++ src/handlers/index/index.go | 10 ++++++++++ src/routes/routes.go | 10 ++++++++++ 4 files changed, 56 insertions(+) create mode 100644 go.mod create mode 100644 main.go create mode 100644 src/handlers/index/index.go create mode 100644 src/routes/routes.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1e60393 --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module notashelf.dev/api + +go 1.19 + +require ( + github.com/fasthttp/router v1.4.16 + github.com/joho/godotenv v1.5.1 + github.com/valyala/fasthttp v1.44.0 +) + +require ( + github.com/andybalholm/brotli v1.0.4 // indirect + github.com/klauspost/compress v1.15.15 // indirect + github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect + github.com/valyala/bytebufferpool v1.0.0 // indirect +) diff --git a/main.go b/main.go new file mode 100644 index 0000000..799cda3 --- /dev/null +++ b/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "log" + "os" + "github.com/fasthttp/router" + "github.com/valyala/fasthttp" + _ "github.com/joho/godotenv/autoload" + + "notashelf.dev/api/src/routes" +) + +func main() { + r := router.New() + routes.InitRoutes(r) + port := os.Getenv("PORT") + fmt.Println("API on port: " + port) + log.Fatal(fasthttp.ListenAndServe(":" + port, r.Handler)) +} diff --git a/src/handlers/index/index.go b/src/handlers/index/index.go new file mode 100644 index 0000000..146d7ed --- /dev/null +++ b/src/handlers/index/index.go @@ -0,0 +1,10 @@ +package index + +import ( + "github.com/valyala/fasthttp" +) + +func IndexHandler(ctx *fasthttp.RequestCtx) { + ctx.SetContentType("text/html") + ctx.WriteString("Hello World!") +} diff --git a/src/routes/routes.go b/src/routes/routes.go new file mode 100644 index 0000000..603beb7 --- /dev/null +++ b/src/routes/routes.go @@ -0,0 +1,10 @@ +package routes + +import ( + "github.com/fasthttp/router" + "github.com/jckli/api/src/handlers/index" +) + +func InitRoutes(r *router.Router) { + r.GET("/", index.IndexHandler) +}