Post 9l2bNdfjdG5Sv56kFc by ivan@vucica.net
(DIR) More posts by ivan@vucica.net
(DIR) Post #9l2aAESdxIoP0g1mIC by jazzyeagle@mastodon.social
2019-07-20T12:14:32Z
0 likes, 0 repeats
Today on "What project should I work on", I am looking at the Go Language to understand how to make a web server. One article I read suggests I don't need a framework, because Go was written to support the web directly. I'm trying to read up on the http and template packages a bit this morning. @fribbledom would be pleased. :)
(DIR) Post #9l2aAFnaytAL9wq1aa by fribbledom@mastodon.social
2019-07-20T12:15:52Z
1 likes, 1 repeats
@jazzyeagle You can totally get away without a framework. I'd even recommend it to learn how the basic/native http package works.Most of the frameworks really just provide a bunch of middleware for logging, data validation, caching etc.
(DIR) Post #9l2aeZjLROpRfBJAyO by ivan@vucica.net
2019-07-20T12:21:04.843287Z
0 likes, 0 repeats
@jazzyeagle There's not many ~statically-typed languages where I can easily create a simple as well as powerful web server using just the standard library.And then, to get URL templating, I can still switch to Gorilla Mux or similar.@fribbledom
(DIR) Post #9l2bIUQSaBKAnKVXea by jazzyeagle@mastodon.social
2019-07-20T12:23:07Z
1 likes, 0 repeats
@ivan @fribbledom Thanks, Ivan! I'll read up on Gorilla Mux as well, then. The http package read was fairly quick and thankfully pretty easy to understand, but URL templating was one of my biggest unknowns at this point.
(DIR) Post #9l2bIVhVqGYikVUfs8 by ivan@vucica.net
2019-07-20T12:28:34.615533Z
0 likes, 0 repeats
@jazzyeagle For most tiny projects I can get away with 'if r.URL.Path == *prefix + "some/path"'.Where r is an *http.Request, and where globally:var ( prefix = flag.String("prefix", "/", "slash-terminated prefix for all URLs on this server"))(explaining the dereference)Some substring magic and regexes are filthy, but good enough for tiny projects.Mux is the mid-level thing. I bet people needing something even more powerful and consistent would use something else. I'm just sharing what I use.Also... if you need inter-process communication, look at gRPC for making remote procedure calls. You can also build an HTTP API for this using gRPC-Gateway. (gRPC exists for other languages too, and gRPC-Gateway doesn't care what the backend service is written in; it just so happens to be that gRPC-Gateway is written in Go and generates Go code that you can spin up.)Go is a really nice thing to look at if you want to write web services or a bunch of microservices in a ~statically-typed language. Good luck!@fribbledom
(DIR) Post #9l2bNdfjdG5Sv56kFc by ivan@vucica.net
2019-07-20T12:29:31.555017Z
0 likes, 0 repeats
@jazzyeagle PS Of course, I put together these snippets above without referring to documentation -- yolo! @fribbledom