Simple user currency module that uses JSON.

UserCurrency

Simple user currency module that uses JSON.

Install

go get github.com/NeutronX-dev/UserCurrency

Functions

  • func UserCurrency.Read(path_to_json string) (*ProfileList, error)

Types & Methods

  • ProfileList
    • func (Profiles *ProfileList) UserExists(user string) bool
    • func (Profiles *ProfileList) CreateUser(user string)
    • func (Profiles *ProfileList) GetUser(user string) User
    • func (Profiles *ProfileList) SaveData() error
  • User
    • func (Usr *User) SetWallet(coins float64)
    • func (Usr *User) SetBank(coins float64)
    • func (Usr *User) AddWallet(coins float64)
    • func (Usr *User) AddBank(coins float64)
    • func (Usr *User) RemoveWallet(coins float64)
    • func (Usr *User) RemoveBank(coins float64)

Example

JSON (users.json) before executing:

{}

Code:

package main

import (
	"github.com/NeutronX-dev/UserCurrency"
)

func HandleError(err error) {
	if err != nil {
		panic(err)
	}
}

func main() {
	Users, err := UserCurrency.Read("./users.json")
	HandleError(err)

	if !Users.UserExists("Someone") {
		Users.CreateUser("Someone")
	}

	User := Users.GetUser("Someone")
	User.SetWallet(1000)

	err = Users.SaveData()
	// Note: Data will always be avaliable but never
	//       saved into the JSON until you call this
	//       method. So make sure to call it.
	HandleError(err)
}

JSON (users.json) after executing:

{
	"Someone": {
		"bank": 0,
		"wallet": 1000
	}
}

LICENSE

gnu-logo

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Similar Resources

Abstract JSON for golang with JSONPath support

Abstract JSON Abstract JSON is a small golang package provides a parser for JSON with support of JSONPath, in case when you are not sure in its struct

Jan 5, 2023

Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

fastjson - fast JSON parser and validator for Go Features Fast. As usual, up to 15x faster than the standard encoding/json. See benchmarks. Parses arb

Jan 5, 2023

Small utility to create JSON objects

Small utility to create JSON objects

gjo Small utility to create JSON objects. This was inspired by jpmens/jo. Support OS Mac Linux Windows Requirements Go 1.1.14~ Git Installtion Build $

Dec 8, 2022

A Go package for handling common HTTP JSON responses.

go-respond A Go package for handling common HTTP JSON responses. Installation go get github.com/nicklaw5/go-respond Usage The goal of go-respond is to

Sep 26, 2022

JSON query in Golang

gojq JSON query in Golang. Install go get -u github.com/elgs/gojq This library serves three purposes: makes parsing JSON configuration file much easie

Dec 28, 2022

Automatically generate Go (golang) struct definitions from example JSON

gojson gojson generates go struct definitions from json or yaml documents. Example $ curl -s https://api.github.com/repos/chimeracoder/gojson | gojson

Jan 1, 2023

A JSON diff utility

JayDiff A JSON diff utility. Install Downloading the compiled binary Download the latest version of the binary: releases extract the archive and place

Dec 11, 2022

Fast and flexible JSON encoder for Go

Fast and flexible JSON encoder for Go

Jettison Jettison is a fast and flexible JSON encoder for the Go programming language, inspired by bet365/jingo, with a richer features set, aiming at

Dec 21, 2022

Create go type representation from json

json2go Package json2go provides utilities for creating go type representation from json inputs. Json2go can be used in various ways: CLI tool Web pag

Dec 26, 2022
Senml-go - a Golang module for the JSON-based SenML sensor data format

ThingWave SenML module for Golang This is a Golang module for the JSON-based Sen

Jan 2, 2022
JSON Spanner - A Go package that provides a fast and simple way to filter or transform a json document

JSON SPANNER JSON Spanner is a Go package that provides a fast and simple way to

Sep 14, 2022
Get JSON values quickly - JSON parser for Go
Get JSON values quickly - JSON parser for Go

get json values quickly GJSON is a Go package that provides a fast and simple way to get values from a json document. It has features such as one line

Dec 28, 2022
JSON diff library for Go based on RFC6902 (JSON Patch)

jsondiff jsondiff is a Go package for computing the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations, which is particula

Dec 4, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Jan 6, 2023
Package json implements encoding and decoding of JSON as defined in RFC 7159

Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions

Jun 26, 2022
Json-go - CLI to convert JSON to go and vice versa
Json-go - CLI to convert JSON to go and vice versa

Json To Go Struct CLI Install Go version 1.17 go install github.com/samit22/js

Jul 29, 2022
A simple Go package to Query over JSON/YAML/XML/CSV Data
A simple Go package to Query over JSON/YAML/XML/CSV Data

A simple Go package to Query over JSON Data. It provides simple, elegant and fast ODM like API to access, query JSON document Installation Install the

Dec 27, 2022
Simple json based db, if you call db xd.

Golang-json-db Simple json based db, if you call db xd. Basics //First of all you have to config main json file then config backup json file. Backup i

Sep 27, 2021
A Simple JSON Description of Telegraph API
A Simple JSON Description of Telegraph API

telegraph-api-spec Introduction This golang program generates a JSON description of methods, types and docstrings of the Telegraph API. Features Easy

Nov 21, 2022