51
19
submitted 10 months ago by tedu@azorius.net to c/golang@programming.dev

Based on the Go 1.22 release notes from the Go team (3-Clause BSD License), with many interactive examples added. This blog post is synchronized with the source document as it gets updated.

52
10
submitted 11 months ago by 111000@reddthat.com to c/golang@programming.dev
53
8

Hi ๐Ÿ‘‹

I have tried to learn some go but I am still very much at the beginning, like understanding how to work with variables and functions. My background is mostly in python but I am not a programmer by trade.

package main

import (
	"crypto/sha256"
	"fmt"
	"io"
	"log"
	"os"
	"path/filepath"
)

func write_lines_to_file(lines []string, output_file string) {
	f, err2 := os.Create(output_file)
	if err2 != nil {
		log.Fatal(err2)
	}
	defer f.Close()
	for _, line := range lines {
		_, err := f.WriteString(line + "\n")
		if err != nil {
			log.Fatal(err2)
		}
	}
}

func get_size_and_hash(file_path string) (int, string) {
	file, err := os.Open(file_path)
	if err != nil {
		panic(err)
	}
	defer file.Close()
	hash := sha256.New()
	if _, err := io.Copy(hash, file); err != nil {
		panic(err)
	}
	sum := fmt.Sprintf("%x", hash.Sum(nil))
	file, err2 := os.Open(file_path)
	if err2 != nil {
		log.Fatal(err2)
	}
	fi, err2 := file.Stat()
	if err != nil {
		log.Fatal(err2)
	}
	my_size := fi.Size()
	return int(my_size), string(sum)
}

func get_list_of_files(target_directory string) []string {
	var files []string
	err := filepath.Walk(target_directory, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			fmt.Println(err)
			return nil
		}
		if !info.IsDir() {
			files = append(files, path)
		}
		return nil
	})
	if err != nil {
		log.Fatal(err)
	}
	return files
}

func main() {
	// accept directory as user input
	target_directory := os.Args[1]

	my_files := get_list_of_files(target_directory)

	var content []string

	for _, file := range my_files {
		size, hash := get_size_and_hash(file)
		var str_file string = string(file)
		str_size := fmt.Sprint(size)
		var str_hash string = string(hash)
		// structure: file, checksum, size
		combined_line := str_file + "," + str_hash + "," + str_size
		content = append(content, combined_line)
	}

	var output_file string = target_directory + "/PULP_MANIFEST"
	write_lines_to_file(content, output_file)
}

I am testing this using the following command: rm -f test_input/PULP_MANIFEST && go fmt pulp_manifest.go && go build pulp_manifest.go && ./pulp_manifest test_input && cat test_input/PULP_MANIFEST on Fedora with go 1.20

Known Limitations

  • My rewrite does not handle files or directories with "," yet.

Untested

  • Files with binary content
  • Paths on macOS or Microsoft Windows
  • Paths with whitespace
  • Symlinks in target_directory
  • target_directory as symlink

I am looking for the following feedback:

  • bugs and limitations
  • a was to add tests: do you have any recommendations for talks or blog posts?
  • style & best practice
  • a way to use static typing?!
  • anything else that you would recommend a novice.

Right now, I believe my rewrite works. Feel free to shatter my assumption. Cheers.

54
5
submitted 11 months ago* (last edited 11 months ago) by mac@programming.dev to c/golang@programming.dev

Not OC

55
12
submitted 11 months ago by mac@programming.dev to c/golang@programming.dev
56
10
57
17
submitted 11 months ago by mac@programming.dev to c/golang@programming.dev
58
15
59
2
60
12

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

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

Hey guys, I made pong clone in Golang with Raylib. Was wondering what you all thought about it.

61
10
submitted 11 months ago* (last edited 11 months ago) by darkhz@lemm.ee to c/golang@programming.dev

Hello Lemmy,

invidtui is a TUI-based Invidious client, which can:

  • Search for and browse videos, playlists and channels
  • Play audio or video from any instance
  • View, open, edit and save m3u8 playlists
  • Download video/audio in any format
  • Authenticate with the preferred instance, and show user feed, playlists and subscriptions

This release contains the following new features/fixes:


  • Playlists are downloadable as well, with progress display in the "Downloads" page. Deleted/private videos are stored separately from the public ones.

    To use this feature:

    • Select a playlist with the i key, wait for the playlist to load
    • Press Ctrl+S to initialize the download
    • To view the progress of the download, press Y

  • Optimizations to the playlist file loading and queue rendering (reduced CPU usage)
    • Updating the queue only for new/updated items
    • Rate limiting the calls to MPV
    • Cancellable loading of playlist entries
      • Open the queue and press x to cancel loading the playlist entries.

  • An "Initializing" indicator is shown when the player is hidden and about to start playing a file

I hope you enjoy this release, and any feedback is appreciated.

62
-3
63
9

Open source with a repo for it at https://github.com/uber-go/nilaway/

64
2
Google's Go Style Guide (google.github.io)
65
17
66
18
67
10
submitted 1 year ago* (last edited 1 year ago) by microcksio@mastodon.social to c/golang@programming.dev

๐Ÿš€ Thrilled to launch today our @golang #testcontainers lib! ๐ŸงŠ

Now you can pop out Microcks from your Go tests to mock your
@openapi, @graphql or #grpcio dependencies and test your #API. It's based on our new #Go client, contributed by @julienbreux ๐Ÿ‘๐ŸŽ‰

๐Ÿ‘‰https://testcontainers.com/modules/microcks/

68
4
69
3

๐Ÿ‘€ Very interesting a deep dive into coroutines and coroutines in @golang

Well, the author needs no introduction ๐Ÿ˜…

https://research.swtch.com/coro

70
2

Go 1.22 will ship with "range over int" and experimental support for "range over func" ๐Ÿฅณ

71
3
Go API server (gitlab.com)

A template project for creating OpenAPI document driven API servers in Go.

72
1
submitted 1 year ago* (last edited 1 year ago) by darkhz@lemm.ee to c/golang@programming.dev

Hello Lemmy,

Bluetuith is a TUI based bluetooth manager for Linux, that aims to be an alternative to most bluetooth managers, and can perform bluetooth based operations like:

  • Connection to and general management of bluetooth devices, with device information like battery percentage, RSSI etc. displayed, if the information is available. More detailed information about a device can be viewed by selecting the 'Info' option in the menu or by clicking the 'i' key.

  • Bluetooth adapter management, with toggleable power, discoverability, pairablilty and scanning modes.

  • Transfer and receive files via the OBEX protocol, with an interactive file picker to choose and select multiple files.

  • Handle both PANU and DUN based networking for each bluetooth device

  • Control media playback on the currently connected device, with a media player popup that displays playback information and controls.

This release contains the following new features:

  • New command-line options --adapter-states to set adapter properties and --connect-bdaddr to connect to a device on initialization
  • Block/unblock devices
  • Indefinite passkey/pincode display
  • Modifiable navigation keys
  • Display the 'Bonded' property for a device

I hope you enjoy this release, and any feedback is appreciated.

73
1
submitted 1 year ago by tedu@azorius.net to c/golang@programming.dev

In this write-up, weโ€™ll delve into how, through differential fuzzing, we uncovered a bug in Goโ€™s exp/net HTMLโ€™s tokenizer. Weโ€™ll show potential XSS implications of this flaw. Additionally, weโ€™ll outline how Google assessed this finding within their VRP program and guide how to engage and employ fuzzing to evaluate your software.

74
2

Say I have go:generate directives in two files: one in the foo/ directory and one in the mock/ directory. The generated mock code will need data structures from the generated code in the foo module. Will go generate ./... reliably generate code in the correct order? What do I need to do to make that happen?

75
3

Oh no, not another 'Is Rust better than Go?' article. Seriously, haven't we all had our fill of these comparisons by now? But before you sigh in exasperation, hear us out!

view more: โ€น prev next โ€บ

Golang

1 readers
1 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 1 year ago
MODERATORS