top | item 22711265

Show HN: Goyave – Golang Web Framework

75 points| SystemGlitch | 6 years ago |github.com

27 comments

order

TXV|6 years ago

Personally, I would still choose gin. Gin seems to be more straight to the point. To name one, compare goyave router.Route("PUT|PATCH", ...) with gin router.PUT() or router.PATCH(). Also I'm not a fan of adding a lot of functionality and opinionated behavior into web frameworks. e.g. configuration files that need to be in a specific place in my workdir, "automatic 404 when a database record is not found", etc.

But sure, if you want to get a server up and running from scratch very quickly for a POC or a simple API-over-a-database app, this lib might be a good starting point.

SystemGlitch|6 years ago

Fair point. The "automatic 404 when a database record is not found" is purely optional and something you choose to use or not, like all the other helpers. For example, see below code:

  func Show(response *goyave.Response, request *goyave.Request) {
    product := model.Product{}
    id, _ := strconv.ParseUint(request.Params["id"], 10, 64)
    result := database.GetConnection().First(&product, id)
    if response.HandleDatabaseError(result) {
      response.JSON(http.StatusOK, product)
    }
  }

"response.HandleDatabaseError" is the helper we're talking about.

hssys|6 years ago

Doesn't Gin still have big issues where it's not compatible with native net/http middleware?

Jemaclus|6 years ago

Can you elaborate a bit on what features were added on top of the standard library or other popular libraries? A lot of this stuff is very similar to viper (configuration), mux (routing), gorm (database), so I'm wondering if there are additional features on top of those, or maybe the goal was to wrap it all into a single framework for ease of use?

Very interesting project. Good job. :)

SystemGlitch|6 years ago

Thank you!

Yes there are quite a lot of features added to the package:

- Request validation

- Localization (for validation error messages and regular text)

- Authentication (with built-in Basic Auth and JWT authenticators, directly using your User model. You can easily implement your own authenticators too)

- CORS

- Status handlers (for default responses depending on the response status when the body is empty, handy for error handling)

- Logging (using Common or Combined log format. You can implement your own formatters too)

- Advanced testing with test suites making it easy to write functional tests, unit tests for your middleware, etc.

- Database testing with record generators and seeders

- Many helpers to make your life easier (that includes multi-values header parsing, file management, automatic 404 when a database record is not found, etc). There are a lot of small things!

- An extensive and pretty documentation. This aspect very important to me.

I try to make it as flexible as possible to let developers implement things for their specific needs without having to fork the framework.

eyegor|6 years ago

Anyone know how this compares to iris? (iris is faster than gin and has a truckload of examples, not sure why it's less popular).

https://github.com/kataras/iris/blob/master/README.md

faizmokhtar|6 years ago

the reason why it's not popular is probably because of the controversy it have before

sethammons|6 years ago

I'm not a fan of non-standard-lib compatible routers. I understand why the op chose to do so, but it doesn't jive with being able to change the implementation later. I'm a fan of Chi for routing and it it compatible with the standard lib. I'm def in the camp of pulling in libraries vs full frameworks.

That said, there is always room for improvement for the development workflow, especially for rapid prototyping. I'd be interested in a side by side comparison between this and the other batteries-included web frameworks such as Gin, Buffalo, Beego, Revel, and the standard lib.

partisan|6 years ago

Those validation rules are scary to look at. They are cryptic strings that express some limited form of logic in that can only be verified at runtime. Is this the state of the art for Go?

dougbarrett|6 years ago

I know the plugins for VS Code can parse them and find errors prior to building.

sneak|6 years ago

Please stop using json for config files. Config files that cannot be commented are terrible for maintainability.

Everything that can read json has the ability to read yaml. Please use yaml instead.

lenkite|6 years ago

Prefer toml over yaml. Large Yaml files are a nightmare to edit with all the special spacing. JSON might be comment unfriendly but it is easily editable.

They just need to have a version of JSON with comments: JSONC and JSON is good.

smt88|6 years ago

As a heavy YAML user for a while (writing and maintaining Open API Spec files), YAML is also a catastrophe. I should not have to "debug" a config file because some tiny whitespace issue is off.

JSON as config isn't good, but YAML is not a silver bullet.

SystemGlitch|6 years ago

I agree that config is quite weak in Goyave. I planned to rework it in a later major version. But I don't want to release breaking changes one by one.

atraac|6 years ago

JSON5 supports comments. NET Core has been working with comments inside .json appsettings files for a very long time now.

hombre_fatal|6 years ago

This is just your arbitrary hobbyhorse opinion about something yet you're saying it with an absoluteness that doesn't make me think you realize that.

TACIXAT|6 years ago

Integration with auto cert would be really nice. That is usually the biggest chunk in the body of my Go servers' main functions.

Edit: Is it also easy to hook up a CRSF middleware?

I guess that's my pain point with modern web development. Most cool features need SSL, you should add CSRF protections, gotta pick a good password hashing algorithm. I know how to do it but it's a bunch of tedious work when I just want to hack something together. Would love a framework that streamlines all that.

SystemGlitch|6 years ago

You can give a path to your SSL cert in the config, and set "protocol" to "https" and you're done. If you're using Certbot, give the path to the live cert and it will work even after renewal.

About CSRF, as the framework is focused on APIs, the use of cookies is possible but not recommended, so you won't need CSRF protection when using Goyave.

masa331|6 years ago

i suggest looking at Rails. It streamlines a lot more than ^^^

dylkil|6 years ago

how does this compare to gin?

SystemGlitch|6 years ago

Goyave is slower than Gin but provides more features such as regex in routes, validation, language support, among others.

shagabutdinov|6 years ago

It's not a framework. It's just a toolbox and set of libraries. There is no inversion of control which is the core point of frameworks.