Stack Exchange Network

Stack Exchange network consists of 174 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-...

0
votes
0answers
20 views

How to design an adapter function for an c library wich takes an int parameter

I'm writing a go adapter for an c library. As my experience with go and c is limited I'm unsure how to handle int parameters because of the different size. There are 2 approaches I thought of: Don't ...
-2
votes
0answers
40 views

Best practices on complying with BSD 2-clause in go project [closed]

I'm building a go project that will be opensourced under MIT license and publicly distributed in a binary format within a docker image. I'm using a library with BSD 2-clause license that states: ...
0
votes
1answer
258 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
1answer
169 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
586 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
68 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
58 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 ...
1
vote
2answers
491 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, ...
3
votes
1answer
74 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
569 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 ...
-5
votes
1answer
97 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
461 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
643 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
263 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
517 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: ...
0
votes
0answers
320 views

Pattern Options for Go Enums with succinct package/type naming

Background I've recently been tasked with a project to develop a small web service that on HTTP request interacts with 2 separate APIs. In an attempt to map out the types I was commonly using I was ...
5
votes
3answers
319 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
301 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
123 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 ...
0
votes
0answers
176 views

Pros and cons using single function interfaces and function types in go

A typical service interface in go might look something like type EventStore interface { func Find(string) (*Event, error) func Save(*Event) error } type MyController struct {} func ...
1
vote
2answers
775 views

GO - Goroutine and Concurrency

Background: Threads use pre-emptive scheduling, whereas fibers use cooperative scheduling. With threads: the current execution path may be interrupted or preempted at any time This means that ...
0
votes
1answer
224 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
838 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
152 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
375 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
971 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 ...
2
votes
1answer
620 views

How to add multiline comments for field of the struct in Go? [closed]

I faced with need add big comment for one of field of my struct, but I don't how to make it more idiomatic and graceful. You can see my versions, but, I think, it's unpleasantly to see. Any ...
12
votes
4answers
1k 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
821 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
173 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
250 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
631 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
314 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
1k 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 ...
1
vote
1answer
198 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') >>> ...
0
votes
2answers
238 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 ...
1
vote
2answers
799 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
257 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
1k 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
124 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
302 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
58 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
609 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
222 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
99 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
943 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 ...
-1
votes
3answers
326 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 ...