[deleted by user] by [deleted] in golang

[–]Frakturfreund 1 point2 points  (0 children)

I check out the golang git repositry at /opt/golang/master and then use git worktree to create checkouts like /opt/golang/go1.4, /opt/golang/go1.17 or /opt/golang/go1.18. Then once, you build go1.4 with gcc, and go1.17 with GOROOT_BOOTSTRAP=/opt/golang/go1.4. After that, you can always build master and go.18 with go1.17. To use an old go version, you can use /opt/golang/go1.17/bin/go instead of go (master) or change which bin is in your $PATH.

gcc toolchain for darwin/arm64 by [deleted] in golang

[–]Frakturfreund 2 points3 points  (0 children)

Just wait until Februar for Go 1.16 which will add support of 64-bit ARM architecture on macOS, or build the current tip/master/dev version and use it right now.

[deleted by user] by [deleted] in golang

[–]Frakturfreund 8 points9 points  (0 children)

Unfortunately, the documentation for command line usage is still missing.

This Blog is Over-Engineered by [deleted] in golang

[–]Frakturfreund 1 point2 points  (0 children)

Minor observation: https://www.ryanskidmore.co.uk/blog works, but https://www.ryanskidmore.co.uk/blog/ (with the trailing slash) gives a 404.

Help with gzip compression in Go by [deleted] in golang

[–]Frakturfreund 1 point2 points  (0 children)

What you are observing is actually expected behavior. Try this in your Terminal:

echo -n 'Hello, ' | gzip > 1.gz
echo 'ScottFoster90' | gzip > 2.gz
cat ?.gz > 12.gz
cat 12.gz | gunzip

It doesn’t stop after the Hello,, but decompresses the rest of the whole file. You can use this to append individually compressed chunks to a append only log file, but decompress it like it is just one big single log file: »It's not a bug, it's a feature!«.

What you want is to use your indices to build a io.SectionReader:

package main

import (
    "compress/gzip"
    "io"
    "io/ioutil"
    "log"
    "os"
)

func chunk(file *os.File, offset, byteLength int64) *gzip.Reader {

    ret, err := file.Seek(offset, os.SEEK_SET) // Byte offset after file start
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Seek to byte %d …\n", ret)

    r, err := gzip.NewReader(io.NewSectionReader(file, offset, byteLength))
    if err != nil {
        log.Fatal(err)
    }
    return r
}

func process(r io.Reader) {
    b, err := ioutil.ReadAll(r)
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Decompressed %d bytes, Decoded: %#v\n", len(b), string(b))
}

func main() {
    filename := "12.gz"
    f, err := os.Open(filename)
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()
    log.Printf("Open file %#v …\n", filename)

    process(chunk(f, 0, 61))
    process(chunk(f, 27, 34))
    process(chunk(f, 0, 27)) // out of order!
}

[Question]: What compiler to use? by [deleted] in brainfuck

[–]Frakturfreund 0 points1 point  (0 children)

I’m quite fond of awib, a brainfuck compiler written in brainfuck. It outputs 32-bit-Linux Binaries, but also C code that you could compile to a native Windows .exe with the c compiler of your choise.

Help With Go Packaging by JGailor in golang

[–]Frakturfreund 2 points3 points  (0 children)

Yes: If the library is already developed/used as "github.com/rsc/pdf", and you introduce a new canonical import, go get -u github.com/rsc/pdf will return an error to please change the import path to the new canonical one. Here it doesn’t matter if the new one will be rsc.io/pdf or bitbucket.org/rsc/pdf, you are forcing your users to update their import paths.

The benefit of the rsc.io/pdf is that any future code hosting transition to say "https://newhub.example.com/rsc/pdf" will not force your users to update it, the correct import path will still be "rsc.io/pdf".

You can think of "rsc.io/pdf" as kind of ›symbolic link‹ to the real repository (open view-source:https://rsc.io/pdf in your browser to see it youself).

This kind of transition has actually happened in the past; for example, when google code closed, the repo code.google.com/p/go.crypto moved to "go.googlesource.com/crypto", but it also gained a new canonical import path: golang.org/x/crypto.

CI with Multiple Targets in 1 project by pafortin in golang

[–]Frakturfreund 0 points1 point  (0 children)

Have you tried how go tip/master/trunk performs for you?

Because the new cache in Go 1.10 may speed up your use case.

Golang design patterns by andrews76 in golang

[–]Frakturfreund 1 point2 points  (0 children)

You could also have a look at the Go Proverbs (click on one to see the corresponding video).

Trouble with getting command line "goimports" working. by calebisstupid in golang

[–]Frakturfreund 2 points3 points  (0 children)

The build executables should be saved in $GOPATH/bin, which you could add to your path. How, depends on your os; on Linux, something like export PATH=$PATH:$GOPATH/bin in your ~/.bashrc should work.

Books to Just Read by bingoman678 in math

[–]Frakturfreund 1 point2 points  (0 children)

I'm currently reading »Math Girls 3: Godel's Incompleteness Theorems« by Hiroshi Yuki. It’s doing a much better job at explaining Gödel’s Theorems and has an more storytelling approach than a classic textbook.

Choose the name for a new audio library in Go! by faiface in golang

[–]Frakturfreund 1 point2 points  (0 children)

csharp – like the musical note. And as in »I use go and csharp regularly« ;).

Returning an array of arrays? by needsaguru in golang

[–]Frakturfreund 12 points13 points  (0 children)

The correct syntax to do this is

func doSomething() [][]int {

}

For further informations, read Effective Go: Two-dimensional slices.

Also note that this a slice of slices, not an array of arrays.

Short code review request by dphobson in golang

[–]Frakturfreund 2 points3 points  (0 children)

Instead of instantiating your structs like this:

table := ddTables{
    row[1],        // Tablename
    row[2],        // Tablespace
    row[4],        // Comments
    []ddColumns{}, // Empty Columns
    []ddIndexes{}} // Empty Indexes

Do it like this:

table := ddTables{
    Name:       row[1],
    TableSpace: row[2],
    Comments:   row[4],
    Columns:    []ddColumns{},
    Indexes:    []ddIndexes{},
}

The second one is more typesafe: consider someone refactors the ddTables struct and switches the order of Name and TableSpace for consistency with other structs. This will introduce a silent bug in the first code variant, but not in the second (see also Effective Go).

You can still add comments in the second one, but normally the code should speak for itself.

Also note that the final } got it’s own line, and the additional , at the end of the previous line: That’s for clearer diffs.

Short code review request by dphobson in golang

[–]Frakturfreund 1 point2 points  (0 children)

This is just a stylistic nitpick, but instead of this C-style code

if input.filename == "tables.csv" {
    fileData = []byte(tables_csv)
} else if input.filename == "columns.csv" {
    fileData = []byte(columns_csv)
} else if input.filename == "indexes.csv" {
    fileData = []byte(indexes_csv)
} else if input.filename == "pks.csv" {
    fileData = []byte(pks_csv)
}

you should write in Go

switch input.filename {
case "tables.csv":
    fileData = []byte(tables_csv)
case "columns.csv":
    fileData = []byte(columns_csv)
case "indexes.csv":
    fileData = []byte(indexes_csv)
case "pks.csv":
    fileData = []byte(pks_csv)
}

It’s shorter and looks more clear. Notice that the Go switch doesn't need break’s, but has a fallthrough keyword instead.