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
51
 
 

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

A new demo video has been uploaded here.

This release contains the following new features/fixes:


Redesigned Media Queue

The queue is now completely managed by invidtui, with MPV being used only for playback. This change resulted in a big reduction in CPU usage, especially when loading large playlists.

  • Shuffle mode is on-demand, with a focus on not playing the same item more than once in a single cycle.
  • Media statuses (fetching/loading/playing) are shown for the currently selected item
  • Dynamic audio/video switching of any item in the queue
  • Media items are fetched from the selected instance, and can be reloaded as the instance is changed.

Media Fetcher

The new media fetcher will show statuses of each added media item, and allow for viewing any errors and performing reload/cancel actions on each or all media items being added.


Playlist/Player Improvements

Playlists are now downloaded faster, and are generated in the proper M3U8 format. The player also shows media statuses, as well as the buffering percentage of the current media.

Note that playlists may have to be regenerated/redownloaded if they were previously generated by older versions.


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

52
53
 
 

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
4
submitted 11 months ago* (last edited 11 months ago) by mac to c/golang
 
 

Not OC

55
56
57
58
59
60
 
 

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
 
 

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
63
 
 

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

64
3
Google's Go Style Guide (google.github.io)
submitted 1 year ago by mac to c/golang
65
66
18
submitted 1 year ago by mac to c/golang
67
 
 

πŸš€ 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
10
submitted 1 year ago by agilob to c/golang
69
 
 

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

Well, the author needs no introduction πŸ˜…

https://research.swtch.com/coro

70
 
 

Go 1.22 will ship with "range over int" and experimental support for "range over func" πŸ₯³

71
6
Go API server (gitlab.com)
submitted 1 year ago by lyda to c/golang
 
 

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

72
 
 

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
 
 

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
 
 

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
24
submitted 1 year ago by nebiros to c/golang
 
 

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 β€Ί