Hacker News new | ask | show | jobs
Show HN: Goyave – Golang Web Framework (github.com)
75 points by SystemGlitch 2270 days ago
10 comments

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.

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.
Doesn't Gin still have big issues where it's not compatible with native net/http middleware?
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. :)

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.

Excellent. Thank you.
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

There was some controversy with its primary maintainer a while ago, not sure how it's progressed since. I can't speak of the technical side, however.

https://github.com/avelino/awesome-go/pull/1137

http://www.florinpatan.ro/2016/10/why-you-should-not-use-iri...

the reason why it's not popular is probably because of the controversy it have before
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.

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?
I know the plugins for VS Code can parse them and find errors prior to building.
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.

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.

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.

Definitely agree that YAML is not a silver bullet. One thing that I’ve found to improve my YAML editing experience is to use a YAML language server [1] backed by JSON schemas. It provides a real time feedback cycle rather than handing the file off to another program to choke cryptically.

[1] https://github.com/redhat-developer/vscode-yaml/blob/master/...

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.
JSON5 supports comments. NET Core has been working with comments inside .json appsettings files for a very long time now.
json5 is a neat idea, but if you’re going to use a serialization format that isn’t json, yaml is the way to go, despite its known minor inconveniences. Everything can read json and yaml. Not much can read json5.
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.
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.

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.

i suggest looking at Rails. It streamlines a lot more than ^^^
how does this compare to gin?
Goyave is slower than Gin but provides more features such as regex in routes, validation, language support, among others.
We should be
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.