Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 125398

Go, commonly referred to as "golang", is a fast, statically typed, compiled language created by Google. The language was initially developed as an alternative to C++ for server infrastructure and has native support for concurrency.

1 vote

Transforming an array: take the square root of each perfect square, else square the number

Naming conventions aside (short names in camelCase are typically used in Go), this is the right way of doing what you want. … The authors of Go have a different view of what is more readable & maintainable than the authors of Python :-) …
Ted's user avatar
  • 701
1 vote
Accepted

Go version of Advent of Code, day 5 - Dealing with runes

Your code is pretty idiomatic. The only obvious style thing I'd change is the end of the evaluateIndex function: if strings.HasPrefix(hash, "00000") { return []rune(hash)[5] } return 0 you …
Ted's user avatar
  • 701
5 votes
Accepted

Vowel/consonant counter in Golang

In Go, foo, _ := something() is a big code smell. Iterating on a string gives you a rune; don't convert it to a one-char string just to compare it to another one-char string. …
Ted's user avatar
  • 701
1 vote
Accepted

Codilty, binary gap get the highest gap

Your naming conventions aren't very Go-like. … stringArray is very wrong: this variable is a byte slice, plus, it doesn't give you extra information from its type TestBinryGap should probably be TestBinaryGap testObjects is weird and slightly misleading; Go
Ted's user avatar
  • 701
3 votes
Accepted

Read CSV into 2D float array in Go

In Go, you would use i instead of rowIndex, floatArray instead of make2dFloatArray, ConvertCSV instead of ReadFromCSV, etc. … See this for a detailed discussion on why Go doesn't have generics for now. …
Ted's user avatar
  • 701
2 votes

go-pg efficient multi table/row insert

services the call to strings.TrimSuffix can be avoided using a simple condition in your template you can replace (select company.id from company) directly by its value, that you previously computed in your Go … code and you can get rid of the []interface{} variable that you pass to Prepare & Exec, just do all the substitution logic in the go code. …
Ted's user avatar
  • 701
0 votes

Validating the difference in days between two dates

You client code is incompatible with the argument type of valueInterval (I guess you meant to write valueInterval{0, 100} instead of 100?). But this is strange to have min for an expiration time, most …
Ted's user avatar
  • 701
3 votes
Accepted

Print log error and save it to a file

If some of your init values (prefix, filePath, fileName) are empty, you should fail on init, not once you try to log something. Returning errors as soon as possible is a good practice and makes debug …
Ted's user avatar
  • 701
3 votes
Accepted

Byte conversion in my Caesar's cipher

So you can initialize directly with the correct allocated capacity: line := make([]byte, 0, len(bytes)) okay, now let's go even further: calling append at each iteration means that under the hood … b <= 'Z' { b = ((b-'A')+shiftB)%26 + 'A' } else if b >= 'a' && b <= 'z' { b = ((b-'a')+shiftB)%26 + 'a' } line[i] = b } return line } We can go
Ted's user avatar
  • 701
2 votes
Accepted

Manipulating /etc/hosts file using Go

Your Add function go away, but fyi: you are making it return a bool and never using it. Your pop function could be simplified and inlined. Just use ip, parts = parts[0], parts[1:]. …
Ted's user avatar
  • 701
1 vote

Extract title with regex

Consider using the html Go library instead. …
Ted's user avatar
  • 701
1 vote

Concurrency-safe stack implementation in Go

Your code is mostly fine. The following comments are nitpicking. I agree with Elias, your default implementation should be thread-safe. Instead of returning nil, I would suggest your Pop function ret …
Ted's user avatar
  • 701
3 votes

Simple HTTP server that performs a regex test

The call to regexp.MatchString is the only really expensive part of your code. Do you need full regexp support? If you just want to find substrings, you should use strings.Contains instead of the rege …
Ted's user avatar
  • 701
3 votes
Accepted

Plotting savings rate in Go

Some high-level comments after one pass on your code: Don't panic. Handle errors instead; and use log.Fatalf at the highest level. Don't use underscores in variable names. Your variable names are al …
Ted's user avatar
  • 701
3 votes
Accepted

Random distributions in Go with inheritance

Style comments Don't panic. Return the incorrect value of n in your error using fmt.Errorf. Use gofmt on your code. (Have your favorite editor call it on-save.) There is no better way to convert a b …
Ted's user avatar
  • 701

15 30 50 per page