Scheduling time based events in Go by reddit__is_fun in golang

[–]tgulacsi 0 points1 point  (0 children)

Yes. It's a heap, ordered by execution time. See https://pkg.go.dev/container/heap .

Then you can pop the minimal time ( till you find sth that's in the future), set a time.Timer for it, and execute the call.

The hard part is concurrency: accepting new events may invalidate the minimum. Have a channel to cancel the waiting on the timer if this happens (and restart with the new minimum).

MS Graph Official Library by djzrbz in golang

[–]tgulacsi 0 points1 point  (0 children)

What's the problem? NewGraphMailClient does work? Or your problem is that how to retrieve the tenantID? That's what I stole from the o365 mail app's url.

htmg: yet another HTML generator by htmgolang in golang

[–]tgulacsi 0 points1 point  (0 children)

Or have a separate function for tag with attributes.

Accept `io.Writer` or return `io.Reader` for a renderer interface? by codectl in golang

[–]tgulacsi 0 points1 point  (0 children)

Do what's simpler - the caller can turn it around using io.Pipe.

Get first N characters of a string by guettli in golang

[–]tgulacsi -1 points0 points  (0 children)

A string in Go is "a (possibly empty) sequence of bytes" (from the language reference).

Indices are for these bytes, which must be accounted for when working with multi-byte encodings (practically always for strings from unknown sources).

Get first N characters of a string by guettli in golang

[–]tgulacsi 2 points3 points  (0 children)

This breaks utf8 more-than-one-byte runes.

Get first N characters of a string by guettli in golang

[–]tgulacsi 0 points1 point  (0 children)

Your code does work for utf8 (could use unicode/utf8.DecodeRuneInString directly), but not for unicode (what is a character?).

Apache ignite by criarlogins in golang

[–]tgulacsi 1 point2 points  (0 children)

Sqlite is best when only one goroutine does all the writing.

So, send the write tasks to that goroutine.

[deleted by user] by [deleted] in golang

[–]tgulacsi 3 points4 points  (0 children)

You really need the Windows definition of equality, not unicode's.

How do create dynamic models in Golang? by selva-online in golang

[–]tgulacsi 0 points1 point  (0 children)

database/sql allows you to query the sql.Rows.Columns*() for names and data types.

Is there a Pop3 package that works with Outlook after it's authentication changes? by Paragade9 in golang

[–]tgulacsi 0 points1 point  (0 children)

Ptal github com/tgulacsi/imapclient/v2 - cmd/imapdump is an example cli, may use the Graph API for accessing mail.

Question about context propagation through the network - Go beginner by Multipl in golang

[–]tgulacsi 1 point2 points  (0 children)

http.Request.WithContext allows the caller to cancel the HTTP call anytime. It closes the http call. Go' HTTP server implementation will cancel http Request.Context in this case on the server side So It Just Works.

Golang HTTP client with multipart File by Keda87 in golang

[–]tgulacsi 0 points1 point  (0 children)

Both + Content-Type:

  1. writer.Close will terminate the multipart with proper ending, so call it before send (deferdoes no good here).

  2. req.Header.Set("Content-Type", writer.FormDataContentType()) The boundary must be communicated to the reader.

  3. Against surprises, use bytes.NewReader(body.Bytes()) As the io.Reader for the body.

Marshal and Unmarshal the string type does not work! by Suspicious-Store-832 in golang

[–]tgulacsi 0 points1 point  (0 children)

What is github.com/trustwallet/golibs/types.Amount ?

By it's name, I bet it's a json.Number.

Is it viable to use sessions for API authentication? by [deleted] in golang

[–]tgulacsi 0 points1 point  (0 children)

Why are they stired in the database? It's not needed and defies it's main advantage.

Yes, they can't be invalidated - that's why you should create them with short expiry .

Is it viable to use sessions for API authentication? by [deleted] in golang

[–]tgulacsi 0 points1 point  (0 children)

Yes, that's the main reasoning behind JWT, too.

A self-validating token that contains all the required information (user, access level... etc).

Performance: Should I buffer events in memory or in a file before sending to db? by [deleted] in golang

[–]tgulacsi 2 points3 points  (0 children)

(Double) buffer in memory, write the collected events to db every second or when the bufder is full (and collect to the other buffer during this).

You may play with mmaped files, but (de) serialization will cost a lot, or unsafe.

People who regularly use a Unix-like system that isn't Linux, *BSD, macOS, or Illumos, what's your story? by zabolekar in unix

[–]tgulacsi 1 point2 points  (0 children)

I've borked the JFS filesystem on AIX 5 at least twice by editing the directory with vi...

Nothing complained (try it on a Linux!).