GolangWebDev

GolangWebDev

admin Joined on Jun 01, 2022

Recent comments

Deal with sticky tcp/socket packet in Golang

GolangWebDev
GolangWebDev Dec 15, 2022 11:32 UTC

Here is a simple solution if you want to read all received data.

    connbuf := bufio.NewReader(c.m_socket)
    // Read the first byte and set the underlying buffer
    b, _ := connbuf.ReadByte() 
    if connbuf.Buffered() > 0 {
        var msgData []byte
        msgData = append(msgData, b)
        for connbuf.Buffered() > 0 {
            // read byte by byte until the buffered data is not empty
            b, err := connbuf.ReadByte()
            if err == nil {
                msgData = append(msgData, b)
            } else {
                log.Println("-------> unreadable caracter...", b)
            }
        }
        // msgData now contain the buffered data...
    }
``

Hello, This's a Golang web forum!

GolangWebDev
GolangWebDev Jun 01, 2022 02:50 UTC

Bolt allows only one read-write transaction at a time, this site all CRUD are use transaction.

// Start a writable transaction.
tx, err := db.Begin(true)
if err != nil {
    return err
}
defer tx.Rollback()

// Use the transaction...
_, err := tx.CreateBucket([]byte("MyBucket"))
if err != nil {
    return err
}

// Commit the transaction and check for error.
if err := tx.Commit(); err != nil {
    return err
}

Recent posts

Login Topics