syahidfrd / go-boilerplate Goto Github PK
View Code? Open in Web Editor NEWREST API boilerplate built with Go - Echo Framework
Home Page: https://pkg.go.dev/github.com/syahidfrd/go-boilerplate
License: MIT License
REST API boilerplate built with Go - Echo Framework
Home Page: https://pkg.go.dev/github.com/syahidfrd/go-boilerplate
License: MIT License
This boilerplate is very helpful for me to create go api projects without starting from scratch, but it would be nice if we implemented a graceful shutdown for the sake of the user, let's say the user is still in the middle of a request and we need to update our app or maybe our app crashes we can drain the connection first before shutting down.
i was tried to do long live request and send interruption signal then i got an error.
My proposal :
adding graceful shitdown using go routine and channel just like in the echo docs https://echo.labstack.com/cookbook/graceful-shutdown/
package main
/* folded code */
func main() {
/* folded code */
// Setup route engine & middleware
e := echo.New()
e.Use(middleware.CORS())
e.Use(appMiddleware.RequestID())
e.Use(appMiddleware.Logger())
e.Use(middleware.Recover())
// Setup handler
e.GET("/swagger/*", echoSwagger.WrapHandler)
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "i am alive")
})
httpDelivery.NewTodoHandler(e, appMiddleware, todoUC)
httpDelivery.NewAuthHandler(e, appMiddleware, authUC)
// gracefull shutdown
go func() {
if err := e.Start(fmt.Sprintf(":%s", configApp.ServerPORT)); err != nil && err != http.ErrServerClosed {
e.Logger.Fatal("shutting down the server")
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
}
it would be nice if you assign this issue to me because i'm gabut
Are you planning to add user signup and JWT auth to your boilerplate?
Hi, thanks for this boilerplate. I use it in my project. Do you think add gorm package to go-boilerplate?
I was able to get swagger docs served via echo server. One question, your jwt stuff uses uid and password for authentication. Is it possible to change to bearer auth tokens for authentication?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.