Is any of you using it? If so, what are you building?
At the moment I'm trying to replicate this website. It's the first time I'm using Go and I'm finding it pretty amusing.
>>1
I started to learn it once. It's an interesting option. I don't know what I'd use for concurrency: Erlang, Go, Lua or (((Scheme)))
>>2
I think I'd choose Go to do it. It feels very natural.
I've been messing around with Go for a month or so now and I'm taking quite a liking to it, at least compared to what I used before it.
What have you been doing with it?
>>5 General web development projects. I feel like it's a pretty good tool for the job for my case.
Cff
>>7 What's this?
>>6
Are you using fasthttp or net/http? What made you choose one over the other?
aea
It's pretty great, especially for web development. Web development is a bit impractical to do in C, but golang basically enables you do to a C-style for it, given it's extremely apt standard library for the task. For anything else though I'd probably just go with C.
Unless you have millions of connections each second, there's almost no reasons to not use the better known stdlib net/http.
>>9 I've always used net/http, I don't see much of a reason to use otherwise like >>12 mentioned.
I like the syntax and the standard library but I hate messing with slices. You need to do the following to add an item to a slice:
a = append(a, item)
But when it comes to removing an item there's no
remove(a, index)
to remove an item.
s
Yeah, that's wierd but the trick is to re-use append when removing like this:
a = append(a[:index], a[:index+1]...)
as described here: https://github.com/golang/go/wiki/SliceTricks.
>>16 I have this wiki in a cheatsheet but it's rather uncomfortable to write this syntax. Nevertheless I find Go pretty cool to write toy projects on.
I made a program that I use with i3lock.
package main
import (
"flag"
"fmt"
"image"
"image/png"
"log"
"os"
"golang.org/x/image/draw"
)
var (
flagImage = flag.String("i", "", "Path to the image you want to pixelate")
flagOutput = flag.String("o", "", "Path to the output image")
flagScale = flag.Int("p", 0, "How much you want to pixelate. [1-100]")
)
func init() {
flag.Parse()
if *flagImage == "" || *flagOutput == "" {
flag.Usage()
os.Exit(1)
}
if *flagScale < 1 || *flagScale > 100 {
fmt.Println("the -p flag must be between 1-100")
os.Exit(1)
}
}
func main() {
img, err := OpenImage(*flagImage)
if err != nil {
log.Fatalf("could not open image '%s': %s\n", *flagImage, err)
}
scaledDown := Rect(img, 100-*flagScale)
out := ScaleTo(img, scaledDown)
originalSize := Rect(img, 100)
out = ScaleTo(out, originalSize)
err = SaveImage(*flagOutput, out)
if err != nil {
log.Fatalf("could not save file to '%s': %s\n", *flagOutput, err)
}
}
func Rect(img image.Image, scale int) image.Rectangle {
s := float64(scale) / 100
x := int(s * float64(img.Bounds().Max.X))
y := int(s * float64(img.Bounds().Max.Y))
return image.Rect(0, 0, x, y)
}
func ScaleTo(from image.Image, rect image.Rectangle) image.Image {
to := image.NewRGBA(rect)
draw.NearestNeighbor.Scale(to, rect, from, from.Bounds(), draw.Over, nil)
return to
}
func SaveImage(path string, img image.Image) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
err = png.Encode(file, img)
if err != nil {
return err
}
return nil
}
func OpenImage(path string) (image.Image, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
img, err := png.Decode(file)
if err != nil {
return nil, err
}
return img, nil
}
I use it with this script:
#!/usr/bin/bash
VALUE=$1
IMG=/tmp/i3lock.png
maim /tmp/i3lock.png
pixelate -i $IMG -o $IMG -p $VALUE
i3lock -i $IMG
rm $IMG
>>19
Came back here to bump this thread and ask how Go was going for you. Talk about synchronicities.
synchronicities
I didn't know about it. Thanks for introducing it to me!
It's been really good. I'm a miserable programmer so I've just understand generics and I'm already missing it. This program is an example of the lack of generics as methods for gif, jpg and png are all the same and I can't wrap them around a generic function. I don't know how to do it with interfaces because I know I have to type structs with the same method for all of them just to get an "unified" function call. Not worth it for a small program like that.
Nevertheless I really enjoy the syntax and the tooling. Having a standard formatter and a whole lot of architecture support out of the box is something I appreciate.
But tell me about you, anon. How has it been for you?
>>21
I have yet to learn it properly and write small programs, like you did. I was curious about your progress and thought to ask you how you were doing. Then I saw that you came back here half an hour before me, answering all those questions.
Have you already grasped Go's model of concurrency?
Have you already grasped Go's model of concurrency?
Yeah, it's not hard at all. My main problem is not knowing when to apply it. But as far as I can tell I don't plan to take Go too far. I like to use it to write small programs.
https://fasterthanli.me/blog/2020/i-want-off-mr-golangs-wild-ride/
I stumbled across most of the problems mentioned on this article.
Any news on Go 2?