feat: initial commit

This commit is contained in:
NotAShelf 2023-03-09 09:01:56 +03:00
parent 4c5511e596
commit 68832eaf35
No known key found for this signature in database
GPG key ID: 419DBDD3228990BE
4 changed files with 56 additions and 0 deletions

16
go.mod Normal file
View file

@ -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
)

20
main.go Normal file
View file

@ -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))
}

View file

@ -0,0 +1,10 @@
package index
import (
"github.com/valyala/fasthttp"
)
func IndexHandler(ctx *fasthttp.RequestCtx) {
ctx.SetContentType("text/html")
ctx.WriteString("Hello World!")
}

10
src/routes/routes.go Normal file
View file

@ -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)
}