/r/golang

Photograph via snooOG

Ask questions and post articles about the Go programming language and related tools, events etc.

Rules

1. Be friendly and welcoming.

Post is not in keeping with an inclusive and friendly technical atmosphere.

2. Be patient.

Remember that people have varying communication styles and that not everyone is using their native language. (Meaning and tone can be lost in translation.)

3. Be thoughtful.

Productive communication requires effort. Think about how your words will be interpreted. Remember that sometimes it is best to refrain entirely from commenting.

4. Be respectful.

In particular, respect differences of opinion.

5. Be charitable.

Interpret the arguments of others in good faith, do not seek to disagree. When we do disagree, try to understand why.

6. Be constructive.

Avoid derailing: stay on topic; if you want to talk about something else, start a new conversation. Avoid unconstructive criticism: don't merely decry the current state of affairs; offer—or at least solicit—suggestions as to how things may be improved. Avoid snarking (pithy, unproductive, sniping comments) Avoid discussing potentially offensive or sensitive issues; this all too often leads to unnecessary conflict. Avoid microaggressions

7. Be responsible.

What you say and do matters. Take responsibility for your words and actions, including their consequences, whether intended or otherwise.

8. Follow the Go Code of Conduct

As a part of the Go community, this subreddit and those who post on it should follow the tenets laid out in the Go Code of Conduct: https://golang.org/conduct

Treat everyone with respect and kindness. Be thoughtful in how you communicate. Don’t be destructive or inflammatory.

9. Must be Go Related

Posts must be of interest to Go developers and related to the Go language.

This includes: - Articles about the language itself - Announcements & articles about open source Go libraries or applications - Dev tools (open source or not) specifically targeted at Go developers

We ask that you not post about closed-source / paid software that is not specifically aimed at Go developers in particular (as opposed to all developers), even if it is written in Go.

10. Do Not Post Pirated Material

Do not post links to or instructions on how to get pirated copies of copyrighted material.

11. Job Posts Go in the "Who's Hiring?" Post

We have a monthly "Who's Hiring?" post that will stay pinned to the top of the subreddit. To avoid too much noise from companies, please post job openings there. Please keep in mind, this is for 1st party postings only. No 3rd party recruiters.

12. No GPT-generated or GPT-quality content.

No GPT or other AI-generated content is allowed as posts, post targets, or comments. This is only for the content itself; posts about GPT or AI related to Go are fine.

As GPT content is difficult to distinguish from merely low-quality content, low-quality content may be removed too. This includes but is not limited to listicles and "Go tutorials" that have no human voice and add nothing of their own.

Documentation

Community

/r/golang

280,504 Subscribers

2

More convenient http client

Do you use a the party package which makes building http clients more convenient?

Which one do you use, and why?

1 Comment
2024/11/03
08:41 UTC

1

Where do I start?

Hi, I want to learn golang and start using it daily. I am not new to programming since I started my career in 2013.

I am looking online for resources and I would like to know from more experienced people, where can I found good quality courses/tutorials.

I enjoy courses/tutorials where you actually build something, like an ecommerce, a blog or anything else from scratch, since they are the best way (in my opinion) to learn something.

I found this for the moment:
https://gowebexamples.com/

7 Comments
2024/11/03
07:30 UTC

0

Public OpenSource Usecase Code example

my repo public opensource

link: https://github.com/ducnpdev/open-dev

0 Comments
2024/11/03
07:25 UTC

6

PDF generation

Good day team. I have a work app that uses js front and back, and we want to migrate everything to go. I’ve already sorted most of it, almost completely with standard library packages. But there is some pdf generation in the backend that uses puppeteer. We’ve done a small amount of research and were wondering if anyone had some recommendations (standard lib or not) or repos that we could look over.

4 Comments
2024/11/03
06:23 UTC

35

What is are your top stdlib gems?

Im curious to hear what packages, features, and particularly useful functions/methods you have found in go and life was never the same after.

What stlib packages are the most useful for what you do?

22 Comments
2024/11/03
02:40 UTC

7

Introducing Swama - A Powerful CLI Tool for Swagger/OpenAPI Interactions!

Hi, everyone! 👋

I'm excited to introduce Swama, a CLI tool designed to make working with Swagger/OpenAPI definitions easier and faster. If you’re frequently working with APIs and want to interact with Swagger files directly from the command line, Swama might be just what you need!

Key Features

  • List & View Endpoints: Easily browse API endpoints and inspect their details.
  • Convert to curl/fetch: Quickly convert API endpoints to curl or fetch commands for easy testing.
  • Mock Server: Spin up a local mock server based on your Swagger file for rapid prototyping and testing.
  • Flexible Filtering: Filter endpoints by method, tag, or even specific endpoint patterns using wildcards.
  • Grouping & Autocompletion: Group endpoints by tag/method, and enable shell autocompletion for faster workflows.

Installation

You can download pre-built binaries for Linux, macOS, and Windows from the releases page.

Alternatively, build it from source:

git clone 
cd swama
go build -o swamahttps://github.com/idsulik/swama

Example Commands

  • List Endpoints: swama endpoints list --file api_spec.yaml
  • Run Mock Server: swama mock-server run --port 8080
  • Convert to curl: swama endpoints convert --endpoint /users --method GET --type curl

GitHub Repository

Check it out here: Swama GitHub Repo

Feedback and Contributions

I’d love to hear your thoughts! Feel free to report issues, suggest features, or submit PRs on GitHub.
If you find it useful, please consider giving the project a ⭐️ on GitHub – it’s a huge help and really appreciated!

1 Comment
2024/11/02
18:43 UTC

69

Is there a path forward for Go's yaml situation?

I've been using Go for a while now, but only lately have had to deal with manipulating yaml files (hell).

Right now there's

For the most part, https://github.com/go-yaml/yaml is the main one that most use, but I can confidently say that it's very broken for anything other than marshaling or unmarshaling into and out of standard go structs (and even that is buggy).

There's currently nearly 300 issues open, and over 100 PR's open with the last commit being 2 years ago. I believe the maintainer is 1 person who is busy with other things (all the power to them, they don't owe anyone anything). For all intents and purposes it's deprecated.

https://github.com/go-yaml/yaml has its own set of issues. Most tooling doesn't use it as the base library, and I believe it's also a little buggy though I can't really comment since I haven't used it as much. That said, it's also maintained by one person.

Due to the importance of yaml parsing these days, is there any centralized movement towards providing something like the json library (ie, maintained by the core language creators?) or is there an alternative that people are looking at?

50 Comments
2024/11/02
18:34 UTC

1

Suggestions Feature for a REPL( read-eval-print-loop)Program

I'm working on a REPL (Read-Eval-Print Loop) program in Go and want to add a feature for real-time command suggestions, similar to search engine suggestions. I understand that I need one goroutine to accept user input and another to generate suggestions based on that input. However, I'm unsure about how to read user input continuously while also updating the suggestions in real-time.

Your Answers are Appreciated

Note: I am Making this to Learn So no External Libraries I just want to Learn ...

3 Comments
2024/11/02
18:06 UTC

25

What are the most interesting features you noticed in Golang?

I'd like to read some of them :)

46 Comments
2024/11/02
17:38 UTC

18

Golang simple lightweight API Gateway

Simple and easy lightweight API Gateway . It comes with integrated features, such as:

  • Reverse proxy
  • RESTFull API Gateway management
  • Domain/host based request routing
  • Multi domain request routing
  • Cross-Origin Resource Sharing (CORS)
  • Backend errors interceptor
  • Authentication middleware
  • JWT client authorization based on the result of a request
  • RateLimiting

Github: https://github.com/jkaninda/goma-gateway

7 Comments
2024/11/02
16:13 UTC

0

How to check inbox in my opensource Gmail-TUI application?

Hi everyone!

Using my newly gained basic understanding of SMTP, I have created a TUI application using Rivo's Tview library that lets you send emails using a TUI-Application:

Gmail-TUI GIF | GitHub Repository

Since SMTP is used for sending emails, I am current looking for a protocol or API that would allow me to view my inbox after signing-into my Gmail account from this very TUI-Application.

I'd love for you to check out the repository and share your feedback! Any suggestions, ideas, or improvements would be greatly appreciated.

2 Comments
2024/11/02
14:57 UTC

11

Golang and drones

By playing with TinyGo (Golang embedded) I came to drones/UAVs.

Just found:

Before starting (hopefully) a new payed project I would like to do more Go :) Therefor I'm looking for a really, really cheap drone which I can program using Golang. Camera and video would be nice, but to be honest I think the thing will fly against the wall of my house a few times and probably be broken before I would even begin to use the video/camera function. I would like to fly 1-3 drones (depending on the price) in formation and have colourful LEDs flash / light up instead of fireworks on new year's eve. Needs to be really cheap, because I need to save up some money to have to pay for medics/treatment (is actually not common in Germany) to shorten a waiting time of >8 months to <1 week. I am open to everything.

EDIT: First Url wrongly copied. Striketrough seems not to work. It was: https://github.com/drone/drone-go

6 Comments
2024/11/02
13:50 UTC

4

TLA+ and Golang

I received an enquiry for a possible future Golang project and was explicitly referred to TLA+. TLA+ was created by Leslie Lamport, a well known LaTeX dev. I found this: https://lamport.azurewebsites.net/tla/tla.html I also found "Finding Goroutine Bugs with TLA+": https://www.hillelwayne.com/post/tla-golang/ Is TLA+ a topic related to Golang? I'm using Golang since 2016 and did >10 "bigger" projects but so far I've had nothing to do with it. Would appreciate any experience and recommendations you would like to share.

10 Comments
2024/11/02
13:15 UTC

97

What patterns to use for writing services in Go?

I've been working in a team that uses Go for its microservices for about 4 months now. I have zero prior experience with Go, my background is primarily Java. One thing that I find difficult to wrap my head around is the lack of a clear pattern in the way that these services are written. I've been accustomed to Spring Boot's controller-service-repository pattern which i like very much, its easy to grasp and the separation of concerns between the layers is well-defined.

In our codebase however, I find it difficult to reason where a piece of code should reside especially when the project structure can vary a lot from service to service. In some services, there are random helper and util functions that encapsulate business logic, and I find myself spending too much effort thinking where I should be writing my code. Then in some other services, i see request handlers that do everything from unmarshalling the request body, validation to calling the DB that results in giant functions.

Maybe its just my inexperience as a SWE, but is it normal for Go services to be written without following any pattern? If not, what useful patterns do you recommend?

29 Comments
2024/11/02
12:27 UTC

3

I'm looking for an equivalent of listr2: beautiful CLI interfaces via easy and logical to implement task lists that feel lively and interactive

Hi,

Do you know a Golang equivalent of the Javascript listr2 library?

My goal is to create a cli tool with the same rendering as demonstrated in the screencast on https://listr2.kilic.dev

Listr2:

Create beautiful CLI interfaces via easy and logical-to-implement task lists that feel alive and interactive.

Best regards,
Stéphane

2 Comments
2024/11/02
11:37 UTC

0

Generating mock HTTP responses for testing with AI in Go

Not long ago, I published an experimental Go tool for effortlessly generating mock HTTP APIs. You can check it out on GitHub: https://github.com/trco/wannabe.

My next "big plan" is to support dynamic HTTP response generation using AI, with a focus on date ranges. In simple terms, this means you could record an HTTP response for a request with a specific date range, and then use that response as a template for AI-generated responses across arbitrary date ranges.

I have a few questions to see what do you think of such plans:

  1. What challenges have you faced when generating mock data that mirrors real-world scenarios?
  2. Do you think dynamically generated responses using AI could be useful? Could it extend to other use cases?
  3. I'm familiar with popular mocking tools like Wiremock, Mockoon, and MockServer, but in my experience, their templated dynamic response generation feels too complex. Do you feel the same about these tools?
  4. For those who have tried AI for mock data, what factors (e.g., accuracy, response time, data consistency) are most important in your testing?
  5. Would you consider integrating tools that support AI-generated mock responses into your test pipelines?
6 Comments
2024/11/02
11:19 UTC

5

Review on my http server prepared from scratch

So recently I came across this side called codecrafters and tried out building a http server. I think it turned out to be pretty good. I would like you guys to look through it and suggest me some enhancements and correction if i have done something wrong.

https://github.com/toastsandwich/codecrafters-http-server

0 Comments
2024/11/01
17:02 UTC

0

How do you version your Go modules ?

Go enforce module being versioned using the semantic versioning model, doing so manually can be tedious and prone to error.

Automating this task was for me a good first open-source Go project: Go Semver Release, a program built to automate the versioning of your Git repositories using their formatted commit history.

How is it different from other such tools ?

  • Focuses only on versioning repositories using tag: fast and very easy to configure
  • Support for custome rules, monorepositories, GPG signing and custom tag prefix out of the box
  • Local or remote mode of execution are supported, access token are not mandatory
  • Supply-chain security is a strong focus of this project, provenance is generated with each release

Feedbacks are more than welcome !

5 Comments
2024/11/01
17:36 UTC

11

I built a minimalist pastebin clone using Go, htmx, and postgresql

Probably something like this already exists, but I wanted a simple and secure way to share snippers between machines, so I created https://notepad.moe! All notes are securely encrypted with AES, and can only be accessed if you know the URL. Feedback welcome! This is the first time I've really done anything with encryption, so I expect it's completely broken somehow.

16 Comments
2024/11/01
14:23 UTC

182

Golang Aha! Moments: Object Oriented Programming

I've been doing Go for several years now, but before that I worked with Java for about 20 years. I've written up how my approach to data structure design changed as I got more comfortable with Go.

What was particularly interesting to me is that Go pushed me towards design patterns that I already considered best practices when working with Java. However, it wasn't till I switched languages that I was able to shift my habits.

Curious if others have had similar experiences, and especially how the experience was for people coming from other languages (python, rust, C or C++).

55 Comments
2024/11/01
14:21 UTC

37

Who's Hiring - November 2024

This post will be stickied at the top of until the last week of November (more or less).

Please adhere to the following rules when posting:

Rules for individuals:

  • Don't create top-level comments; those are for employers.
  • Feel free to reply to top-level comments with on-topic questions.
  • Meta-discussion should be reserved for the distinguished mod comment.

Rules for employers:

  • To make a top-level comment you must be hiring directly, or a focused third party recruiter with specific jobs with named companies in hand. No recruiter fishing for contacts please.
  • The job must involve working with Go on a regular basis, even if not 100% of the time.
  • One top-level comment per employer. If you have multiple job openings, please consolidate their descriptions or mention them in replies to your own top-level comment.
  • Please base your comment on the following template:

COMPANY: [Company name; ideally link to your company's website or careers page.]

TYPE: [Full time, part time, internship, contract, etc.]

DESCRIPTION: [What does your team/company do, and what are you using Go for? How much experience are you seeking and what seniority levels are you hiring for? The more details the better.]

LOCATION: [Where are your office or offices located? If your workplace language isn't English-speaking, please specify it.]

ESTIMATED COMPENSATION: [Please attempt to provide at least a rough expectation of wages/salary.If you can't state a number for compensation, omit this field. Do not just say "competitive". Everyone says their compensation is "competitive".If you are listing several positions in the "Description" field above, then feel free to include this information inline above, and put "See above" in this field.If compensation is expected to be offset by other benefits, then please include that information here as well.]

REMOTE: [Do you offer the option of working remotely? If so, do you require employees to live in certain areas or time zones?]

VISA: [Does your company sponsor visas?]

CONTACT: [How can someone get in touch with you?]

9 Comments
2024/11/01
13:03 UTC

30

Write Python in Go - The most intuitive Python wrapper for Golang

I'm working on a library to make interaction between Go and Python very easy: https://github.com/cpunion/go-python

Anyone interested?

16 Comments
2024/11/01
13:01 UTC

8

Best way to scan null DB fields into a struct?

What is the best way to scan null DB fields into a struct? How do I deal with null fields in a database? My options are:

  1. use sql.NullString
  2. Make all DB fields NOT NULL
  3. Use a pointer which can be null

Which of these is more performant? Which one do you use? Which one would you recommend? Are there other ways? Bad experiences with pointers? Any blog posts regarding this? I asked GPT but it simply gave me simple pros and cons and not much more than that.

NullString seems like a no brainer, but NOT NULL is also quite attractive. I use postgresql. Does NOT NULL need more space on disk? Does it make creating new rows slower? Any problems doing it on scale? It's a very attractive solution! It's the one I currently use for my poc. GPT says it actually is more performant than using nullable fields because the null check is skipped.

Another question would be, should I scan into a struct which is different from that which I send off at the api endpoint?

24 Comments
2024/11/01
12:13 UTC

22

Zog, the Zod-like validation library v0.11.0

Its has been a quite a few releases since I last posted about Zog (https://github.com/Oudwins/zog) v0.9.0.

I case you are not familiar, Zog is a Zod inspired schema validation library for go. Example usage looks like this:

type User struct {
  Name string
  Password string
}
var userSchema = z.Struct(z.Schema{
  "name": z.String().Min(3, z.Message("Name too short")).Required(),
  "password": z.String().ContainsSpecial().ContainsUpper().Required(),
})
// in a handler somewhere:
var user User
errs := userSchema.Parse(map[string]string{"name": "Zog", "password": "nop"}, &user)

We have added a bunch of new bug fixes and small tweaks. Notable changes:

Support for uuid validation and regexes: This has been missing for a while and I was very happy to see @amaro0 contribute the validations.

Better error printing for debugging: Zog already has some of the best errors of any validation library out there but there was one small thing missing. Printing the errors easily in a nice format for debugging. I had to dive deep into the stdlib to figure out the issue but I'm happy to say that its working perfectly.

// example printing the result of parsing a primitive type:
fmt.Println(errs) // [ZogError{Code: coerce, Params: map[], Type: number, Value: not_empty, Message: number is invalid, Error: failed to coerce string int: strconv.Atoi: parsing "not_empty": invalid syntax}]

90%+ code coverage: This was necessary to apply for the awesome-go project but also just a sign that Zog is ready to be used in production (in fact we have quite a few people actively using it in production today!)

edit: RIP I forgot to add "release" to the title. edit2: forgot github link

14 Comments
2024/11/01
12:06 UTC

Back To Top