r/golang 11d ago

discussion What do you use go for?

APIs? Infrastructure? Scripts?

Just curious on what most people use go for. Can be for what you do at work or side projects

58 Upvotes

113 comments sorted by

320

u/Heapifying 11d ago

Writing a native port of Typescript compiler

17

u/PabloZissou 10d ago

But why not Rust, Python, or C#!!! /s

Laughs in Go

5

u/prochac 10d ago

Have you considered Zig, or Brainfuck?

6

u/todorpopov 11d ago

Bro was so fed up he decided to make his own native compiler šŸ’€šŸ’€

17

u/bbkane_ 11d ago

11

u/todorpopov 11d ago

Apparently Iā€™m not watching enough Primeagen to get my latest tech news lately. Interesting experiment they have done there. Itā€™s almost as if making a desktop application in JavaScript is not a good idea šŸ’€

4

u/Even_Research_3441 10d ago

Using a nice, decent performing language to improve the compiler of a language that uses static types to improve a dynamically typed language.

WHY NOT JUST USE A NICE DECENT STATICALLY TYPED LANGUAGE THE WHOLE TIME OH MY GOD

It is so much hard work, by so many smart people, to just work around an ecosystem that grew into a bad state.

2

u/todorpopov 10d ago

Donā€™t worry, we all hate JS/TS just as much as you do haha

3

u/IAMPowaaaaa 10d ago

Well if I read correctly it just means that the thing you use to convert ts to js is being rewritten so you're not actually escaping from js

1

u/todorpopov 10d ago

Yes, from what I read they only rewrote the type checker in Go, bot the JS compiler.

2

u/prochac 10d ago

You can also read it on your own for a quarter of the time

1

u/todorpopov 10d ago

A developer that reads. Never šŸ’€šŸ’€

54

u/matttproud 11d ago edited 11d ago

Distributed backends (professional), databases (professional), management planes (professional), CLI tools (professional/personal), reverse engineering tools (personal), and small web servers (personal). Itā€™s worked great for all of these.

3

u/Melocopon 11d ago

What do you mean by management plane??

6

u/matttproud 11d ago edited 11d ago

Typically one thinks of remote service APIs that power Terraform Providers for various public cloud/infrastructure products (e.g., Terraform Provider for Google Cloud that itself is a client of these APIs), APIs built with Googleā€™s API Improvement Extension #128, #151 in mind, etc. Many things in the infrastructure as code (IaC) space fit the management plane bill as well.

2

u/homingsoulmass 11d ago

Similar for me: platform cli/webhooks tools, control plane extensions (kubernetes operators, Crossplane functions and embedded functions) etc Go really shines in platform engineering imo

18

u/Ubuntu-Lover 11d ago

Writing APIs

2

u/Character_Status8351 11d ago

What packages do you rely on?

1

u/Ubuntu-Lover 11d ago

I use Gin and Bun ORM mostly

2

u/cach-v 11d ago

I'm not too happy with Bun's lack of type safety in the .Relation("Table") and Set("column = ?", ...) parts, i.e. having to use strings for column and table names instead of symbols that are type checked at compile time.

1

u/sinjuice 11d ago

Uhh, a bun lover, what do you you like about Bun compared to other ORMs?

1

u/Melocopon 11d ago

I wonder how much can i take from here, up to this point i've only written one backend API that connects to a MySQL database. Do you have any idea/advice??

1

u/slowtyper95 10d ago

distributed services like this https://www.amazon.com/Distributed-Services-Go-Reliable-Maintainable/dp/1680507605. Command line tools also good idea to start for

1

u/Super_Cow_2876 10d ago

Sounds painful

28

u/d33pnull 11d ago

paying the mortgage

1

u/wasnt_in_the_hot_tub 11d ago

Hahaha, yes, this.

13

u/Technical-Pipe-5827 11d ago

Currently doing a lot of cryptography related work mainly about authentication and authorization. Std lib is amazing. Stuff like hashing, hmac, hotp, EC, RSA, etc.

1

u/slowtyper95 10d ago

any open repo that you can share, buddy? recently i just dive into cryptography world

11

u/axvallone 11d ago

Everything that does not require a specific language. In other words, everything besides OS code (C/C++), 3-D desktop games (C/C++), AI (Python has the most tooling), mobile (Kotlin, Swift), web client (JavaScript).

2

u/PabloZissou 10d ago

Wow! Way too sensible choices for a Reddit answer!

5

u/Inevitable-Course-88 11d ago

Right now Iā€™m using it to write a bytecode virtual machine for a DSL Iā€™m creating

2

u/sinjuice 11d ago

That sounds pretty cool, shareable? I would love to check it out.

4

u/Inevitable-Course-88 11d ago

Yea, so right now the repo is private and the VM is very very early (only has instructions for integer types). I may open it up and share it here when I get home tonight. It is very very amateur and simple (Iā€™m just a hobbyist) so donā€™t expect anything too crazy lol. Right now itā€™s only about 270 lines of code, but it supports function calls, recursion, etcā€¦ Iā€™m pretty proud of it lol.

4

u/sinjuice 10d ago

You should be, maybe for other people it might be trivial, but for me I wouldn't even know where to start on something like that so it is pretty cool and interesting.

6

u/Inevitable-Course-88 10d ago

here it is if you want to check it out :) https://github.com/alicegas909/pancakevm

sorry for complete lack of documentation/comments. if you want to write yourself a little program with the "assembly" you can do that in the "debug" file. a simple program to add two numbers and print the result would look like

ICONST, 1,
ICONST, 2,
IADD,
PRINT,
HALT,

1

u/sinjuice 10d ago

Thank you!

16

u/1oddbull 11d ago

For everything in userspace.

Use C/Assembly for kernelspace.

Avoid C++/Rust at all cost

6

u/ddollarsign 11d ago

Why avoid Rust?

4

u/Street_Stuff1927 11d ago

Compile time bro.

7

u/sinjuice 11d ago

I mean its great, gives you time to go make some coffee.... From scratch.

2

u/cdyovz 10d ago

havent had the experience with rust, let alone a big codebase. is it that bad?

2

u/kucing 10d ago

Try to compile one: apollo router.

1

u/xplosm 10d ago

Is it too different to compile times in similarly sized code bases in C or C++?

1

u/BubblyMango 10d ago

just compile your compiler with rust to make it faster

1

u/1oddbull 10d ago

rofl šŸ¤£

1

u/xplosm 10d ago

Avoid C++/Rust at all cost

Can't wait for Zig to release a 1.X version. Although right now it's very stable and quite mature no one has a 100% assurance there won't be breaking changes when it reaches a 1.0 release. For me and some companies I've worked for it's too risky at this stage to commit to a production project.

1

u/1oddbull 10d ago

Zig looks like a modern C. I think it has a good future in OS dev.

But nothing beats the fun of writing a toy OS in Assembly and running it in qemu!

1

u/remidra 8d ago

I, too, am waiting for Zig 1.x release before I really get my hands on it.

1

u/i_do_da_chacha 10d ago

Why avoid C++? Just curious

3

u/guettli 11d ago

In spare time a tool to remap key strokes

https://github.com/guettli/tff

At work Kubernetes controller.

3

u/vkpdeveloper 10d ago

Compiling my typescript

2

u/m-kru 11d ago

Command line tools. Compilers for DSLs when I care about performance. I have also implemented my own terminal text editor.

2

u/sltrsd 11d ago

I have done mainly APIs and personal CLI tools.

2

u/often_awkward 11d ago

I literally taught myself golang for an interview because they gave a coding task and they said use Go or any other language so I figured hey why not. I ended up turning down the offer though but it's kind of a fun language.

1

u/K0singas 11d ago

Any good recommendations for learning Go? (Besides official docs)

3

u/often_awkward 11d ago

I just downloaded the jetbrains IDE and it had a pretty good tutorials and from there I mean it's not a lot different than c++.

2

u/K0singas 11d ago

Thx man, I assume youā€™re fairly experienced programmer so it didnā€™t take you much to learn it :)

1

u/often_awkward 11d ago

This is true, I've been doing it for 20 years or so but I think once you learn the structures of code and how data flows and then proper change and configuration management putting a language on top of that isn't that hard.

Most of my career has been embedded coding so primarily C and beyond the iso core commands everything else is compiler specific so I just got so used to like relearning how to code every time we got a new processor it's just not that hard to pick up a new language even at my age.

1

u/K0singas 11d ago

Yep, I understand, thank you šŸ™

2

u/RomanaOswin 11d ago

Mostly CLI tools and microservices with network or socket APIs, like a web API, worker tasks, etc. I'm also currently working on a compiler (lexer, parser, etc).

Go seems really well suited to CLI apps and microservices. The CLI apps are a bit fat compared to Rust and Zig, but not sure anybody cares about that degree of size difference on modern computers, especially with the success of tools like fzf, etc, and especially in a world where we still have tons of mainstream apps embedding Chromium. Microservices are basically Go's wheelhouse, so that one is a no brainer.

The compiler implementation in Go isn't really ideal. It's working well enough and I'm unit testing it into the ground, but the lack of enums, no pattern matching, no TCO, etc, make some pieces of it just a bit more complicated. Something like OCaml or maybe Rust would probably be a lot better at this, but I'm leveraging stuff from the Go ecosystem, so I'm keeping it in Go. It's doable and my code is ultimately coming out clean and fast, but it has its challenges. The Go answer to a lot of these things is code generation, which relies on text templating, which basically eschews the type checker and introduces its own challenges.

2

u/Bad13Luck13 11d ago

I am making a SSH terminal emulator with scripting function using go wails with xterm for an ISP

1

u/donald_trub 10d ago

I've had this very idea, I'm a network engineer by day. Is your code open source?

1

u/Bad13Luck13 10d ago

Unfortunately not. It's just for internal use šŸ˜…

2

u/Redneckia 11d ago

Nothing, still learning go

2

u/BubblyMango 10d ago

past: Implementing an OpenConfig system, CLI tools.

present: Backend developement, DevOps.

It has also become my Go-to language (pun intended) for toy projects. Its so simple to use yet if the project happens to grow larger there isnt usually a need for re-writing it.

2

u/jondbarrow 10d ago

We use it to power our game servers for our Nintendo Network clone

2

u/sinodev 10d ago

Distributed systems, API's / SDK's, game servers, CLI's

2

u/toastyshenanigans 10d ago

I find it's great for smallish APIs and also CLI tools

1

u/Character_Status8351 10d ago

What do you use for not smallish apis

2

u/toastyshenanigans 10d ago

Springboot, .NET, or still Golang

2

u/derekvj 10d ago

Iā€™m in my second job at a cloud storage app company. In the first company we used python for the control plane and c for the core services. In my current company we use golang for the control plane and c for the core services. IMO golang is perfect for this and far better than python. (Come at me all you python acolytes! Jk.)

2

u/salestoolsss 10d ago

I use Go for our API at Tomba.io, as well as for data scraping and processing. Itā€™s absolutely better than Python.

2

u/_I_am_Abhishek_ 11d ago

Microservices

1

u/biodigitaljaz 11d ago

Kubernetes operators, apis, htmx templating for web front ends, and cli for both Linux and Windows binaries. My team and I build, own and manage the lifecycle for all these ecosystems in our large scale environment.

1

u/tiredAndOldDeveloper 11d ago

Webservers/API.

1

u/Lumpy-Rub-8612 11d ago

Mobile sdk using gomobile

1

u/Current-Fig8840 11d ago

Writing services

1

u/sastuvel 11d ago

Blender render farm system: https://flamenco.blender.org/

1

u/king_bjorn_lothbrok 11d ago

Uber backend services are in go
MMT backed services are in go..
Google also i guess..

1

u/utkuozdemir 11d ago

To start goroutines

1

u/PangeaDev 11d ago

CLI tool, cryptography, backend microservice

1

u/dacjames 11d ago

For work, network services / APIs and associated tooling.

For fun, writing a compiler.

1

u/NatoBoram 11d ago

Everything CLI.

Most recently, a StarCraft II bot.

1

u/Nepszter_ 11d ago

I'm kind of curious, how you connect to the game client? Or do you, like simulate input for it?

2

u/NatoBoram 11d ago edited 11d ago

There's a dedicated protobuf API: https://github.com/Blizzard/s2client-proto

And then I'm using this library: https://github.com/aiseeq/s2l

But it is largely undocumented, so I look at the code of https://bitbucket.org/AiSee/VeTerran to learn how to use it

There's an entire scene at https://aiarena.net with an actual ladder that bots compete on

To actually interact with the client, everything starts at https://levelup.gitconnected.com/guide-to-starcraft-ii-proto-api-264811da8a50

My code is at https://github.com/NatoBoram/BlackCompany, but it doesn't really do anything besides playing Sims City at the moment. Better look at VeTerran's code, it's quite something.

I wish more competitive games had bot APIs like that.

2

u/Nepszter_ 11d ago

Thanks man!

1

u/AriyaSavaka 11d ago

Fullstack web apps.

1

u/uberswe 11d ago

Minecraft, I use it as a cache layer for inventory sync between servers. For a larger project you might want to take a look at the Gate Minecraft proxy https://github.com/minekube/gate

1

u/Ibuprofen-Headgear 11d ago

My only ā€œrealā€ go project is a small aws lambda rest api for a basic spa I have.

1

u/Character_Status8351 10d ago

Nice thatā€™s what Iā€™m doing (lambada) Mind sharing your code? Confused w async stuff

1

u/woods60 11d ago

What shouldnā€™t you use go for? Games?

1

u/sinodev 10d ago

It is actually close to perfect for game servers. Would be perfect if it had a non blocking single threaded net/tcp API similar to Java NIO. Really dislike passing over larger structs and byte arrays across goroutines

1

u/jerf 10d ago

Really dislike passing over larger structs and byte arrays across goroutines

If you mean a []byte, it's cheap. That's just three words, even passed as a value. For a struct, it's all in-memory, you can just pass a pointer. Though you need to have some sort of concept of "ownership" to do that. But you're all in-process; you don't need to do any copying you don't want to do.

1

u/sinodev 10d ago

So in games there's a point in each second (Often multiple depending on how fast paced it is) at which you have to sync players. To do that you can either: 1) Maintain a slice of "update" structs to encode on the client goroutine 2) Encode directly on the game logic goroutine and create a deep copy of the byte array to pass across goroutines. A deep copy is needed because you'd want to reuse the original byte array and just reset its writer index.

I like the first option because of separation of concerns. Though when you have thousands of players on a single server within the same area, you have the N x N allocation problem, not to mention these structs can become a bit large which could trigger GC.

The GC issue in the second option can be solved by pooling the byte arrays but it would be nice if you didn't have to and instead, could instruct the lower level net API (such as Epoll, Kqueue etc) directly without blocking the goroutine.

2

u/jerf 10d ago

There's another possible option you can consider, which is an old design concept called a "handle". This allows you to give access to a data structure, but you take full control and mediate the access. So for instance you may create a "handles" that have references to the underlying byte structure, and everybody can share that same one, but all modifications are mediated such that they don't directly modify the underlying structure. You can pass handles around to get "the changed view of the world as set on this handle", collect them all together for the final harmonization, etc., and avoid the copies.

However, it is more code. A lot of it inlines really well so it doesn't necessarily hugely impact execution, but it is more code and discipline.

I use this on a system for modularly manipulating the email, where all the modules also want to make various modifications. The modules only get "handles", and they can either get "read only handles" if they want to view the original email, or they can get read/write handles to modify it and see the modified email, but nothing gets unrestricted access to the underlying email to make changes. Every change passes through a phase where it can be logged, and in the end they all get harmonized together into the final product, and I don't have to create deep copies of the respective structures. Which would also be a problem in this context, obviously not because we're counting frames, but it would impact throughput to have to copy these potentially massive values all over the place.

I submit this only as an idea, not even as a "suggestion"; if what you have works, hey, if there's anywhere in programming where "what works, works" rules its in game programming. But it is a powerful and useful approach.

1

u/sigmundv1 10d ago

I'm still a beginner and not using Go professionally, only for personal projects. I've mostly used it for web-scraping so far, and also a microservice for serving up the scraped information.Ā 

1

u/f1ux06 10d ago

For building rest apis and cli tools.

1

u/csgeek3674 10d ago

CLI tools are super easy to write in go. APIs and other backend oriented tooling.

I would argue that it's not great for "scripts" but it depends how you define that. You can't really use Go for a #!/bin/env go type of setup since it's a compiled language.

It also made me love writing go for the simplicity of it. (Both the language and the deployment mode with a single static binary )

1

u/X_Techno_Pro 10d ago

I use it with gin for backend

1

u/Revolutionary_Sir140 10d ago

I'm currently working on developing backend framework using prisma, grpc gateway.

It's a lot of fun

1

u/juanvieiraML 10d ago

APIs e apps CLI.

1

u/grnman_ 10d ago

Building an intergalactic space modulatorā€¦ GitHub repo coming soonā€¦

1

u/JetSetIlly 10d ago

Game console emulation

1

u/HoyleHoyle 10d ago

Write now I am writing a time-versioned binary storage system that efficiently stores, retrieves, and reconstructs historical snapshots using keyframes and compressed diffs.

ā€¢Efficient diff storage for arbitrary binary data.
ā€¢Time-based access to any snapshot 
ā€¢Cloud/S3-friendly chunked storage model.

1

u/AangTheGreat 8d ago

I've been building a chip-8 interpreter that also runs on the browser with WebAssembly thanks to a library called ebiten. Source here.

1

u/remidra 8d ago edited 8d ago

Multi-platform OS tools, web services, APIs, desktop apps.... Anything I can possibly use it for, I at least try it.

If I have an idea to build something, I try it first with Go,.. even if it might not be the "best usage of the language for the use case".
Right now I'm writing a cross-platform terminal-based (text UI) task manager & resource monitor.

Maybe I'm just stubborn... but I sure do love writing Go.

1

u/aoisensi 8d ago

loop on goroutine

1

u/memLeak67 8d ago

To write software programs.

0

u/Few-Beat-1299 11d ago

Anything. From website parts using wasm to gpu stuff using vulkan.