Golar v0.5.1

Full-stack framework for Go

Laravel's developer experience, built on the Go standard library.

Golar generates API, Web and Full Stack projects and gives them routing, validation, an ORM, authentication, sessions and mail, while net/http handlers, database/sql and standard middleware keep working as usual.

terminal
go install github.com/dayanchm/golar/cmd/golar@v0.5.1
golar new blog --template fullstack --frontend react \
  --database sqlite --auth session
cd blog && go mod tidy && golar migrate && golar serve

What's included

Handlers that read like the problem

Handlers return errors. The default error handler turns validation failures into 422 JSON, oversized bodies into 413 and everything unexpected into a logged 500, so the happy path stays short.

  • Plain func(http.Handler) http.Handler middleware
  • Session IDs and tokens stored as SHA-256 hashes
  • Tested against real SQLite, PostgreSQL and MySQL
type CreatePost struct {
    Title string `json:"title" validate:"required,max=120"`
    Body  string `json:"body" validate:"required"`
}

app := golar.New()
app.Use(middleware.RequestID(), middleware.Logger(), middleware.Recovery())

app.Post("/posts", func(c *golar.Context) error {
    var in CreatePost
    if err := c.Validate(&in); err != nil {
        return err // 422 with field errors
    }
    post := models.Post{Title: in.Title, Body: in.Body}
    if err := orm.Create(c.Context(), db, &post); err != nil {
        return err
    }
    return c.JSON(http.StatusCreated, post)
})