Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [go]

Go, also called golang, is an open source programming language initially developed at Google. It is a statically-typed language with syntax loosely derived from that of C, adding automatic memory management, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.

0
votes
1answer
122 views

Why do new language versions typically use an early compiler version for the bootstrap compiler?

Wikipedia describes a bootstrap compiler to have these properties: An initial core version of the compiler A minimal subset of the language to be used by successive compiler versions Everything I've ...
0
votes
1answer
122 views

Which message pattern should I use?

I'd like to develop a microservice architecture application that sends text messages from one communication provider to another and I'm just considering changing architecture would be best suited to ...
1
vote
1answer
61 views

Batching CRUD of individual models that need to be linked

I have a few models which need to be linked together during a workflow on my webapp and I'm having trouble thinking of a nice abstraction for the api. They are represented as individual constructs on ...
0
votes
1answer
115 views

Generic Message Queue Interface

I'm trying to implement an Interface for a Message Queue. This interface should allow different implementations of queues to be implemented etc AWS SQS, Azure Queue Service. So lets say that I have ...
0
votes
1answer
55 views

Golang: Directory structure for Multiple Applications

I'm creating a proof-of-concept for a Go-app for my organization. I've read all of the intro docs on setting up a Go workspace, packages, etc. However, I am still unclear about the relationship ...
0
votes
1answer
277 views

How to structure similar structs using Go and PostgreSQL without too much duplicate code

I am making a REST API in Go using PostgreSQL. Quick introduction: I suddenly have a case where I have different variations of the same basic entity, one of the variations have maybe 12 extra fields ...
3
votes
2answers
366 views

How to handle concurrent updates for the same record in a distributed system

I'm trying to figure out the best solution for the below. Any help would be great. So basically I have a service (that can be scaled horizontally), which listens on a queue. Every message received ...
5
votes
1answer
821 views

How to test interactors in clean architecture?

After reading the last book from Robert C. Martin, I've tried a to develop some big Go applications following clean architecture. While writing interactors, I end up with a lot of complex unit tests, ...
0
votes
1answer
70 views

Login to application based on profile created on another application

I have a "difficult" problem that i am not sure how should i approach it. Basically i have a mobile app, that has a server side (in Go) and the appropriate base (PSSQL). User can register via the ...
1
vote
0answers
77 views

What is the benefit of this actor pattern for HTTP handlers in go

I've been reading a few go blogs and and more recently I stubbled upon Peter Bourgon's talk titled "Ways to do things". He shows a few examples of the actor pattern for concurrency in GO. Here is a ...
2
votes
2answers
600 views

Dependency Injection and DI Container

I have implemented clean architecture for my app, and I have a few questions. Typically, pure DI is argued for over a Service Locator pattern, because it is very explicit and more testable. However, ...
4
votes
1answer
111 views

When does structural typing's flexibility provide an advantage over nominal typing?

I'm trying to understand the implications of structural typing vs. nominal typing. From reading, I've managed to gather that one of the key advantages of nominal typing is the ability to declare an ...
1
vote
1answer
737 views

Extending an existing type in Go

This is my first post here. I want to do the following with the help of embedding in GO, extend the html.Tokenizer with new methods of my own while still able to access all existing html.Tokenizer ...
-6
votes
1answer
111 views

Concurrent password cracking

I am writing a utility in Go that concurrently attempts to crack passwords given a salted hash and the salt. That part works fine, but now I'd like to take advantage of go routines and have them crack ...
0
votes
2answers
568 views

Consuming external APIs within the microservice architecture

I'm writing a small microservice-based application. One of the services is assigned the task of querying an external API and processing the JSON response (filtered list of houses). Since I'm using ...
2
votes
1answer
817 views

What is the motivation for Go lang syntax? [closed]

Since the Go lang is getting popular, I started to play with it. I do derive from Java language so when I saw the Go syntax it has been a bit strange to me. sample code from go lang project site: ...
-1
votes
3answers
269 views

Go: design API service with minimum of repeatable code

I have to create a service which expose an API (REST). It will use MongoDB as a database and structs as data model. The problem is I really can't find a nice solution for making the basic CRUD non ...
-1
votes
2answers
975 views

In Go when to write a function with or without a receiver?

We're trying to write Go in the most possibile idiomatic way, but sometimes we struggle to find which is the best way. For example in our service we're creating/converting a struct from another one: ...
6
votes
3answers
478 views

Large doubly-linked-list (or other) storage on disk for queue system; options for how to store

I'm looking at building a message queuing library in Go, which will be used as part of a larger application. A doubly-linked-list seems like a sensible approach for an in-memory data structure, but ...
-1
votes
1answer
381 views

languages with native thread support

I am investigating ways of making my bundle of python network-requesting processes more efficient and became interested in the likes of Go and Julia for their apparent strong concurrency support and ...
3
votes
1answer
138 views

Generic-type operations must by provided by the run-time. Why this is a weakness of Go?

So, reading golang blog on slices there is a snippet by Rob Pike A weakness of Go is that any generic-type operations must be provided by the run-time. which I don't quite understand. Can one ...
4
votes
2answers
1k views

GO - Goroutine and Concurrency

Background: pthreads follow pre-emptive scheduling, whereas C++ fibers follow cooperative scheduling. With Pthreads: the current execution path may be interrupted or preempted at any time This ...
-1
votes
1answer
265 views

GO - How to define methods of named type?

In GO, rule is, methods can be defined only on named type and pointer to named type. In C, below code, operations are defined on type(say List), typedef struct List List; //list.h typedef struct { ...
3
votes
2answers
1k views

Type safety - GO vs C pointers

C is a static-typed language that is not type-safe, because pointers(void *y) let you do pretty much anything you like, even things that will crash your program. GO is also a static typed language ...
-4
votes
1answer
156 views

Did GO embrace any language construct introduced in Java?

GO has embraced, 1) JavaScript/Python language constructs, Higher order function Closure Slicing Range operator Anonymous function(inner function) Provides abstractions ...
5
votes
1answer
416 views

How to parse a simple custom syntax in Go?

I have a limited amount of input types: 34:56 = sensorA#, sensorA#, sensorB# 2:5 = { led# } 66 = otherSensor 2,3,4,5 = greenRelay#, redRelay#, relayA#, relayA# a:b implies range. {name} implies a ...
4
votes
1answer
1k views

directory layout of a Go-lang project?

I'm just discovering the Go programming language. (FWIW, I am fluent in C++, Ocaml, C, Common Lisp, Scheme, I know well Linux, and I have designed & implemented GCC MELT; I am considering a ...
16
votes
5answers
2k views

Is a common library a good idea?

I've always thought that a "common library" was a good idea. By that I mean a library that contains the common functionality that is often needed by a few different applications. It results in less ...
8
votes
3answers
1k views

What is the difference between Haskell's type classes and Go's interfaces?

I am wondering if there is a difference between Haskell's type classes and Go's interfaces. Both define types based on functions, in that way, that a value matches a type, if a function required by ...
2
votes
2answers
182 views

What does “a type system [that] has no hierarchy” mean?

I was reading the Go-lang documents and found under the section of Types that Go has no type hierarchy. What does that mean exactly? Is it like python that types are been checked at run time (...
6
votes
1answer
254 views

Idiomatic way of writing a GUI system in Go?

I'm writing a little GUI system for my game in Go. So far my structure is kind of like this: type Component interface { Update() Render(ctx) Translate() GetComponent() []Component ...
3
votes
3answers
675 views

How do programming languages work?

This is probably a dumb question, but how do programming languages work on a low level? If you go to the Go language GitHub page here, it says almost 90% of the source files are Go files. How is it ...
3
votes
1answer
113 views

Why are pointers of structs not printed like pointers of variables? [closed]

Consider the following code: package main import "fmt" type Vertex struct { X, Y int } var ( i = 10 p = &i v = Vertex{1,2} q = &v ) func main() { fmt.Println(p) // ...
4
votes
1answer
326 views

Idiomatic internal architecture of Go microservices

For learning purposes, i'm trying to implement a small project using (buzzword warning!) microservices. There are plenty of resources online talking about the 'macro' microservice world -integration, ...
22
votes
1answer
2k views

Could Hindley-Milner inference work for the Go language?

I've read that Hindley-Milner does not work with type systems that have subclasses, and there are other type system features that also do not work well with it. Go currently has only very limited type ...
1
vote
3answers
2k views

Flow control in Go without a for loop

I've been set a challenge that I'm trying to get my head around, but am struggling with the best (or 'correct') way to implement it. The challenge is to create a simple console app written in Go that ...
2
votes
1answer
214 views

In Go, why isn't append() implemented as a method, but as a function?

In Python, lists offer an append() method which can be called using standard Python method syntax; for example: >>> my_list = [] >>> my_list.append('a', 'b', 'c') >>> ...
1
vote
2answers
316 views

Should I log errors in the function they occur? or pass them back and log them when control returns?

One of the things I love about Go is how they encourage passing errors as return values, but when it comes to logging what is the most maintainable solution: passing the error as far back down the ...
2
votes
2answers
1k views

Why does gofmt discourage blank lines at the end of files?

Since I started programming, I've always been taught to leave a trailing blank line at the end of my files, the reason usually being something relating to how it makes concatenated files easier to ...
2
votes
1answer
270 views

What was the reason behind using quotes in Go's import statements?

The usage of quotes in Go's import statement strikes me as unnecessary. Typical Go import statements look like: import "foo/bar" import other_name "foo/bar" import ( "foo/bar" x "foo/baz/bar" ...
4
votes
1answer
2k views

Checking for nil in Go [closed]

In Go, is it idiomatic to check for nil and return an error if a parameter is nil? Should pointer method receivers ever include nil checks? I've seen a lot of code in other languages where people ...
1
vote
1answer
92 views

I am able to use PUT to act like GET when using my REST API

I wrote a simple REST API (just learning) using Go and I am calling it using python requests. I have two methods, "update_x", which updates the value of the resource, "get_x_times_n" which gets the ...
2
votes
1answer
134 views

TDD Duplicate Testing on Related Classes

In following the principle of testing only the exported functions on a package (using Go - or for others languages, the public functions on a class), I'm running into a scenario where related packages ...
-8
votes
1answer
314 views

Golang Testing Process [closed]

I am new to golang and RunC and now doing some research on it as a part of my intership. What kind of contents do the ' _test.go ' functions check during testing a program or a container with Golang (...
0
votes
1answer
59 views

How do I use type assertions in Go when returning an interface type?

A struct I'm working on called fieldDefinition holds metadata about a field used by an object in my web app. One of the fields on fieldDefinition (it does get a bit confusing) looks something like ...
2
votes
2answers
651 views

Restful User/Password Authentication

I'm currently designing a REST-API with the following properties: Backend for a single page application (Later Apps) Integrated user database for each instance HTTPS/TLS only Authentication with a ...
4
votes
2answers
258 views

Go - idioms/design for determining when an unknown number of goroutines are complete

I have a workflow wherein I walk recursively through a bunch of directories, then for each file perform some action. I'm using goroutines to walk each directory, and also to process each file. The ...
0
votes
1answer
108 views

What locking mechanism should be used when persisting data to files

I am beginning to learn how to create web applications from a golang tutorial. For simplicity, it persists data to files instead of a database. The complete code creates a server that can handle ...
0
votes
2answers
1k views

Nested functions; allow or not? [closed]

Having programmed a whole lot in python, using nested functions is a good way to not clutter the namespace with small helper functions that are only used once. Now I'm programming in go, and upon ...
0
votes
3answers
357 views

Would it be possible to create a language similar to Ruby/Python with static typing that had the speed/memory usage of a compiled C program? [closed]

One of the main drawbacks of Ruby/Python is performance. I understand that they are interpreted and C is compiled. (And there are things like JRuby which do JIT compilation with Ruby). But they never ...