Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
go.rice
go.rice is a Go package that makes working with resources such as html,js,css,images,templates, etc very easy.
-
goa
π Goa: Elevate Go API development! π Streamlined design, automatic code generation, and seamless HTTP/gRPC support. β¨
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
Nice demo. A few things you could add to make this more realistic to something that gets shipped:
-CORS support. Deploy this to a non-local domain and try to reach it from a web browser and it will fail. I like https://github.com/rs/cors. I had rolled my own but then moved to that library.
- input validation. I like go-playground/validator.
The other big issue is the locking by hand around the task store. In reality usually there would be a database to handle concurrent read/writes. I use SQLite in production. I know this is just a demo and you want to use just stdlib, but serializing all data access is sort of unacceptable as a solution in a concurrent language like Go. When I'm not handling concurrency with SQLite I like to implement The actor pattern, having a persistent goroutine listen and respond to "taskstore" requests via channels.
> I've had this a few times, most recently with "how do I add this data file to my binary". At least that one made it to master now, and will be in 1.16!
And before 1.16, there is statik: https://github.com/rakyll/statik.
How does statik compare to rice, which is what I had assumed everyone was using: https://github.com/GeertJohan/go.rice
It depends on what the struct contains. I have developed many Go API's professionally at several companies since Go 1.1, and all my servers and up looking like a server struct with only a few fields - a database, AWS client object, and some prometheus metrics. The logic is typically split among many files, all implementing receivers on that struct.
If you have independent, different elements in that API, you break them out into separate "servers" but still register the endpoints on the same HTTP handler.
I know that people don't like external libraries too much, but I'd like to plug my own here. You declare your API in OpenAPI 3.0 (aka, Swagger) and it generates your server and models for you, so all you need to do is write the business logic. (https://github.com/deepmap/oapi-codegen)
- similar to grpc gateway you just need to conform to the generated codeβs service interface.
I believe it supports, http, websocket and grpc.
[1]https://github.com/goadesign/goa
Related posts
- [Request] Library Recommendation for Auto Swagger/OpenAPIv3 Documentation
- Is there a way to generate controller from swagger through build tools?
- how to update swagger logo (API documentation)
- chai - a library for type safe http handlers via generics with automatic swagger generation
- IBM to Acquire HashiCorp, Inc