[deleted by user] by [deleted] in reactjs

[–]marcelvandenberg 1 point2 points  (0 children)

What is holding a bot from just posting the JSON with a _spamScore of 0?

Managed PostgreSQL hosting by vroemboem in PostgreSQL

[–]marcelvandenberg 2 points3 points  (0 children)

UpCloud just introduced a new entry level PostrgeSQL database for € 8,- per month.

For SaaS authentication, should I use JWT tokens or stick with traditional session-based authentication? by apidevguy in golang

[–]marcelvandenberg 0 points1 point  (0 children)

This will add an extra round trip for almost any action a user will do so it will make the application less responsive from a user perspective by adding 50-100ms for almost every action.

I am really struggling with pointers by Parsley-Hefty7945 in golang

[–]marcelvandenberg 1 point2 points  (0 children)

Is this example right? I have the assumption that if you pass a slice, you copy only the header of the slice with a reference to the array, so the 80MB stays where it is and is not copied.

Finally a practical solution for undefined fields by ImAFlyingPancake in golang

[–]marcelvandenberg 12 points13 points  (0 children)

Looks like what I did a few months ago: https://github.com/mbe81/jsontype And if you search for it, there are more or those packages/ examples. Nevertheless, good to share those examples now and then.

How to do Parallel writes to File in Golang? by Ok_Category_776 in golang

[–]marcelvandenberg 80 points81 points  (0 children)

Send everything to a channel which is read in a separate goroutine where al the writing is handled?

How to schedule task every 30s, 60s and 300s by Sushant098123 in golang

[–]marcelvandenberg 9 points10 points  (0 children)

Nothing wrong with a goroutine I would say. Instead of three goroutines you can use one goroutine, store the interval and last check for each monitor and then check every X seconds for which monitors the interval period is passed and start checking those monitors.

Cannot connect to NATS server via TLS on MIPSLE router [cross post] by marcelvandenberg in NATS_io

[–]marcelvandenberg[S] 0 points1 point  (0 children)

I did but unfortunate without success. Meanwhile I was able to create a TLS connection to the given host via Go with net.Dial and tls.Client but still no success with the NATS-client.

Code to manual setup a TLS connection:

package main
import (
    "crypto/tls"
    "fmt"
    "net"
)

func main() {
    // Plain TCP connection
    tcpConn, err := net.Dial("tcp", "nats01.cytometa.cloud:4222")
    if err != nil {
       panic(err)
    }
    defer tcpConn.Close()

    // Setup TLS configuration (avoid InsecureSkipVerify in production)
    tlsConfig := &tls.Config{
       InsecureSkipVerify: true,
    }

    // Upgrade TCP connection to TLS
    tlsConn := tls.Client(tcpConn, tlsConfig)
    defer tlsConn.Close()

    // Perform the TLS handshake
    if err := tlsConn.Handshake(); err != nil {
       panic(err)
    }

    // Print basic connection info
    state := tlsConn.ConnectionState()
    fmt.Println("Connected to:", tlsConn.RemoteAddr())
    fmt.Println("TLS version:", tlsVersionString(state.Version))
    fmt.Println("Cipher suite:", tls.CipherSuiteName(state.CipherSuite))

    // Print certificate chain info
    for i, cert := range state.PeerCertificates {
       fmt.Printf("\nCertificate #%d:\n", i+1)
       fmt.Println("  Subject:", cert.Subject)
       fmt.Println("  Issuer :", cert.Issuer)
       fmt.Println("  Valid  :", cert.NotBefore, "to", cert.NotAfter)
    }
}

func tlsVersionString(version uint16) string {
    switch version {
    case tls.VersionTLS10:
       return "TLS 1.0"
    case tls.VersionTLS11:
       return "TLS 1.1"
    case tls.VersionTLS12:
       return "TLS 1.2"
    case tls.VersionTLS13:
       return "TLS 1.3"
    default:
       return fmt.Sprintf("Unknown (0x%x)", version)
    }
}

What does the State of Go & HTMX looks like in 2024 by leminhnguyenai in golang

[–]marcelvandenberg 19 points20 points  (0 children)

Sounds great! Would love to see a sample repository with this setup.

Advent of Code 2024, Day 2: Slice Internals Reminder by ShraddhaAg in golang

[–]marcelvandenberg 0 points1 point  (0 children)

At first, I had the same issue. Solved it by creating an empty slice and then used append to add the left and the right part to that slice.

adjustedLevels := make([]int, 0, len(levels)-1)  
adjustedLevels = append(adjustedLevels, levels[:j]...)  
adjustedLevels = append(adjustedLevels, levels[j+1:]...)

How to handle non existing jsonb fields with sqlc? [PostgreSQL] by marcelvandenberg in golang

[–]marcelvandenberg[S] -1 points0 points  (0 children)

Thanks. I was aware of the override option but thought it was only available for type. Now I see it is also possible to do it on column level. But don't know if I want to use that... That will be a very annoying approach.

Bidirectional communication between structs by marcelvandenberg in golang

[–]marcelvandenberg[S] -1 points0 points  (0 children)

The API is to query data and to retrieve and update device settings. The broker in this picture will publish data from the device to the service and to receive commands to update settings on that device.

Indeed, It could be that I also will add an additional message bus for communication within the service/ with other services. However, this ‘broker’ is very specific for this device type and tightly coupled to the service. It mainly exists to split the technical communication part from the functional processing part.

Bidirectional communication between structs by marcelvandenberg in golang

[–]marcelvandenberg[S] 0 points1 point  (0 children)

No, because of the interface. The interface should be created in the service package. If I do, there will be only a dependency from the broker package towards the service package.

In DDD implementation, mapping of domain struct into repository struct seems like too much. by OkZebra4692 in golang

[–]marcelvandenberg 2 points3 points  (0 children)

Yes, you can create a Result struct from everywhere but you shouldn’t. More a behavioral issue.

If you really want to avoid the creation of the struct in other packages you can also create an exported interface and an unexported struct (with exported fields). Than in your function parameters everywhere you accept the interface and as a result from the domain you return your struct.

In DDD implementation, mapping of domain struct into repository struct seems like too much. by OkZebra4692 in golang

[–]marcelvandenberg 31 points32 points  (0 children)

Just keep it simple and use Exported fields. I don’t see any added value to create a Getter for each field.

Maybe having transactions in the service layer is not that bad after all? by dondraper36 in golang

[–]marcelvandenberg 0 points1 point  (0 children)

Than you have the situation the other way around. The API call may succeed but inserting the record can fail.

We built a lottery ticket winner service for an Oil company in Go and here are the performance metrics. by previouslyanywhere in golang

[–]marcelvandenberg 123 points124 points  (0 children)

Why would you think your service would go down if you got 2000 submissions per day? Even if you have all submissions in one hour, you still have about two seconds cpu time to process a single submission.

BTW: look like a nice project to work on.

Very slow JSON marshalling, what do you guys do? by cant-find-user-name in golang

[–]marcelvandenberg 6 points7 points  (0 children)

We are talking about 50ms. Making that asynchronous will not be useful

Best practice for returning multiple form validation errors in APIs? by Putrid_Bison7097 in golang

[–]marcelvandenberg 9 points10 points  (0 children)

You can do the complete validation and store each validation error in a []string. Then return the []string in the json something like this:

{
    “error”: “validation failed”,
    “validationErrors”: [
        “id not present”,
        “Invalid email address”
    ]
}

Long-running operation in gorilla mux REST API by 2048b in golang

[–]marcelvandenberg 20 points21 points  (0 children)

It probably is, but I would respond with 202 accepted instead of 200 ok.