Store - Read and write data structures

Store - Read and write data structures

Store provides the ability to write the data structures to a file and read from a file in the Go programming language.

The module provides possibility of the data structures in a JSON format or in a binary format. During the writing or reading process the file is locked.

Reading/writing in JSON format were implemented with the standard library encoding/json.

For reading/writing in binary format the module is encoding/gob used.

Usage

Writing in JSON format to a file:

type message struct {
	Name      string
	Timestamp time.Time
	Payload   []byte
	Ssid      []uint32
}

msg := &message{
    Name:      "John",
    Timestamp: time.Now(),
    Payload:   []byte("hi"),
    Ssid:      []uint32{1, 2, 3},
}

if err := WriteJSON("./temp.json", msg); err != nil {
    log.Fatalln(err)
}

Read from a file written in JSON format:

var msg message
if err := ReadJSON("./temp.json", &msg); err != nil {
    log.Fatalln(err)
}

fmt.Println(msg.Name) // Output John

Writing in binary format to a file:

type message struct {
	Name      string
	Timestamp time.Time
	Payload   []byte
	Ssid      []uint32
}

msg := &message{
    Name:      "John",
    Timestamp: time.Now(),
    Payload:   []byte("hi"),
    Ssid:      []uint32{1, 2, 3},
}

if err := WriteBinary("./temp.bin", msg); err != nil {
    log.Fatalln(err)
}

Read from a file written in binary format:

var msg message
if err := ReadBinary("./temp.bin", &msg); err != nil {
    log.Fatalln(err)
}
fmt.Println(msg.Name) // Output John

Copyright

Copyright (c) 2021 Andrej Giesbrecht

Owner
Similar Resources

A non-go engineer tries to write Go to solve Advent of Code

Wherein an engineer (who primarily uses Kotlin, Java, Scala and C#) tries to teach themselves Go by solving Advent of Code challenges. It's... not pre

Dec 9, 2021

A project that provides an in-memory key-value store as a REST API. Also, it's containerized and can be used as a microservice.

Easy to Use In-Memory Key-Value Store A project that provides an in-memory key-value store as a REST API. Also, it's containerized and can be used as

Mar 6, 2022

Exercise for solve problem data processing, performance and something wrong in passing data

Citcall Exercise Exercise for solve problem data processing, performance and something wrong in passing data Pengolahan data data processing - Readme

Nov 25, 2021

Windows Store Installer for VS Code

vscode-winsta11er This repo contains the code for a simple Go-based installer for the new Windows store. Releases To create a release, create and push

Dec 9, 2022

Implement a toy in-memory store information service for a delivery company

Implement a toy in-memory store information service for a delivery company

Nov 22, 2021

An in-memory, key-value store HTTP API service

This is an in-memory key-value store HTTP API service, with the following endpoints: /get/{key} : GET method. Returns the value of a previously set ke

May 23, 2022

Simple distributed kv-store using ABD algorithm.

Distributed-kv-store Simple distributed kv-store using ABD algorithm. API GET /key Get value by key. 302 = found key. PUT /key Put key with value. 201

Dec 14, 2021

A server for TurboRepo Remote Cache to store cache artefacts in Google Cloud Storage or Amazon S3

Tapico Turborepo Remote Cache This is an implementation of Vercel's Turborepo Remote Cache API endpoints used by the turborepo CLI command. This solut

Dec 13, 2022

Random fake data and struct generator for Go.

Faker Random fake data and struct generator for Go. More than 100 generator functions Struct generator Unique data generator Builtin types support Eas

Oct 3, 2022
Related tags
Gosfdc module - a collection of packages containing the data structures from the various Salesforce APIs and Tools

Gosfdc module - a collection of packages containing the data structures from the various Salesforce APIs and Tools

Jan 21, 2022
Decrypts and dumps K3s bootstrap data read from stdin.

k3s-dump-bootstrap Decrypts and dumps K3s bootstrap data read from stdin. Note: <token> parameter should be just the bare passphrase, not a full K10-f

Jan 12, 2022
Read RFID card data so Protospace directors can assign them to users!

RFID Reader Dependencies This application was developed with: go1.17.5 linux/amd64 xclip version 0.13 (if you're on Linux) Find go for your OS and arc

Dec 15, 2021
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations.

typex Examine Go types and their transitive dependencies. Export results as TypeScript value objects (or types) declaration. Installation go get -u gi

Dec 6, 2022
Parse a shell script and output all export declarations in an easy to read format

Find Exports Parse a shell script and output all export declarations in an easy to read format. Usage Example $ findexports ~/.bashrc PATH=$PATH:/usr/

Jan 13, 2022
Write API for employees and teams

Problem Manager Employees - Teams Connect to Database and save information Write API for employees and teams Getting Started Install MySQL Create file

Feb 18, 2022
Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it.

Day-1 is apart of my 6 days of Christmas challenge where i write in two new languages everyday, and make something weird out of it. today was a HTTP server written with PostGreSQL using Golang, R, and shell script read more

Dec 21, 2021
Vocabular checker JetBrains Academy home work Read file with bad words

Vocabulary Checker JetBrains Academy home work Read file with bad words and replace them on * in the next entered text until exitVocabulary Checker JetBrains Academy home work Read file with bad words and replace them on * in the next entered text until exit

Jan 14, 2022
Neko is a cross-platform open-source animated cursor-chasing cat. This is the reimplementation write in Go.

Neko Neko is a cat that chases the mouse cursor across the screen, an app written in the late 1980s and ported for many platforms. This code is a re-i

Nov 21, 2022
Go jackc/pgx helper to write proper transactions

Go jackc/pgx helper to write proper transactions.

Dec 16, 2022