The Go Programming Language

1 readers
0 users here now

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

founded 1 year ago
MODERATORS
1
 
 
The original post: /r/music by /u/Londontown-Artist on 2024-06-18 11:53:19.
2
 
 
This is an automated archive.

The original was posted on /r/golang by /u/CreepToCrypto on 2023-09-03 20:59:53+00:00.

3
 
 
The original post: /r/mademesmile by /u/Alchemist_Joshua on 2024-06-19 03:09:55.
4
 
 
The original post: /r/mademesmile by /u/Aaaaaaarrrrrggggghh on 2024-06-19 02:36:09.
5
 
 
This is an automated archive.

The original was posted on /r/golang by /u/MBytee on 2023-09-03 18:56:56+00:00.

6
 
 
This is an automated archive.

The original was posted on /r/golang by /u/rudrmuu on 2023-09-03 18:50:22+00:00.

7
 
 
This is an automated archive.

The original was posted on /r/golang by /u/GlamorousBunchberry on 2023-09-03 18:48:03+00:00.


I thought I'd ask for some feedback here, because it feels like I'm straying far from "normal" go testing.

I'm building a cobra/viper app that does a lot of interaction with a database. For testing purposes, I want to stand up a MySQL database in a Docker container, create a schema, and then use it for all my tests, which live in various packages.

Setting up the container is easy, using testcontainers/mysql. But it takes a while, so I'd hate to be running the same container over and over again.

What I landed on was to make a suite_test.go at the top level of my project, which uses testify/suite. It creates the container in its SetupSuite() func, and shuts it down in its TearDownSuite() func.

In order to make those the absolute first and last things called, I'm importing all my other testify/suite classes explicitly in suite_test.go, and invoking them there, like this:

// Include test cases from different packages by calling their respective methods

func (mySuite \*AllTestsSuite) TestMySQL() {
    tester := &mysql.MySQLTestSuite{
        Suite:  mySuite.Suite,
        DBConn: mySuite,
    }
    suite.Run(mySuite.T(), tester)
}

DBConn is an interface I define here and again in the file that defines MySQLTestSuite, so I can pass the parent suite in as a source of shared data, like the host, port, and data source name of the MySQL database.

The thing that makes me question, though, is the fact that you can't just import test code from another package. Which means I can't put my other tests in normal *_test.go files; instead I'm creating a child package called "tests" for each package. That way suite_test.go can import "internal/database/mysql/tests" with the alias "mysql," and then instantiate a mysql.MySQLTestSuite as you see above.

Since the code under .../mysql/tests isn't normal test code, it doesn't have any funcs with the with the signature "func TestFoo(t *testing.T)" -- only suite_test.go does. There I have one testify test per sub-suite, which instantites the suite and then runs it, as you see above.

Is all this crazy? Is there a simpler way?

Thanks in advance!

8
 
 
This is an automated archive.

The original was posted on /r/golang by /u/GrayLiterature on 2023-09-03 18:39:49+00:00.


I'm getting more into Go as a hobby language, and in part because I'd like to transition into backend development at some point. I am a Junior Developer, so my experience is pretty limited in scope and I currently work on a monolithic architecture (not in Go). I have worked in places before that leveraged services, for example, a Payments Service, but I never got to work on these services.

So what I am trying to do is think of an extremly narrowly scoped project to build a microservice system in Go, but i'm not really sure how I could properly scope it because I only have examples of larger, production level services.

An initial project idea that I had was to do the following:

  • Create an HTTP POST endpoint in a Github Repo (Call it A) that accepts a string.
  • When that endpoint gets hit, the server will do something to that string, like append to it, encode it, whatever, something stupid simple to represent business logic.
  • Save it to a file (to represent a database for the microservice)
  • Then send it to some other service (Call it B) using gRPC that maybe appends another word to it and then sends a text message.

I'm really trying to make this as close to extremely useless and boring as possible, just to build up an intuition of microservices. Do you think my project idea would be a good representation of the essence behind microservices, if so, what would you do to extend the idea just a little further? I'd also appreciate any ideas that are in this spirit: simple, fairly pointless, but captures some of the critical ideas behind a microservice.

Feedback is welcome, i'm just brain storming at the moment.

9
 
 
This is an automated archive.

The original was posted on /r/golang by /u/Spcbrn on 2023-09-03 17:57:07+00:00.


Hi fellow gophers,

I've been playing with validator and gin-gonic for quite some time and found myself having to copy-paste my structs/forms whenever I needed the slightest validation difference.

Most common case is when I'm writing create and update endpoints for an object.I would want the create object validation to have most of its fields mandatory but not in the case of an update.

Some code will surely help you understand what I'm talking about: go type CreateCarForm struct { Manufacturer string json:"manufacturer" binding:"required"Model stringjson:"model" binding:"required"FuelType stringjson:"fuel_type" binding:"required,oneof=diesel electricity gasoline"} type UpdateCarForm struct { Manufacturer stringjson:"manufacturer"Model stringjson:"model"FuelType stringjson:"fuel_type" binding:"oneof=diesel electricity gasoline" }

I am missing something or Is it the way to go? (pun intended)

Thanks!

10
 
 
This is an automated archive.

The original was posted on /r/golang by /u/darkhz on 2023-09-03 14:19:30+00:00.

11
 
 
This is an automated archive.

The original was posted on /r/golang by /u/mimixbox on 2023-09-03 13:29:48+00:00.


Hello, Golang users.

I enjoy developing small CLI tools in Golang, and I'd like to introduce one of the CLI tools I've created.

What's spare

The "spare" command is a tool designed to create infrastructure for hosting Single Page Applications (SPAs). It stores the SPA on S3 and delivers it through CloudFront. Since it's still in development, there is currently only one infrastructure pattern that can be built. However, there are plans to expand the infrastructure patterns and support CloudFormation generation in the future.

How to use

The "spare" command is used as follows:

  1. spare init: Generates the configuration file ".spare.yml".
  2. spare build: Constructs AWS infrastructure based on the ".spare.yml" configuration file. Currently, it creates S3 and CloudFront.
  3. spare deploy: Uploads the SPA to S3.

Motivation

I am a backend engineer, and my main job involves API development. In addition to my main responsibilities, I am sometimes tasked with "building infrastructure for hosting websites." This job has some repetitive aspects, and I am considering developing tools to assist with infrastructure setup, similar to ecspresso or lambroll.

Conclusion

It's still in the development phase, but I would appreciate it if you could show interest in spare command.

12
 
 
This is an automated archive.

The original was posted on /r/golang by /u/pan-bubnov on 2023-09-03 12:30:58+00:00.


Hello!

Our project developed a monolithic application. But now our architects decide to divide the app into multiple small services called microservice architecture.To deploy services we use kubernetes.From now I have become a developer of one of the services and development has become a nightmare...To test my service I need to run all services which my service depends on. As far my service depends on only a few services that is not a big problem although it takes extra time compared to monolithic app.But I faced the next difficulties:

  1. I cannot attach with debugger to my service. Instead I need to use traces/logs to understand the root cause of bugs or wrong behaviour of my service. If I do not have enough traces/logs in my app I need to add them and then rebuild and deploy it again.
  2. Every time I make some changes in code I need to deploy my service again and it takes some time which slows down my development and debugging.

When I develop monolithic app to attach with a debugger was not a problem. I did it right from vscode. And I did not need to deploy my app I just run "run with debugger" that is it.

I did not waste my time at all and did my job very quickly.

There is another way to go it is using mocks of service which my app depends on in development. But to write a good mock and then maintain it - it is not so trivial task which will take some extra time. Sometimes the mock works differently from the original service which leeds to extra bugs during functional tests. Writing a good mock becomes more difficult when services depend on each other.

It seems I need to accept the fact that development and debugging will never be easy as in monolithic architecture.

I realize that I need to change my process of development and debugging because we switched to microservices architecture. I would like to know general best practices which (maybe) do not depend on programming languages. But if programming languages matter then we use go.

Can you please point me to any best practices? If there is no best practice can you please share how your process is organized?

I would prefer to run my service without any containrusters (docker/k8s/minikube and so on) to avoid deployment and in this case and I can attach debugger easily to my service. But here I need to mock other services which I depend on. Is it the wrong approach?

13
 
 
This is an automated archive.

The original was posted on /r/golang by /u/PrestigiousFeeling86 on 2023-09-03 11:28:13+00:00.


Hi, I'm working on my first Golang project. Is there a tool that determines which tests to run and assesses code coverage specifically for modified files?

14
 
 
This is an automated archive.

The original was posted on /r/golang by /u/jhoepken on 2023-09-03 11:07:23+00:00.


I'm relatively new to Go, but a seasoned developer in other languages (Python and C++). At the moment I'm developing an API using Gin and have some trouble wrapping my head around how I should do my error handling in a "go way". On the code level, where I define my handlers, I can return HTTP status codes via Gin. Lower down into the business logic, should I pass errors up (e.g. via fmt.Errorf ?)

How do you do it? Are there are best practices, that I should know?

15
1
Id or ID? (zerobytes.monster)
submitted 1 year ago by [email protected] to c/[email protected]
 
 
This is an automated archive.

The original was posted on /r/golang by /u/sslime336 on 2023-09-03 08:01:27+00:00.


or Http or HTTP, it seems that using staff like UserID is recommended?

I got a hint like 'struct field xxxId should be xxxID'

16
 
 
This is an automated archive.

The original was posted on /r/golang by /u/SdoMeGjeshKurr on 2023-09-03 07:38:55+00:00.


Am I supposed to try doing gophercises on my own? Or watching the solutions to learn?

I'm like 7 exercises in and so far I tried to do them on my own first, and I come up with some weird spaghetti code that is a mess but works. Then I watched the youtube solution videos and the guy's code is art compared to mine. Should I continue like this? Or what would be the best way to learn from them?

17
 
 
This is an automated archive.

The original was posted on /r/golang by /u/bahadiravci on 2023-09-03 07:16:57+00:00.


Hello Reddit! I want to prepare a video where I answer commonly asked questions about Golang. What do you think are the most frequently asked questions about Golang? For example, questions like "Is Golang an object-oriented language?"

18
 
 
This is an automated archive.

The original was posted on /r/golang by /u/RedoubtableBeast on 2023-09-03 07:05:23+00:00.


Hi folks!

Let me introduce tiny pet project

Why systemd-styled env files? It is well known, well documented and widespread format. It allows comments, spaces around =, blank lines, multiline values... You cat check out main features at this playground

It is two in one: library and CLI tool.

The CLI tool works as expected. Just like that:

xenv you_script arg arg arg

You can customize looking up env-files using XENV=PATH:PATH:PATH eviroment.

The library provides two functions (details and example at pkg.go.dev): low-level parser and high-level helper.

If you are loading you configuration in that way:

env := os.Environ()
cfg := Load(env)

You are free to let it consider env file like that:

env, err := sdenv.Environ(os.Environ(), "config.env") // you are free to specify several files
if err != nil {
    panic(err)
}
cfg := Load(env)

This library and CLI have TODOs, however they are not vital. I hope to find more ideas here. You are welcome to open issues or just drop you thoughts right here.

19
 
 
This is an automated archive.

The original was posted on /r/golang by /u/Mighmi on 2023-09-03 00:49:49+00:00.


Someone on Hackernews pointed out only seeing microservice projects past a certain line count (of course a few dev ops tools with illegible code) like k8s are also there.

20
 
 
This is an automated archive.

The original was posted on /r/golang by /u/AlexCoventry on 2023-09-03 00:21:54+00:00.


Slack conversation where I heard that goroutine scheduling is nondeterministic.

21
 
 
This is an automated archive.

The original was posted on /r/golang by /u/Top_Chocolate_4203 on 2023-09-03 00:09:04+00:00.


Hello Guys! Hope you guys are all doing well.

Couple of weeks ago, I made a post title: "Do you know a really well-made open source REST-ful API built using Golang using only the standard library for me to reference to study?"Link:

And the comments from you guys motivated me to attempt to create one myself, for which you can find here:

I am an inexperienced engineer, so I would like to use this opportunity and reddit to possibly ask for guidance/help to critique my project and share your insights into what I can improve. it would help me tremendously to study and learn to become a better engineer.

Thank you guys in advance for your time and your help!

**Please feel free to create an issue using Github (this will streamline me implementing your feedback)

22
 
 
This is an automated archive.

The original was posted on /r/golang by /u/Forumpy on 2023-09-02 23:07:55+00:00.


I’m learning goa, but struggling to understand how to properly structure my project around it, and how it works with multiple different APIs/Services.

Does anyone know of any projects that use goa? It’d be great to see some examples of multiple Services.

23
 
 
This is an automated archive.

The original was posted on /r/golang by /u/e-san55 on 2023-09-02 19:58:33+00:00.

24
1
Newbie (zerobytes.monster)
submitted 1 year ago by [email protected] to c/[email protected]
 
 
This is an automated archive.

The original was posted on /r/golang by /u/Mac_Komen on 2023-09-02 14:54:04+00:00.


Hi everyone! I'm new in software dev, I am looking for a language to commence my career in web application dev, backend. Am I in the tight path with Golang

25
 
 
This is an automated archive.

The original was posted on /r/golang by /u/jacalz on 2023-09-02 11:32:40+00:00.

view more: next ›