Golang

2217 readers
1 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 1 year ago
MODERATORS
126
 
 

cross-posted from: https://lemmy.ml/post/2230752

I really like seeing people's interesting projects. Even if they are generic or were started just to learn something.

And on top of that, I consider Go to be one of those languages that you can find projects on a pretty diverse range of topics.

So, is there any interesting (or not too) personal Go projects that is in the making, or is already finished?

127
 
 

Are there any websites, newsletters or RSS feeds that you could redo to read/subscribe to get the latest news about Go and everything around it? Like, not only about releases of new versions of the language itself, but also about trends around it.

Is there anything like that?

128
 
 

Go tech lead Russ Cox:

This post is about why we need a coroutine package for Go, and what it would look like.

With a post like this it usually means there will almost certainly be a new standard library package. But even more interestingly:

If we are to add coroutines to Go, we should aim to do it without language changes. That means the definition of coroutines should be possible to implement and understand in terms of ordinary Go code. Later, I will argue for an optimized implementation provided directly by the runtime, but that implementation should be indistinguishable from the pure Go definition.

129
130
10
Analyzing Go Build Times (blog.howardjohn.info)
submitted 1 year ago by nebiros to c/golang
131
 
 

Govulncheck is a command-line tool that helps Go users find known vulnerabilities in their project dependencies. The tool can analyze both codebases and binaries, and it reduces noise by prioritizing vulnerabilities in functions that your code is actually calling.

132
9
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/golang
 
 

Go 1.21 is almost here and as usual, with it is a pile of features and improvements.

I'm looking forward to using the new clear function as well as the new slices and maps packages.

What about you?

133
 
 

What's the change with highest impact to you?

134
16
submitted 1 year ago by krom to c/golang
135
5
Generics in Go (bitfieldconsulting.com)
submitted 1 year ago by austin to c/golang
136
137
9
submitted 1 year ago* (last edited 1 year ago) by CodeBlooded to c/golang
 
 

I’ve been using this to execute Go “scripts” in CI pipelines where Bash just doesn’t cut it. It’s an interpreter for Go. It can be used to treat Go code like a “script,” rather than a compiled application. It is also able to be imported into a Go program and used to load up Go code dynamically at run time (think “loading plugins” with Go!).

From the readme:

release Build Status GoDoc

Yaegi is Another Elegant Go Interpreter. It powers executable Go scripts and plugins, in embedded interpreters or interactive shells, on top of the Go runtime.

Features

  • Complete support of Go specification
  • Written in pure Go, using only the standard library
  • Simple interpreter API: New(), Eval(), Use()
  • Works everywhere Go works
  • All Go & runtime resources accessible from script (with control)
  • Security: unsafe and syscall packages neither used nor exported by default
  • Support the latest 2 major releases of Go (Go 1.19 and Go 1.20)

Install

Go package

import "github.com/traefik/yaegi/interp"

Command-line executable

go install github.com/traefik/yaegi/cmd/yaegi@latest

Note that you can use rlwrap (install with your favorite package manager), and alias the yaegi command in alias yaegi='rlwrap yaegi' in your ~/.bashrc, to have history and command line edition.

CI Integration

curl -sfL https://raw.githubusercontent.com/traefik/yaegi/master/install.sh | bash -s -- -b $GOPATH/bin v0.9.0

Usage

As an embedded interpreter

Create an interpreter with New(), run Go code with Eval():

package main

import (
	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
)

func main() {
	i := interp.New(interp.Options{})

	i.Use(stdlib.Symbols)

	_, err := i.Eval(`import "fmt"`)
	if err != nil {
		panic(err)
	}

	_, err = i.Eval(`fmt.Println("Hello Yaegi")`)
	if err != nil {
		panic(err)
	}
}

Go Playground

As a dynamic extension framework

The following program is compiled ahead of time, except bar() which is interpreted, with the following steps:

  1. use of i.Eval(src) to evaluate the script in the context of interpreter
  2. use of v, err := i.Eval("foo.Bar") to get the symbol from the interpreter context, as a reflect.Value
  3. application of Interface() method and type assertion to convert v into bar, as if it was compiled
package main

import "github.com/traefik/yaegi/interp"

const src = `package foo
func Bar(s string) string { return s + "-Foo" }`

func main() {
	i := interp.New(interp.Options{})

	_, err := i.Eval(src)
	if err != nil {
		panic(err)
	}

	v, err := i.Eval("foo.Bar")
	if err != nil {
		panic(err)
	}

	bar := v.Interface().(func(string) string)

	r := bar("Kung")
	println(r)
}

Go Playground

As a command-line interpreter

The Yaegi command can run an interactive Read-Eval-Print-Loop:

$ yaegi
> 1 + 2
3
> import "fmt"
> fmt.Println("Hello World")
Hello World
>

Note that in interactive mode, all stdlib package are pre-imported, you can use them directly:

$ yaegi
> reflect.TypeOf(time.Date)
: func(int, time.Month, int, int, int, int, int, *time.Location) time.Time
>

Or interpret Go packages, directories or files, including itself:

$ yaegi -syscall -unsafe -unrestricted github.com/traefik/yaegi/cmd/yaegi
>

Or for Go scripting in the shebang line:

$ cat /tmp/test
#!/usr/bin/env yaegi
package main

import "fmt"

func main() {
	fmt.Println("test")
}
$ ls -la /tmp/test
-rwxr-xr-x 1 dow184 dow184 93 Jan  6 13:38 /tmp/test
$ /tmp/test
test

Documentation

Documentation about Yaegi commands and libraries can be found at usual godoc.org.

Limitations

Beside the known bugs which are supposed to be fixed in the short term, there are some limitations not planned to be addressed soon:

  • Assembly files (.s) are not supported.
  • Calling C code is not supported (no virtual "C" package).
  • Directives about the compiler, the linker, or embedding files are not supported.
  • Interfaces to be used from the pre-compiled code can not be added dynamically, as it is required to pre-compile interface wrappers.
  • Representation of types by reflect and printing values using %T may give different results between compiled mode and interpreted mode.
  • Interpreting computation intensive code is likely to remain significantly slower than in compiled mode.

Go modules are not supported yet. Until that, it is necessary to install the source into $GOPATH/src/github.com/traefik/yaegi to pass all the tests.

Contributing

Contributing guide.

License

Apache 2.0.

138
139
 
 

cross-posted from: https://infosec.pub/post/249829

Basicgopot is a basic honeypot I have been developing. It is an HTTP honeypot that logs and saves all file uploads, optionally checking the uploaded file against VirusTotal. Additionally, the user can easily extend the functionality of the honeypot by configuring API webhooks. I plan on adding more features and possibly broadening the project's scope to include deploying deceptions for other protocols.

I would appreciate any feedback and contributions are always welcome.

140
5
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/golang
 
 

cross-posted from: https://infosec.pub/post/244512

This is a linter I wrote for Go that ensures all slice and array bound accesses are validated. Right now, it ensures that all accesses are enclosed within an if-statement that calls cap or len.

Any and all contributions and feature requests are welcome.

141
20
submitted 1 year ago by austin to c/golang
142
 
 

cross-posted from: https://programming.dev/post/166688

Neon Modem is built in Go, using Charm's Bubble Tea TUI framework:

143
 
 

Go 1.21 RC released today. Some really interesting new additions. I'm pretty excited to see the map and slice package additions that contain a lot of generic methods. Will be nice not to have to maintain my own going forward.

144
145
8
Don't use mocks (joeblu.com)
submitted 1 year ago by [email protected] to c/golang
 
 

Always interesting to hear different points of view on this subject. Personally I think mocks make sense to capture complex sets of interactions or otherwise difficult to reach error conditions, so I don't think it's a do or do-not kind of thing.

146
147
148
12
submitted 1 year ago* (last edited 1 year ago) by RandomDevOpsDude to c/golang
 
 

Good quality production go

149
10
Write Go like a senior engineer (levelup.gitconnected.com)
submitted 1 year ago by RandomDevOpsDude to c/golang
150
 
 

I don't feel terribly strongly either way, but I do lean towards the cleaner "Go" as that is the language's true name and is more idiomatic Go :)

Folks will surely understand what it means either way, but I figured we should try to get ourselves set off on the right foot!

For the record I think a mix of terms could work too. Like the community url could remain the same: /c/golang aka !golang but then the 'nice' name could just be "Go programming language" or the context could be understood as we are on programming.dev and it could just be "Go", as well as having the icon to help people identify it as the programming language.

view more: ‹ prev next ›